(function(a) {
    a.fn.imgScroll = function(b) {
        return this.each(function() {
            var e = a.extend({evtType: "click",visible: 1,showControl: true,showNavItem: false,navItemEvtType: "click",navItemCurrent: "current",showStatus: false,direction: "x",next: ".next",prev: ".prev",disableClass: "disabled",speed: 300,loop: false,step: 1,ie6DisableClass: "disableIE6"}, b);
            var l = a(this), q = l.find("ul"), p = q.find("li"), h = e.width || p.outerWidth(), d = e.height || p.outerHeight(), u = p.length, c = e.visible, j = e.step, i = parseInt((u - c) / j), v = 0, m = l.css("position") == "absolute" ? "absolute" : "relative", x = p.css("float") !== "none", t = a('<div class="scroll-nav-wrap"></div>'), f = e.direction == "x" ? "left" : "top", k = e.direction == "x", r = typeof e.prev == "string" ? a(e.prev) : e.prev, s = typeof e.next == "string" ? a(e.next) : e.next, w = "";
            e.loop = false;
            function o() {
                if (!x) {
                    p.css("float", "left")
                }
                q.css({position: "absolute",left: 0,top: 0});
                l.css({position: m,width: e.direction == "x" ? c * h : p.outerWidth(),height: e.direction == "x" ? d : c * d,overflow: "hidden"});
                r.addClass(e.disableClass + w);
                if (e.loop) {
                } else {
                    if ((u - c) % j !== 0 && u > c) {
                        var A = j - (u - c) % j;
                        q.append(p.slice(0, A).clone());
                        u = q.find("li").length;
                        i = parseInt((u - c) / j)
                    }
                }
                if (k) {
                    q.css("width", u * h)
                } else {
                    q.css("height", u * d)
                }
                if (!e.showControl && u <= c) {
                    s.hide();
                    r.hide()
                } else {
                    s.show();
                    r.show()
                }
                if (u <= c) {
                    s.addClass(e.disableClass);
                    r.addClass(e.disableClass)
                } else {
                    r.addClass(e.disableClass);
                    s.removeClass(e.disableClass)
                }
                if (e.showNavItem) {
                    for (var y = 0; y <= i; y++) {
                        var z = y == 0 ? e.navItemCurrent : "";
                        t.append('<em class="' + z + '">' + (y + 1) + "</em>")
                    }
                    l.after(t);
                    t.find("em").bind(e.navItemEvtType, function() {
                        var B = parseInt(this.innerHTML);
                        g((B - 1) * j)
                    })
                }
                if (e.showStatus) {
                    l.after('<span class="scroll-status">' + 1 + "/" + (i + 1) + "</span>")
                }
            }
            function g(y) {
                if (q.is(":animated")) {
                    return false
                }
                if (y < 0) {
                    r.addClass(e.disableClass + w);
                    return false
                }
                if (y + c > u) {
                    s.addClass(e.disableClass);
                    return false
                }
                v = y;
                q.animate(e.direction == "x" ? {left: -((y) * h)} : {top: -((v) * d)}, e.speed, function() {
                    if (y > 0) {
                        r.removeClass(e.disableClass + w)
                    } else {
                        r.addClass(e.disableClass + w)
                    }
                    if (y + c < u) {
                        s.removeClass(e.disableClass)
                    } else {
                        s.addClass(e.disableClass)
                    }
                    n(y)
                })
            }
            function n(y) {
                t.find("em").removeClass(e.navItemCurrent).eq(y / j).addClass(e.navItemCurrent);
                if (e.showStatus) {
                    a(".scroll-status").html(((y / j) + 1) + "/" + (i + 1))
                }
            }
            o();
            if (u > c) {
                s.click(function() {
                    g(v + j)
                });
                r.click(function() {
                    g(v - j)
                })
            }
        })
    }
}(jQuery));