(function (i) {
    i.fn.jcarousel = function (a) { return this.each(function () { new f(this, a) }) }; var p = { vertical: false, start: 1, offset: 1, size: null, scroll: 3, visible: null, animation: "normal", easing: "swing", auto: 0, wrap: null, initCallback: null, reloadCallback: null, itemLoadCallback: null, itemFirstInCallback: null, itemFirstOutCallback: null, itemLastInCallback: null, itemLastOutCallback: null, itemVisibleInCallback: null, itemVisibleOutCallback: null, buttonNextHTML: "<div></div>", buttonPrevHTML: "<div></div>", buttonNextEvent: "click",
        buttonPrevEvent: "click", buttonNextCallback: null, buttonPrevCallback: null
    }; i.jcarousel = function (a, b) {
        this.options = i.extend({}, p, b || {}); this.locked = false; this.buttonPrev = this.buttonNext = this.list = this.clip = this.container = null; this.wh = !this.options.vertical ? "width" : "height"; this.lt = !this.options.vertical ? "left" : "top"; for (var c = "", d = a.className.split(" "), e = 0; e < d.length; e++) if (d[e].indexOf("jcarousel-skin") != -1) { i(a).removeClass(d[e]); c = d[e]; break } if (a.nodeName == "UL" || a.nodeName == "OL") {
            this.list = i(a);
            this.container = this.list.parent(); if (this.container.hasClass("jcarousel-clip")) { if (!this.container.parent().hasClass("jcarousel-container")) this.container = this.container.wrap("<div></div>"); this.container = this.container.parent() } else if (!this.container.hasClass("jcarousel-container")) this.container = this.list.wrap("<div></div>").parent()
        } else { this.container = i(a); this.list = i(a).find(">ul,>ol,div>ul,div>ol") } c != "" && this.container.parent()[0].className.indexOf("jcarousel-skin") == -1 && this.container.wrap('<div class=" ' +
c + '"></div>'); this.clip = this.list.parent(); if (!this.clip.length || !this.clip.hasClass("jcarousel-clip")) this.clip = this.list.wrap("<div></div>").parent(); this.buttonPrev = i(".jcarousel-prev", this.container); if (this.buttonPrev.size() == 0 && this.options.buttonPrevHTML != null) this.buttonPrev = this.clip.before(this.options.buttonPrevHTML).prev(); this.buttonPrev.addClass(this.className("jcarousel-prev")); this.buttonNext = i(".jcarousel-next", this.container); if (this.buttonNext.size() == 0 && this.options.buttonNextHTML !=
null) this.buttonNext = this.clip.before(this.options.buttonNextHTML).prev(); this.buttonNext.addClass(this.className("jcarousel-next")); this.clip.addClass(this.className("jcarousel-clip")); this.list.addClass(this.className("jcarousel-list")); this.container.addClass(this.className("jcarousel-container")); var g = this.options.visible != null ? Math.ceil(this.clipping() / this.options.visible) : null; c = this.list.children("li"); var h = this; if (c.size() > 0) {
            var k = 0; e = this.options.offset; c.each(function () {
                h.format(this,
e++); k += h.dimension(this, g)
            }); this.list.css(this.wh, k + "px"); if (!b || b.size === undefined) this.options.size = c.size()
        } this.container.css("display", "block"); this.buttonNext.css("display", "block"); this.buttonPrev.css("display", "block"); this.funcNext = function () { h.next() }; this.funcPrev = function () { h.prev() }; this.funcResize = function () { h.reload() }; this.options.initCallback != null && this.options.initCallback(this, "init"); if (i.browser.safari) { this.buttons(false, false); i(window).bind("load", function () { h.setup() }) } else this.setup()
    };
    var f = i.jcarousel; f.fn = f.prototype = { jcarousel: "0.2.3" }; f.fn.extend = f.extend = i.extend; f.fn.extend({ setup: function () { this.prevLast = this.prevFirst = this.last = this.first = null; this.animating = false; this.tail = this.timer = null; this.inTail = false; if (!this.locked) { this.list.css(this.lt, this.pos(this.options.offset) + "px"); var a = this.pos(this.options.start); this.prevFirst = this.prevLast = null; this.animate(a, false); i(window).unbind("resize", this.funcResize).bind("resize", this.funcResize) } }, reset: function () {
        this.list.empty();
        this.list.css(this.lt, "0px"); this.list.css(this.wh, "10px"); this.options.initCallback != null && this.options.initCallback(this, "reset"); this.setup()
    }, reload: function () {
        this.tail != null && this.inTail && this.list.css(this.lt, f.intval(this.list.css(this.lt)) + this.tail); this.tail = null; this.inTail = false; this.options.reloadCallback != null && this.options.reloadCallback(this); if (this.options.visible != null) {
            var a = this, b = Math.ceil(this.clipping() / this.options.visible), c = 0, d = 0; i("li", this.list).each(function (e) {
                c += a.dimension(this,
b); if (e + 1 < a.first) d = c
            }); this.list.css(this.wh, c + "px"); this.list.css(this.lt, -d + "px")
        } this.scroll(this.first, false)
    }, lock: function () { this.locked = true; this.buttons() }, unlock: function () { this.locked = false; this.buttons() }, size: function (a) { if (a != undefined) { this.options.size = a; this.locked || this.buttons() } return this.options.size }, has: function (a, b) { if (b == undefined || !b) b = a; if (this.options.size !== null && b > this.options.size) b = this.options.size; for (var c = a; c <= b; c++) { var d = this.get(c); if (!d.length || d.hasClass("jcarousel-item-placeholder")) return false } return true },
        get: function (a) { return i(".jcarousel-item-" + a, this.list) }, add: function (a, b) {
            var c = this.get(a), d = 0; if (c.length == 0) { var e; c = this.create(a); for (var g = f.intval(a); e = this.get(--g); ) if (g <= 0 || e.length) { g <= 0 ? this.list.prepend(c) : e.after(c); break } } else d = this.dimension(c); c.removeClass(this.className("jcarousel-item-placeholder")); typeof b == "string" ? c.html(b) : c.empty().append(b); e = this.options.visible != null ? Math.ceil(this.clipping() / this.options.visible) : null; d = this.dimension(c, e) - d; a > 0 && a < this.first && this.list.css(this.lt,
f.intval(this.list.css(this.lt)) - d + "px"); this.list.css(this.wh, f.intval(this.list.css(this.wh)) + d + "px"); return c
        }, remove: function (a) { var b = this.get(a); if (!(!b.length || a >= this.first && a <= this.last)) { var c = this.dimension(b); a < this.first && this.list.css(this.lt, f.intval(this.list.css(this.lt)) + c + "px"); b.remove(); this.list.css(this.wh, f.intval(this.list.css(this.wh)) - c + "px") } }, next: function () {
            this.stopAuto(); this.tail != null && !this.inTail ? this.scrollTail(false) : this.scroll((this.options.wrap == "both" || this.options.wrap ==
"last") && this.options.size != null && this.last == this.options.size ? 1 : this.first + this.options.scroll)
        }, prev: function () { this.stopAuto(); this.tail != null && this.inTail ? this.scrollTail(true) : this.scroll((this.options.wrap == "both" || this.options.wrap == "first") && this.options.size != null && this.first == 1 ? this.options.size : this.first - this.options.scroll) }, scrollTail: function (a) {
            if (!(this.locked || this.animating || !this.tail)) {
                var b = f.intval(this.list.css(this.lt)); !a ? b -= this.tail : b += this.tail; this.inTail = !a; this.prevFirst =
this.first; this.prevLast = this.last; this.animate(b)
            } 
        }, scroll: function (a, b) { this.locked || this.animating || this.animate(this.pos(a), b) }, pos: function (a) {
            if (!(this.locked || this.animating)) {
                a = f.intval(a); if (this.options.wrap != "circular") a = a < 1 ? 1 : this.options.size && a > this.options.size ? this.options.size : a; for (var b = this.first > a, c = f.intval(this.list.css(this.lt)), d = this.options.wrap != "circular" && this.first <= 1 ? 1 : this.first, e = b ? this.get(d) : this.get(this.last), g = b ? d : d - 1, h = null, k = 0, l = false, j = 0; b ? --g >= a : ++g < a; ) {
                    h =
this.get(g); l = !h.length; if (h.length == 0) { h = this.create(g).addClass(this.className("jcarousel-item-placeholder")); e[b ? "before" : "after"](h) } e = h; j = this.dimension(h); if (l) k += j; if (this.first != null && (this.options.wrap == "circular" || g >= 1 && (this.options.size == null || g <= this.options.size))) c = b ? c + j : c - j
                } d = this.clipping(); var o = [], n = 0; g = a; var m = 0; for (e = this.get(a - 1); ++n; ) {
                    h = this.get(g); l = !h.length; if (h.length == 0) {
                        h = this.create(g).addClass(this.className("jcarousel-item-placeholder")); e.length == 0 ? this.list.prepend(h) :
e[b ? "before" : "after"](h)
                    } e = h; j = this.dimension(h); if (j == 0) return 0; if (this.options.wrap != "circular" && this.options.size !== null && g > this.options.size) o.push(h); else if (l) k += j; m += j; if (m >= d) break; g++
                } for (e = 0; e < o.length; e++) o[e].remove(); if (k > 0) { this.list.css(this.wh, this.dimension(this.list) + k + "px"); if (b) { c -= k; this.list.css(this.lt, f.intval(this.list.css(this.lt)) - k + "px") } } e = a + n - 1; if (this.options.wrap != "circular" && this.options.size && e > this.options.size) e = this.options.size; if (g > e) {
                    n = 0; g = e; for (m = 0; ++n; ) {
                        h =
this.get(g--); if (!h.length) break; m += this.dimension(h); if (m >= d) break
                    } 
                } g = e - n + 1; if (this.options.wrap != "circular" && g < 1) g = 1; if (this.inTail && b) { c += this.tail; this.inTail = false } this.tail = null; if (this.options.wrap != "circular" && e == this.options.size && e - n + 1 >= 1) { b = f.margin(this.get(e), !this.options.vertical ? "marginRight" : "marginBottom"); if (m - b > d) this.tail = m - d - b } for (; a-- > g; ) c += this.dimension(this.get(a)); this.prevFirst = this.first; this.prevLast = this.last; this.first = g; this.last = e; return c
            } 
        }, animate: function (a, b) {
            if (!(this.locked ||
this.animating)) { this.animating = true; var c = this, d = function () { c.animating = false; a == 0 && c.list.css(c.lt, 0); if (c.options.wrap == "both" || c.options.wrap == "last" || c.options.size == null || c.last < c.options.size) c.startAuto(); c.buttons(); c.notify("onAfterAnimation") }; this.notify("onBeforeAnimation"); if (!this.options.animation || b == false) { this.list.css(this.lt, a + "px"); d() } else this.list.animate(!this.options.vertical ? { left: a} : { top: a }, this.options.animation, this.options.easing, d) } 
        }, startAuto: function (a) {
            if (a != undefined) this.options.auto =
a; if (this.options.auto == 0) return this.stopAuto(); if (this.timer == null) { var b = this; this.timer = setTimeout(function () { b.next() }, this.options.auto * 1E3) } 
        }, stopAuto: function () { if (this.timer != null) { clearTimeout(this.timer); this.timer = null } }, buttons: function (a, b) {
            if (a == undefined || a == null) {
                a = !this.locked && this.options.size !== 0 && (this.options.wrap && this.options.wrap != "first" || this.options.size == null || this.last < this.options.size); if (!this.locked && (!this.options.wrap || this.options.wrap == "first") && this.options.size !=
null && this.last >= this.options.size) a = this.tail != null && !this.inTail
            } if (b == undefined || b == null) { b = !this.locked && this.options.size !== 0 && (this.options.wrap && this.options.wrap != "last" || this.first > 1); if (!this.locked && (!this.options.wrap || this.options.wrap == "last") && this.options.size != null && this.first == 1) b = this.tail != null && this.inTail } var c = this; this.buttonNext[a ? "bind" : "unbind"](this.options.buttonNextEvent, this.funcNext)[a ? "removeClass" : "addClass"](this.className("jcarousel-next-disabled")).attr("disabled",
a ? false : true); this.buttonPrev[b ? "bind" : "unbind"](this.options.buttonPrevEvent, this.funcPrev)[b ? "removeClass" : "addClass"](this.className("jcarousel-prev-disabled")).attr("disabled", b ? false : true); if (this.buttonNext.length > 0 && (this.buttonNext[0].jcarouselstate == undefined || this.buttonNext[0].jcarouselstate != a) && this.options.buttonNextCallback != null) { this.buttonNext.each(function () { c.options.buttonNextCallback(c, this, a) }); this.buttonNext[0].jcarouselstate = a } if (this.buttonPrev.length > 0 && (this.buttonPrev[0].jcarouselstate ==
undefined || this.buttonPrev[0].jcarouselstate != b) && this.options.buttonPrevCallback != null) { this.buttonPrev.each(function () { c.options.buttonPrevCallback(c, this, b) }); this.buttonPrev[0].jcarouselstate = b } 
        }, notify: function (a) {
            var b = this.prevFirst == null ? "init" : this.prevFirst < this.first ? "next" : "prev"; this.callback("itemLoadCallback", a, b); if (this.prevFirst !== this.first) { this.callback("itemFirstInCallback", a, b, this.first); this.callback("itemFirstOutCallback", a, b, this.prevFirst) } if (this.prevLast !== this.last) {
                this.callback("itemLastInCallback",
a, b, this.last); this.callback("itemLastOutCallback", a, b, this.prevLast)
            } this.callback("itemVisibleInCallback", a, b, this.first, this.last, this.prevFirst, this.prevLast); this.callback("itemVisibleOutCallback", a, b, this.prevFirst, this.prevLast, this.first, this.last)
        }, callback: function (a, b, c, d, e, g, h) {
            if (!(this.options[a] == undefined || typeof this.options[a] != "object" && b != "onAfterAnimation")) {
                var k = typeof this.options[a] == "object" ? this.options[a][b] : this.options[a]; if (i.isFunction(k)) {
                    var l = this; if (d === undefined) k(l,
c, b); else if (e === undefined) this.get(d).each(function () { k(l, this, d, c, b) }); else for (var j = d; j <= e; j++) j !== null && !(j >= g && j <= h) && this.get(j).each(function () { k(l, this, j, c, b) })
                } 
            } 
        }, create: function (a) { return this.format("<li></li>", a) }, format: function (a, b) { var c = i(a).addClass(this.className("jcarousel-item")).addClass(this.className("jcarousel-item-" + b)); c.attr("jcarouselindex", b); return c }, className: function (a) { return a + " " + a + (!this.options.vertical ? "-horizontal" : "-vertical") }, dimension: function (a, b) {
            var c =
a.jquery != undefined ? a[0] : a, d = !this.options.vertical ? c.offsetWidth + f.margin(c, "marginLeft") + f.margin(c, "marginRight") : c.offsetHeight + f.margin(c, "marginTop") + f.margin(c, "marginBottom"); if (b == undefined || d == b) return d; d = !this.options.vertical ? b - f.margin(c, "marginLeft") - f.margin(c, "marginRight") : b - f.margin(c, "marginTop") - f.margin(c, "marginBottom"); i(c).css(this.wh, d + "px"); return this.dimension(c)
        }, clipping: function () {
            return !this.options.vertical ? this.clip[0].offsetWidth - f.intval(this.clip.css("borderLeftWidth")) -
f.intval(this.clip.css("borderRightWidth")) : this.clip[0].offsetHeight - f.intval(this.clip.css("borderTopWidth")) - f.intval(this.clip.css("borderBottomWidth"))
        }, index: function (a, b) { if (b == undefined) b = this.options.size; return Math.round(((a - 1) / b - Math.floor((a - 1) / b)) * b) + 1 } 
    }); f.extend({ defaults: function (a) { return i.extend(p, a || {}) }, margin: function (a, b) {
        if (!a) return 0; var c = a.jquery != undefined ? a[0] : a; if (b == "marginRight" && i.browser.safari) {
            var d = { display: "block", "float": "none", width: "auto" }, e, g; i.swap(c, d,
function () { e = c.offsetWidth }); d.marginRight = 0; i.swap(c, d, function () { g = c.offsetWidth }); return g - e
        } return f.intval(i.css(c, b))
    }, intval: function (a) { a = parseInt(a); return isNaN(a) ? 0 : a } 
    })
})(jQuery);
