(function (a) {
    a.fn.slides = function (b) {
        return b = a.extend({}, a.fn.slides.option, b), this.each(function () {
            function e() {
                b.pause ? (clearTimeout(f.data("pause")), clearInterval(f.data("interval")), x = setTimeout(function () {
                    clearTimeout(f.data("pause")), y = setInterval(function () {
                        c("next", l)
                    }, b.play), f.data("interval", y)
                }, b.pause), f.data("pause", x)) : d()
            }
            function d() {
                clearInterval(f.data("interval"))
            }
            function c(c, d, e) {
                if (!s && r) {
                    s = !0, b.animationStart(q + 1);
                    switch (c) {
                    case "next":
                        o = q, n = q + 1, n = h === n ? 0 : n, u = i * 2, c = -i * 2, q = n;
                        break;
                    case "prev":
                        o = q, n = q - 1, n = n === -1 ? h - 1 : n, u = 0, c = 0, q = n;
                        break;
                    case "pagination":
                        n = parseInt(e, 10), o = a("." + b.paginationClass + " li." + b.currentClass + " a", f).attr("href").match("[^#/]+$"), n > o ? (u = i * 2, c = -i * 2) : (u = 0, c = 0), q = n
                    }
                    d === "fade" ? b.crossfade ? g.children(":eq(" + n + ")", f).css({
                        zIndex: 10
                    }).fadeIn(b.fadeSpeed, b.fadeEasing, function () {
                        b.autoHeight ? g.animate({
                            height: g.children(":eq(" + n + ")", f).outerHeight()
                        }, b.autoHeightSpeed, function () {
                            g.children(":eq(" + o + ")", f).css({
                                display: "none",
                                zIndex: 0
                            }), g.children(":eq(" + n + ")", f).css({
                                zIndex: 0
                            }), b.animationComplete(n + 1), s = !1
                        }) : (g.children(":eq(" + o + ")", f).css({
                            display: "none",
                            zIndex: 0
                        }), g.children(":eq(" + n + ")", f).css({
                            zIndex: 0
                        }), b.animationComplete(n + 1), s = !1)
                    }) : g.children(":eq(" + o + ")", f).fadeOut(b.fadeSpeed, b.fadeEasing, function () {
                        b.autoHeight ? g.animate({
                            height: g.children(":eq(" + n + ")", f).outerHeight()
                        }, b.autoHeightSpeed, function () {
                            g.children(":eq(" + n + ")", f).fadeIn(b.fadeSpeed, b.fadeEasing)
                        }) : g.children(":eq(" + n + ")", f).fadeIn(b.fadeSpeed, b.fadeEasing, function () {
                            a.browser.msie && a(this).get(0).style.removeAttribute("filter")
                        }), b.animationComplete(n + 1), s = !1
                    }) : (g.children(":eq(" + n + ")").css({
                        left: u,
                        display: "block"
                    }), b.autoHeight ? g.animate({
                        left: c,
                        height: g.children(":eq(" + n + ")").outerHeight()
                    }, b.slideSpeed, b.slideEasing, function () {
                        g.css({
                            left: -i
                        }), g.children(":eq(" + n + ")").css({
                            left: i,
                            zIndex: 5
                        }), g.children(":eq(" + o + ")").css({
                            left: i,
                            display: "none",
                            zIndex: 0
                        }), b.animationComplete(n + 1), s = !1
                    }) : g.animate({
                        left: c
                    }, b.slideSpeed, b.slideEasing, function () {
                        g.css({
                            left: -i
                        }), g.children(":eq(" + n + ")").css({
                            left: i,
                            zIndex: 5
                        }), g.children(":eq(" + o + ")").css({
                            left: i,
                            display: "none",
                            zIndex: 0
                        }), b.animationComplete(n + 1), s = !1
                    })), b.pagination && (a("." + b.paginationClass + " li." + b.currentClass, f).removeClass(b.currentClass), a("." + b.paginationClass + " li:eq(" + n + ")", f).addClass(b.currentClass))
                }
            }
            a("." + b.container, a(this)).children().wrapAll('<div class="slides_control"/>');
            var f = a(this),
                g = a(".slides_control", f),
                h = g.children().size(),
                i = g.children().outerWidth(),
                j = g.children().outerHeight(),
                k = b.start - 1,
                l = b.effect.indexOf(",") < 0 ? b.effect : b.effect.replace(" ", "").split(",")[0],
                m = b.effect.indexOf(",") < 0 ? l : b.effect.replace(" ", "").split(",")[1],
                n = 0,
                o = 0,
                p = 0,
                q = 0,
                r, s, t, u, v, w, x, y;
            if (h < 2) return a("." + b.container, a(this)).fadeIn(b.fadeSpeed, b.fadeEasing, function () {
                r = !0, b.slidesLoaded()
            }), a("." + b.next + ", ." + b.prev).fadeOut(0), !1;
            if (h < 2) return;
            k < 0 && (k = 0), k > h && (k = h - 1), b.start && (q = k), b.randomize && g.randomize(), a("." + b.container, f).css({
                overflow: "hidden",
                position: "relative"
            }), g.children().css({
                position: "absolute",
                top: 0,
                left: g.children().outerWidth(),
                zIndex: 0,
                display: "none"
            }), g.css({
                position: "relative",
                width: i * 3,
                height: j,
                left: -i
            }), a("." + b.container, f).css({
                display: "block"
            }), b.autoHeight && (g.children().css({
                height: "auto"
            }), g.animate({
                height: g.children(":eq(" + k + ")").outerHeight()
            }, b.autoHeightSpeed));
            if (b.preload && g.find("img:eq(" + k + ")").length) {
                a("." + b.container, f).css({
                    background: "url(" + b.preloadImage + ") no-repeat 50% 50%"
                });
                var z = g.find("img:eq(" + k + ")").attr("src") + "?" + (new Date).getTime();
                a("img", f).parent().attr("class") != "slides_control" ? w = g.children(":eq(0)")[0].tagName.toLowerCase() : w = g.find("img:eq(" + k + ")"), g.find("img:eq(" + k + ")").attr("src", z).load(function () {
                    g.find(w + ":eq(" + k + ")").fadeIn(b.fadeSpeed, b.fadeEasing, function () {
                        a(this).css({
                            zIndex: 5
                        }), a("." + b.container, f).css({
                            background: ""
                        }), r = !0, b.slidesLoaded()
                    })
                })
            } else g.children(":eq(" + k + ")").fadeIn(b.fadeSpeed, b.fadeEasing, function () {
                r = !0, b.slidesLoaded()
            });
            b.bigTarget && (g.children().css({
                cursor: "pointer"
            }), g.children().click(function () {
                return c("next", l), !1
            })), b.hoverPause && b.play && (g.bind("mouseover", function () {
                d()
            }), g.bind("mouseleave", function () {
                e()
            })), b.generateNextPrev && (a("." + b.container, f).after('<a href="#" class="' + b.prev + '">Prev</a>'), a("." + b.prev, f).after('<a href="#" class="' + b.next + '">Next</a>')), a("." + b.next, f).click(function (a) {

                a.preventDefault(), b.play && e(), c("next", l)
            }), a("." + b.prev, f).click(function (a) {
                a.preventDefault(), b.play && e(), c("prev", l)
            }), b.generatePagination ? (b.prependPagination ? f.prepend("<ul class=" + b.paginationClass + "></ul>") : f.append("<ul class=" + b.paginationClass + "></ul>"), g.children().each(function () {
                a("." + b.paginationClass, f).append('<li><a href="#' + p + '">' + (p + 1) + "</a></li>"), p++
            })) : a("." + b.paginationClass + " li a", f).each(function () {
                a(this).attr("href", "#" + p), p++
            }), a("." + b.paginationClass + " li:eq(" + k + ")", f).addClass(b.currentClass), a("." + b.paginationClass + " li a", f).click(function () {
                return b.play && e(), t = a(this).attr("href").match("[^#/]+$"), q != t && c("pagination", m, t), !1
            }), a("a.link", f).click(function () {
                return b.play && e(), t = a(this).attr("href").match("[^#/]+$") - 1, q != t && c("pagination", m, t), !1
            }), b.play && (y = setInterval(function () {
                c("next", l)
            }, b.play), f.data("interval", y))
        })
    }, a.fn.slides.option = {
        container: "slides_container",
        generateNextPrev: !1,
        next: "next",
        prev: "prev",
        pagination: !0,
        generatePagination: !0,
        prependPagination: !1,
        paginationClass: "pagination",
        currentClass: "current",
        fadeSpeed: 350,
        fadeEasing: "",
        slideSpeed: 350,
        slideEasing: "",
        start: 1,
        effect: "slide",
        crossfade: !1,
        randomize: !1,
        play: 0,
        pause: 0,
        hoverPause: !1,
        autoHeight: !1,
        autoHeightSpeed: 350,
        bigTarget: !1,
        animationStart: function () {},
        animationComplete: function () {},
        slidesLoaded: function () {}
    }, a.fn.randomize = function (b) {
        function c() {
            return Math.round(Math.random()) - .5
        }
        return a(this).each(function () {
            var d = a(this),
                e = d.children(),
                f = e.length;
            if (f > 1) {
                e.hide();
                var g = [];
                for (i = 0; i < f; i++) g[g.length] = i;
                g = g.sort(c), a.each(g, function (a, c) {
                    var f = e.eq(c),
                        g = f.clone(!0);
                    g.show().appendTo(d), b !== undefined && b(f, g), f.remove()
                })
            }
        })
    }
})(jQuery)
