(function(e){
    function p(f, c){
        var b = e(c);
        return b.length < 2 ? b : f.parent().find(c)
    }
    function u(f, c){
        var b = this, n = f.add(b), g = f.children(), l = 0, j = c.vertical;
        k || (k = b);
        if (g.length > 1) 
            g = e(c.items, f);
        e.extend(b, {
            getConf: function(){
                return c
            },
            getIndex: function(){
                return l
            },
            getSize: function(){
                //return b.getItems().size()
				a = b.getItems().size()-4;
				return a;
            },
            getNaviButtons: function(){
                return o.add(q)
            },
            getRoot: function(){
                return f
            },
            getItemWrap: function(){
                return g
            },
            getItems: function(){
                return g.children(c.item).not("." + c.clonedClass)
            },
            move: function(a, d){
                return b.seekTo(l +
                a, d)
            },
            next: function(a){
                return b.move(1, a)
            },
            prev: function(a){
                return b.move(-1, a)
            },
            begin: function(a){
                return b.seekTo(0, a)
            },
            end: function(a){
                return b.seekTo(b.getSize() - 1, a)
            },
            focus: function(){
                return k = b
            },
            addItem: function(a){
                a = e(a);
                if (c.circular) {
                    g.children("." + c.clonedClass + ":last").before(a);
                    g.children("." + c.clonedClass + ":first").replaceWith(a.clone().addClass(c.clonedClass))
                }
                else 
                    g.append(a);
                n.trigger("onAddItem", [a]);
                return b
            },
            seekTo: function(a, d, h){
                a.jquery || (a *= 1);
                if (c.circular && a === 0 && l == -1 &&
                d !==
                0) 
                    return b;
                if (!c.circular && a < 0 || a > b.getSize() || a < -1) 
                    return b;
                var i = a;
                if (a.jquery) 
                    a = b.getItems().index(a);
                else 
                    i = b.getItems().eq(a);
                var r = e.Event("onBeforeSeek");
                if (!h) {
                    n.trigger(r, [a, d]);
                    if (r.isDefaultPrevented() || !i.length) 
                        return b
                }
                i = j ? {
                    top: -i.position().top
                } : {
                    left: -i.position().left
                };
                l = a;
                k = b;
                if (d === undefined) 
                    d = c.speed;
                g.animate(i, d, c.easing, h ||
                function(){
                    n.trigger("onSeek", [a])
                });
                return b
            }
        });
        e.each(["onBeforeSeek", "onSeek", "onAddItem"], function(a, d){
            e.isFunction(c[d]) && e(b).bind(d, c[d]);
            b[d] = function(h){
                h &&
                e(b).bind(d, h);
                return b
            }
        });
        if (c.circular) {
            var s = b.getItems().slice(-1).clone().prependTo(g), t = b.getItems().eq(1).clone().appendTo(g);
            s.add(t).addClass(c.clonedClass);
            b.onBeforeSeek(function(a, d, h){
                if (!a.isDefaultPrevented()) 
                    if (d == -1) {
                        b.seekTo(s, h, function(){
                            b.end(0)
                        });
                        return a.preventDefault()
                    }
                    else 
                        d == b.getSize() && b.seekTo(t, h, function(){
                            b.begin(0)
                        })
            });
            b.seekTo(0, 0, function(){
            })
        }
        var o = p(f, c.prev).click(function(){
            b.prev()
        }), q = p(f, c.next).click(function(){
            b.next()
        });
        if (!c.circular && b.getSize() > 1) {
            b.onBeforeSeek(function(a, d){
                setTimeout(function(){
                    if (!a.isDefaultPrevented()) {
                        o.toggleClass(c.disabledClass, d <= 0);
                        q.toggleClass(c.disabledClass, d >= b.getSize() - 1)
                    }
                }, 1)
            });
            c.initialIndex || o.addClass(c.disabledClass)
        }
        c.mousewheel && e.fn.mousewheel && f.mousewheel(function(a, d){
            if (c.mousewheel) {
                b.move(d < 0 ? 1 : -1, c.wheelSpeed || 50);
                return false
            }
        });
        if (c.touch) {
            var m = {};
            g[0].ontouchstart = function(a){
                a = a.touches[0];
                m.x = a.clientX;
                m.y = a.clientY
            };
            g[0].ontouchmove = function(a){
                if (a.touches.length == 1 && !g.is(":animated")) {
                    var d = a.touches[0], h = m.x - d.clientX;
                    d = m.y - d.clientY;
                    b[j && d > 0 || !j && h > 0 ? "next" : "prev"]();
                    a.preventDefault()
                }
            }
        }
        c.keyboard && e(document).bind("keydown.scrollable", function(a){
            if (!(!c.keyboard || a.altKey || a.ctrlKey || e(a.target).is(":input"))) 
                if (!(c.keyboard != "static" && k != b)) {
                    var d = a.keyCode;
                    if (j && (d == 38 || d == 40)) {
                        b.move(d == 38 ? -1 : 1);
                        return a.preventDefault()
                    }
                    if (!j && (d == 37 || d == 39)) {
                        b.move(d == 37 ? -1 : 1);
                        return a.preventDefault()
                    }
                }
        });
        c.initialIndex && b.seekTo(c.initialIndex, 0, function(){
        })
    }
    e.tools = e.tools ||
    {
        version: "1.2.5"
    };
    e.tools.scrollable = {
        conf: {
            activeClass: "active",
            circular: false,
            clonedClass: "cloned",
            disabledClass: "disabled",
            easing: "swing",
            initialIndex: 0,
            item: null,
            items: ".items",
            keyboard: true,
            mousewheel: false,
            next: ".next",
            prev: ".prev",
            speed: 400,
            vertical: false,
            touch: true,
            wheelSpeed: 0
        }
    };
    var k;
    e.fn.scrollable = function(f){
        var c = this.data("scrollable");
        if (c) 
            return c;
        f = e.extend({}, e.tools.scrollable.conf, f);
        this.each(function(){
            c = new u(e(this), f);
            e(this).data("scrollable", c)
        });
        return f.api ? c : this
    }
})(jQuery);
(function(a){
    function t(d, b){
        var c = this, j = d.add(c), o = a(window), k, f, m, g = a.tools.expose && (b.mask || b.expose), n = Math.random().toString().slice(10);
        if (g) {
            if (typeof g == "string") 
                g = {
                    color: g
                };
            g.closeOnClick = g.closeOnEsc = false
        }
        var p = b.target || d.attr("rel");
        f = p ? a(p) : d;
        if (!f.length) 
            throw "Could not find Overlay: " + p;
        d && d.index(f) == -1 && d.click(function(e){
            c.load(e);
            return e.preventDefault()
        });
        a.extend(c, {
            load: function(e){
                if (c.isOpened()) 
                    return c;
                var h = q[b.effect];
                if (!h) 
                    throw 'Overlay: cannot find effect : "' + b.effect +
                    '"';
                b.oneInstance && a.each(s, function(){
                    this.close(e)
                });
                e = e || a.Event();
                e.type = "onBeforeLoad";
                j.trigger(e);
                if (e.isDefaultPrevented()) 
                    return c;
                m = true;
                g && a(f).expose(g);
                var i = b.top, r = b.left, u = f.outerWidth({
                    margin: true
                }), v = f.outerHeight({
                    margin: true
                });
                if (typeof i == "string") 
                    i = i == "center" ? Math.max((o.height() - v) / 2, 0) : parseInt(i, 10) / 100 * o.height();
                if (r == "center") 
                    r = Math.max((o.width() - u) / 2, 0);
                h[0].call(c, {
                    top: i,
                    left: r
                }, function(){
                    if (m) {
                        e.type = "onLoad";
                        j.trigger(e)
                    }
                });
                g && b.closeOnClick &&
                a.mask.getMask().one("click", c.close);
                b.closeOnClick && a(document).bind("click." + n, function(l){
                    a(l.target).parents(f).length || c.close(l)
                });
                b.closeOnEsc && a(document).bind("keydown." + n, function(l){
                    l.keyCode == 27 && c.close(l)
                });
                return c
            },
            close: function(e){
                if (!c.isOpened()) 
                    return c;
                e = e || a.Event();
                e.type = "onBeforeClose";
                j.trigger(e);
                if (!e.isDefaultPrevented()) {
                    m = false;
                    q[b.effect][1].call(c, function(){
                        e.type = "onClose";
                        j.trigger(e)
                    });
                    a(document).unbind("click." + n).unbind("keydown." + n);
                    g && a.mask.close();
                    return c
                }
            },
            getOverlay: function(){
                return f
            },
            getTrigger: function(){
                return d
            },
            getClosers: function(){
                return k
            },
            isOpened: function(){
                return m
            },
            getConf: function(){
                return b
            }
        });
        a.each("onBeforeLoad,onStart,onLoad,onBeforeClose,onClose".split(","), function(e, h){
            a.isFunction(b[h]) && a(c).bind(h, b[h]);
            c[h] = function(i){
                i && a(c).bind(h, i);
                return c
            }
        });
        k = f.find(b.close || ".close");
        if (!k.length && !b.close) {
            k = a('<a class="close"></a>');
            f.prepend(k)
        }
        k.click(function(e){
            c.close(e)
        });
        b.load && c.load()
    }
    a.tools = a.tools ||
    {
        version: "1.2.5"
    };
    a.tools.overlay = {
        addEffect: function(d, b, c){
            q[d] = [b, c]
        },
        conf: {
            close: null,
            closeOnClick: true,
            closeOnEsc: true,
            closeSpeed: "fast",
            effect: "default",
            fixed: !a.browser.msie || a.browser.version > 6,
            left: "center",
            load: false,
            mask: null,
            oneInstance: true,
            speed: "normal",
            target: null,
            top: "10%"
        }
    };
    var s = [], q = {};
    a.tools.overlay.addEffect("default", function(d, b){
        var c = this.getConf(), j = a(window);
        if (!c.fixed) {
            d.top += j.scrollTop();
            d.left += j.scrollLeft()
        }
        d.position = c.fixed ? "fixed" : "absolute";
        this.getOverlay().css(d).fadeIn(c.speed, b)
    }, function(d){
        this.getOverlay().fadeOut(this.getConf().closeSpeed, d)
    });
    a.fn.overlay = function(d){
        var b = this.data("overlay");
        if (b) 
            return b;
        if (a.isFunction(d)) 
            d = {
                onBeforeLoad: d
            };
        d = a.extend(true, {}, a.tools.overlay.conf, d);
        this.each(function(){
            b = new t(a(this), d);
            s.push(b);
            a(this).data("overlay", b)
        });
        return d.api ? b : this
    }
})(jQuery);

