jQuery.easing.jswing = jQuery.easing.swing;
jQuery.extend(jQuery.easing, {
    def: "easeOutQuad",
    swing: function(f, g, a, j, h) {
        return jQuery.easing[jQuery.easing.def](f, g, a, j, h)
    },
    easeInQuad: function(f, g, a, j, h) {
        return j * (g /= h) * g + a
    },
    easeOutQuad: function(f, g, a, j, h) {
        return -j * (g /= h) * (g - 2) + a
    },
    easeInOutQuad: function(f, g, a, j, h) {
        if ((g /= h / 2) < 1) {
            return j / 2 * g * g + a
        }
        return -j / 2 * ((--g) * (g - 2) - 1) + a
    },
    easeInCubic: function(f, g, a, j, h) {
        return j * (g /= h) * g * g + a
    },
    easeOutCubic: function(f, g, a, j, h) {
        return j * ((g = g / h - 1) * g * g + 1) + a
    },
    easeInOutCubic: function(f, g, a, j, h) {
        if ((g /= h / 2) < 1) {
            return j / 2 * g * g * g + a
        }
        return j / 2 * ((g -= 2) * g * g + 2) + a
    },
    easeInQuart: function(f, g, a, j, h) {
        return j * (g /= h) * g * g * g + a
    },
    easeOutQuart: function(f, g, a, j, h) {
        return -j * ((g = g / h - 1) * g * g * g - 1) + a
    },
    easeInOutQuart: function(f, g, a, j, h) {
        if ((g /= h / 2) < 1) {
            return j / 2 * g * g * g * g + a
        }
        return -j / 2 * ((g -= 2) * g * g * g - 2) + a
    },
    easeInQuint: function(f, g, a, j, h) {
        return j * (g /= h) * g * g * g * g + a
    },
    easeOutQuint: function(f, g, a, j, h) {
        return j * ((g = g / h - 1) * g * g * g * g + 1) + a
    },
    easeInOutQuint: function(f, g, a, j, h) {
        if ((g /= h / 2) < 1) {
            return j / 2 * g * g * g * g * g + a
        }
        return j / 2 * ((g -= 2) * g * g * g * g + 2) + a
    },
    easeInSine: function(f, g, a, j, h) {
        return -j * Math.cos(g / h * (Math.PI / 2)) + j + a
    },
    easeOutSine: function(f, g, a, j, h) {
        return j * Math.sin(g / h * (Math.PI / 2)) + a
    },
    easeInOutSine: function(f, g, a, j, h) {
        return -j / 2 * (Math.cos(Math.PI * g / h) - 1) + a
    },
    easeInExpo: function(f, g, a, j, h) {
        return (g == 0) ? a : j * Math.pow(2, 10 * (g / h - 1)) + a
    },
    easeOutExpo: function(f, g, a, j, h) {
        return (g == h) ? a + j : j * (-Math.pow(2, -10 * g / h) + 1) + a
    },
    easeInOutExpo: function(f, g, a, j, h) {
        if (g == 0) {
            return a
        }
        if (g == h) {
            return a + j
        }
        if ((g /= h / 2) < 1) {
            return j / 2 * Math.pow(2, 10 * (g - 1)) + a
        }
        return j / 2 * (-Math.pow(2, -10 * --g) + 2) + a
    },
    easeInCirc: function(f, g, a, j, h) {
        return -j * (Math.sqrt(1 - (g /= h) * g) - 1) + a
    },
    easeOutCirc: function(f, g, a, j, h) {
        return j * Math.sqrt(1 - (g = g / h - 1) * g) + a
    },
    easeInOutCirc: function(f, g, a, j, h) {
        if ((g /= h / 2) < 1) {
            return -j / 2 * (Math.sqrt(1 - g * g) - 1) + a
        }
        return j / 2 * (Math.sqrt(1 - (g -= 2) * g) + 1) + a
    },
    easeInElastic: function(g, j, f, n, m) {
        var k = 1.70158;
        var l = 0;
        var h = n;
        if (j == 0) {
            return f
        }
        if ((j /= m) == 1) {
            return f + n
        }
        if (!l) {
            l = m * 0.3
        }
        if (h < Math.abs(n)) {
            h = n;
            var k = l / 4
        } else {
            var k = l / (2 * Math.PI) * Math.asin(n / h)
        }
        return -(h * Math.pow(2, 10 * (j -= 1)) * Math.sin((j * m - k) * (2 * Math.PI) / l)) + f
    },
    easeOutElastic: function(g, j, f, n, m) {
        var k = 1.70158;
        var l = 0;
        var h = n;
        if (j == 0) {
            return f
        }
        if ((j /= m) == 1) {
            return f + n
        }
        if (!l) {
            l = m * 0.3
        }
        if (h < Math.abs(n)) {
            h = n;
            var k = l / 4
        } else {
            var k = l / (2 * Math.PI) * Math.asin(n / h)
        }
        return h * Math.pow(2, -10 * j) * Math.sin((j * m - k) * (2 * Math.PI) / l) + n + f
    },
    easeInOutElastic: function(g, j, f, n, m) {
        var k = 1.70158;
        var l = 0;
        var h = n;
        if (j == 0) {
            return f
        }
        if ((j /= m / 2) == 2) {
            return f + n
        }
        if (!l) {
            l = m * (0.3 * 1.5)
        }
        if (h < Math.abs(n)) {
            h = n;
            var k = l / 4
        } else {
            var k = l / (2 * Math.PI) * Math.asin(n / h)
        }
        if (j < 1) {
            return -0.5 * (h * Math.pow(2, 10 * (j -= 1)) * Math.sin((j * m - k) * (2 * Math.PI) / l)) + f
        }
        return h * Math.pow(2, -10 * (j -= 1)) * Math.sin((j * m - k) * (2 * Math.PI) / l) * 0.5 + n + f
    },
    easeInBack: function(f, g, a, k, j, h) {
        if (h == undefined) {
            h = 1.70158
        }
        return k * (g /= j) * g * ((h + 1) * g - h) + a
    },
    easeOutBack: function(f, g, a, k, j, h) {
        if (h == undefined) {
            h = 1.70158
        }
        return k * ((g = g / j - 1) * g * ((h + 1) * g + h) + 1) + a
    },
    easeInOutBack: function(f, g, a, k, j, h) {
        if (h == undefined) {
            h = 1.70158
        }
        if ((g /= j / 2) < 1) {
            return k / 2 * (g * g * (((h *= (1.525)) + 1) * g - h)) + a
        }
        return k / 2 * ((g -= 2) * g * (((h *= (1.525)) + 1) * g + h) + 2) + a
    },
    easeInBounce: function(f, g, a, j, h) {
        return j - jQuery.easing.easeOutBounce(f, h - g, 0, j, h) + a
    },
    easeOutBounce: function(f, g, a, j, h) {
        if ((g /= h) < (1 / 2.75)) {
            return j * (7.5625 * g * g) + a
        } else {
            if (g < (2 / 2.75)) {
                return j * (7.5625 * (g -= (1.5 / 2.75)) * g + 0.75) + a
            } else {
                if (g < (2.5 / 2.75)) {
                    return j * (7.5625 * (g -= (2.25 / 2.75)) * g + 0.9375) + a
                } else {
                    return j * (7.5625 * (g -= (2.625 / 2.75)) * g + 0.984375) + a
                }
            }
        }
    },
    easeInOutBounce: function(f, g, a, j, h) {
        if (g < h / 2) {
            return jQuery.easing.easeInBounce(f, g * 2, 0, j, h) * 0.5 + a
        }
        return jQuery.easing.easeOutBounce(f, g * 2 - h, 0, j, h) * 0.5 + j * 0.5 + a
    }
});
(function(b) {
    b.tools = b.tools || {
        version: {}
    };
    b.tools.version.scrollable = "1.0.5";
    var c = null;

    function a(q, j) {
        var m = this;
        if (!c) {
            c = m
        }
        function w(x, y) {
            b(m).bind(x, function(A, z) {
                if (y && y.call(this, z.index) === false && z) {
                    z.proceed = false
                }
            });
            return m
        }
        b.each(j, function(x, y) {
            if (b.isFunction(y)) {
                w(x, y)
            }
        });
        var t = !j.vertical;
        var k = b(j.items, q);
        var g = j.start;
        var d = t ? "left" : "top";

        function n(y, x) {
            return y.indexOf("#") != -1 ? b(y).eq(0) : x.siblings(y).eq(0)
        }
        var v = n(j.navi, q);
        var o = n(j.prev, q);
        var p = n(j.next, q);
        var f = n(j.prevPage, q);
        var r = n(j.nextPage, q);
        b.extend(m, {
            getIndex: function() {
                return g
            },
            getConf: function() {
                return j
            },
            getSize: function() {
                return m.getItems().size()
            },
            getPageAmount: function() {
                size = j.loop ? this.getSize() - (j.size * 2) : this.getSize();
                return Math.ceil(size / j.size)
            },
            getPageIndex: function(x) {
                var y = j.loop ? (x - j.size) : x;
                var z = m.getPageAmount();
                page = Math.ceil(y / j.size);
                if (page < 0) {
                    page = z - 1
                } else {
                    if (page >= z) {
                        page = 0
                    }
                }
                return page
            },
            getRoot: function() {
                return q
            },
            getItemWrap: function() {
                return k
            },
            getItems: function() {
                return k.children()
            },
            getVisibleItems: function() {
                return m.getItems().slice(g, g + j.size)
            },
            getPositionForItem: function(x) {
                return (t) ? -x.position().left : -x.position().top
            },
            seekTo: function(z, y, C) {
                if (y === undefined) {
                    y = j.speed
                }
                if (b.isFunction(y)) {
                    C = y;
                    y = j.speed
                }
                if (z < 0) {
                    z = 0
                }
                if (z > m.getSize() - j.size) {
                    return m
                }
                var F = m.getItems().eq(z);
                if (!F.length) {
                    return m
                }
                var x = {
                    index: z,
                    proceed: true
                };
                b(m).trigger("onBeforeSeek", x);
                if (!x.proceed) {
                    return m
                }
                params = {};
                params[d] = m.getPositionForItem(F);
                k.animate(params, y, j.easing, C ?
                function() {
                    C.call(m)
                } : null);
                if (v.length) {
                    var B = j.activeClass;
                    v.children().removeClass(B).eq(m.getPageIndex(z)).addClass(B)
                }
                if (!j.loop) {
                    var E = j.disabledClass,
                        D = o.add(f),
                        A = p.add(r);
                    if (z === 0) {
                        D.addClass(E)
                    } else {
                        D.removeClass(E)
                    }
                    if (z >= m.getSize() - j.size) {
                        A.addClass(E)
                    } else {
                        A.removeClass(E)
                    }
                }
                c = m;
                g = z;
                b(m).trigger("onSeek", {
                    index: z
                });
                return m
            },
            move: function(B, A, z) {
                var C = g + B,
                    x = m.getItems(),
                    y = m.getSize();
                if (j.loop) {
                    if (C < 0) {
                        for (i = g + 1; i < y; i++) {
                            if (b(x[i]).data("id") == b(x[g]).data("id")) {
                                m.setPosition(i);
                                C = i - (Math.abs(C) + g);
                                break
                            }
                        }
                    } else {
                        if (C > (y - j.size)) {
                            for (i = 0; i < y; i++) {
                                if (b(x[i]).data("id") == b(x[g]).data("id")) {
                                    m.setPosition(i);
                                    C = i + (C - g);
                                    break
                                }
                            }
                        }
                    }
                }
                g = C;
                return this.seekTo(g, A, z)
            },
            next: function(y, x) {
                return this.move(1, y, x)
            },
            prev: function(y, x) {
                return this.move(-1, y, x)
            },
            movePage: function(z, y, x) {
                return this.move(j.size * z, y, x)
            },
            setPage: function(C, D, z) {
                var y = j.size,
                    A = m.getSize();
                var x = y * C;
                var B = x + y >= A;
                if (B) {
                    x = A - y
                }
                return this.seekTo(x + (j.loop ? y : 0), D, z)
            },
            setPosition: function(x) {
                m.getItemWrap().css(d, m.getPositionForItem(m.getItems().eq(x)))
            },
            prevPage: function(y, x) {
                return this.movePage(-1, y, x)
            },
            nextPage: function(y, x) {
                return this.movePage(1, y, x)
            },
            begin: function(y, x) {
                return this.seekTo(0, y, x)
            },
            end: function(y, x) {
                return this.seekTo(this.getSize() - j.size, y, x)
            },
            reload: function() {
                return h()
            },
            click: function(y, B, z) {
                var A = m.getItems().eq(y);
                var x = j.activeClass;
                if (y < 0 || y >= this.getSize()) {
                    return m
                }
                if (j.size == 2) {
                    if (y == m.getIndex()) {
                        y--
                    }
                    m.getItems().removeClass(x);
                    A.addClass(x);
                    return this.seekTo(y, B, z)
                }
                if (!A.hasClass(x)) {
                    m.getItems().removeClass(x);
                    A.addClass(x);
                    var D = Math.floor(j.size / 2);
                    var C = y - D;
                    if (C > m.getSize() - j.size) {
                        C = m.getSize() - j.size
                    }
                    if (C !== y) {
                        return this.seekTo(C, B, z)
                    }
                }
                return m
            },
            onBeforeSeek: function(x) {
                return w("onBeforeSeek", x)
            },
            onSeek: function(x) {
                return w("onSeek", x)
            }
        });
        if (b.isFunction(b.fn.mousewheel)) {
            q.bind("mousewheel.scrollable", function(y, z) {
                var x = b.browser.opera ? 1 : -1;
                m.move(z > 0 ? x : -x, 50);
                return false
            })
        }
        o.click(function() {
            m.prev()
        }).hover(s, u);
        p.click(function() {
            m.next()
        }).hover(s, u);
        r.click(function() {
            m.nextPage()
        }).hover(s, u);
        f.click(function() {
            m.prevPage()
        }).hover(s, u);
        if (j.loop) {
            o.add(f).add(p).add(r).removeClass(j.disabledClass)
        } else {
            o.add(f).addClass(j.disabledClass)
        }
        if (j.keyboard) {
            b(document).unbind("keydown.scrollable").bind("keydown.scrollable", function(x) {
                var y = c;
                if (!y || x.altKey || x.ctrlKey) {
                    return
                }
                if (t && (x.keyCode == 37 || x.keyCode == 39)) {
                    y.move(x.keyCode == 37 ? -1 : 1);
                    return x.preventDefault()
                }
                if (!t && (x.keyCode == 38 || x.keyCode == 40)) {
                    y.move(x.keyCode == 38 ? -1 : 1);
                    return x.preventDefault()
                }
                return true
            })
        }
        function h() {
            if (j.loop && m.getSize() >= j.size) {
                var A = 0,
                    y = m.getItems(),
                    x = m.getItemWrap();
                y.each(function() {
                    b(this).data("id", A++)
                });
                y.slice(0, j.size).each(function() {
                    b(this).clone().data("id", b(this).data("id")).appendTo(x)
                });
                var C = b.makeArray(y.slice(-(j.size)));
                C.reverse();
                b(C).each(function() {
                    b(this).clone().data("id", b(this).data("id")).prependTo(x)
                });
                g += j.size
            }
            if (v.is(":empty") || v.data("me") == m) {
                v.empty();
                v.data("me", m);
                for (var A = 0; A < m.getPageAmount(); A++) {
                    var B = b("<" + j.naviItem + "/>").attr("href", A).click(function(E) {
                        var D = b(this);
                        D.parent().children().removeClass(j.activeClass);
                        D.addClass(j.activeClass);
                        m.setPage(D.attr("href"));
                        return E.preventDefault()
                    }).hover(s, u);
                    if (A === 0) {
                        B.addClass(j.activeClass)
                    }
                    v.append(B)
                }
            } else {
                var z = v.children();
                z.each(function(D) {
                    var E = b(this);
                    E.attr("href", D);
                    if (D === 0) {
                        E.addClass(j.activeClass)
                    }
                    E.click(function() {
                        v.find("." + j.activeClass).removeClass(j.activeClass);
                        E.addClass(j.activeClass);
                        m.setPage(E.attr("href"))
                    })
                })
            }
            if (j.clickable) {
                m.getItems().each(function(E, D) {
                    var F = b(this);
                    if (!F.data("set")) {
                        F.bind("click.scrollable", function() {
                            m.click(E)
                        });
                        F.data("set", true)
                    }
                })
            }
            if (j.hoverClass) {
                m.getItems().hover(function() {
                    b(this).addClass(j.hoverClass)
                }, function() {
                    b(this).removeClass(j.hoverClass)
                })
            }
            return m
        }
        h();
        if (g < j.size || (!j.loop && j.start < j.size)) {
            g = 0
        }
        if (!j.loop && g >= (m.getSize() - j.size)) {
            g = m.getSize() - j.size
        }
        m.setPosition(g);
        var l = null;

        function u() {
            if (l) {
                return
            }
            l = setInterval(function() {
                if (j.interval === 0) {
                    clearInterval(l);
                    l = 0;
                    return
                }
                m.next()
            }, j.interval)
        }
        function s() {
            clearInterval(l);
            l = 0
        }
        if (j.interval > 0) {
            q.hover(s, u);
            u()
        }
    }
    b.fn.scrollable = function(d) {
        var f = this.eq(typeof d == "number" ? d : 0).data("scrollable");
        if (f) {
            return f
        }
        var g = {
            size: 5,
            start: 0,
            vertical: false,
            clickable: true,
            loop: false,
            interval: 0,
            speed: 400,
            keyboard: true,
            activeClass: "active",
            disabledClass: "disabled",
            hoverClass: null,
            easing: "swing",
            items: ".items",
            prev: ".prev",
            next: ".next",
            prevPage: ".prevPage",
            nextPage: ".nextPage",
            navi: ".navi",
            naviItem: "a",
            api: false,
            onBeforeSeek: null,
            onSeek: null
        };
        b.extend(g, d);
        this.each(function() {
            f = new a(b(this), g);
            b(this).data("scrollable", f)
        });
        return g.api ? f : this
    }
})(jQuery);

jQuery(function(e) {

    e("#home .scroll").scrollable({ size: 3, start: 0, clickable: false, loop: true, keyboard: false, interval: 4321, speed: 500, items: "ul", navi: "#home .carousel .navi" });
    e("#home .scroll li").hover(function() {
        e(this).siblings().find("img").animate({ opacity: 0.5 }, { duration: 500, queue: false });
    },
        function() {
            e(this).siblings().find("img").animate({ opacity: 1 }, { duration: 500, queue: false });
        }
    );

    var c = e(".has-carousel .carousel");
    if (c.length) {
        var h = 0;
        var d = e.url.attr("path");

        if (e.url.segment(1)) {
            e(".has-carousel .carousel li").each(
                function(l) {
                    if (e("a[href=" + d + "]", this).length) {
                        h = l;
                    }
                }
            )
        }

        var b;
        var f = e(".has-carousel .carousel li:first img").width();

        if (f > 286) {
            b = tmp_scroll = 2;
            e(".has-carousel .carousel ul").addClass("cnt2")
        } else {
            if (f > 138) {
                b = tmp_scroll = 3;
            }
            else {
                b = tmp_scroll = 6;
                e(".has-carousel .carousel ul").addClass("cnt6");
            }
        }

        should_loop = e("li", c).size() > b;
        e(".scroll", c).scrollable({ size: b, start: h, clickable: false, loop: should_loop, keyboard: false, speed: 1500, items: "ul", easing: "easeInOutCubic" });

        if (e.url.segment(1)) {
            d = e.url.attr("path");
            e("img", ".has-carousel .carousel li a:not([href=" + d + "])").css("opacity", 0.5).hover(
            function() {
                e(this).animate({ opacity: 1 }, { duration: 300, queue: false });
            },
            function() {
                e(this).animate({ opacity: 0.5 }, { duration: 300, queue: false });
            });
            e(".has-carousel .carousel li").each(function(m) {
                var l = e("a[href=" + d + "]", this);
                if (l.length) {
                    $("img", l).css("opacity", 1);
                    h = m;
                }
            })
        }
        else {
            e(".has-carousel .carousel li").hover(
                function() {
                    e(this).siblings().find("img").animate({ opacity: 0.5 }, { duration: 300, queue: false });
                },
                function() {
                    e(this).siblings().find("img").animate({ opacity: 1 }, { duration: 300, queue: false });
                })
        }
    }

});

function MousePopup() {
    var b = a();

    b.start = function(d, f) {
        if (f) {
            b.html("<img src='" + f + "' />");
        }

        $("body").bind("mousemove", b.mouseMove);
        b.show();
    };
    b.mouseMove = function(d) {
        b.css("top", d.pageY + 10);
        b.css("left", d.pageX + 10)
    };
    b.stop = function() {
        $("body").unbind("mousemove", b.mouseMove);
        b.hide();
    };

    function a() {
        b = $("#mouse_popup");
        if (b.length > 0) { return b; }
        else { return c(); }
    }
    function c() {
        $("body").append('<div id="mouse_popup"></div>');
        return $("#mouse_popup");
    }
    return b;
}
