/*!
 * Bez v1.0.10-g5ae0136
 * http://github.com/rdallasgray/bez
 * 
 * A plugin to convert CSS3 cubic-bezier co-ordinates to jQuery-compatible easing functions
 * 
 * With thanks to Nikolay Nemshilov for clarification on the cubic-bezier maths
 * See http://st-on-it.blogspot.com/2011/05/calculating-cubic-bezier-function.html
 * 
 * Copyright 2011 Robert Dallas Gray. All rights reserved.
 * Provided under the FreeBSD license: https://github.com/rdallasgray/bez/blob/master/LICENSE.txt
 */
jQuery.extend({
    bez: function (a) {
        var b = "bez_" + $.makeArray(arguments).join("_").replace(".", "p");
        if (typeof jQuery.easing[b] != "function") {
            var c = function (a, b) {
                    var c = [null, null],
                        d = [null, null],
                        e = [null, null],
                        f = function (f, g) {
                            return e[g] = 3 * a[g], d[g] = 3 * (b[g] - a[g]) - e[g], c[g] = 1 - e[g] - d[g], f * (e[g] + f * (d[g] + f * c[g]))
                        },
                        g = function (a) {
                            return e[0] + a * (2 * d[0] + 3 * c[0] * a)
                        },
                        h = function (a) {
                            var b = a,
                                c = 0,
                                d;
                            while (++c < 14) {
                                d = f(b, 0) - a;
                                if (Math.abs(d) < .001) break;
                                b -= d / g(b)
                            }
                            return b
                        };
                    return function (a) {
                        return f(h(a), 1)
                    }
                };
            jQuery.easing[b] = function (b, d, e, f, g) {
                return f * c([a[0], a[1]], [a[2], a[3]])(d / g) + e
            }
        }
        return b
    }
});
/*!
 * Roto v1.2.15-ga3db5c2
 * http://github.com/rdallasgray/roto
 * 
 * A simple, flexible, touch-capable scrolling plugin for jQuery
 * 
 * Copyright 2011 Robert Dallas Gray. All rights reserved.
 * Provided under the FreeBSD license: https://github.com/rdallasgray/roto/blob/master/LICENSE.txt
 */
(function (a, b, c, d) {
    a.fn.roto = function (e) {
        var f = {
            compat: !1,
            rotoSelector: ".rotoFrame",
            btnPrev: ".prev",
            btnNext: ".next",
            direction: "h",
            shift_duration: 200,
            shift_bezier: [0, 0, 0, 1],
            drift_duration: 1800,
            drift_factor: 500,
            drift_bezier: [0, 0, .3, 1],
            bounce_duration: 400,
            bounce_bezier: [0, .5, .5, 1],
            pull_divisor: 1.7,
            timer_interval: 50,
            disable_transitions: !1,
            startOffset: 0,
            endOffset: 0,
            snap: !0
        },
            e = a.extend(f, e || {}),
            g = 1e3,
            h = "client",
            i = function () {
                try {
                    return c.createEvent("TouchEvent"), !0
                } catch (a) {
                    return !1
                }
            }(),
            j = i ? {
                start: "touchstart",
                move: "touchmove",
                end: "touchend"
            } : {
                start: "mousedown",
                move: "mousemove",
                end: "mouseup"
            },
            k = function (a) {
                return i && typeof a.originalEvent.touches != "undefined" ? a.originalEvent.touches[0] : a
            },
            l = null,
            m = null,
            n = null,
            o = null,
            p = {
                h: {
                    measure: "Width",
                    offsetName: "left",
                    coOrd: "X"
                },
                v: {
                    measure: "Height",
                    offsetName: "top",
                    coOrd: "Y"
                }
            },
            q = p[e.direction];
        if (!e.disable_transitions) {
            var r = c.body || c.documentElement,
                s = {
                    transform: "transform",
                    MozTransform: "-moz-transform",
                    WebkitTransform: "-webkit-transform"
                },
                t = {
                    transition: {
                        prop: "transition",
                        event: "transitionend"
                    },
                    MozTransition: {
                        prop: "-moz-transition",
                        event: "transitionend"
                    },
                    WebkitTransition: {
                        prop: "-webkit-transition",
                        event: "webkitTransitionEnd"
                    }
                };
            for (var u in s) if (typeof r.style[u] != "undefined") {
                l = s[u];
                break
            }
            for (var u in t) if (typeof r.style[u] != "undefined") {
                m = t[u].prop, n = t[u].event;
                break
            }
        }
        var v = m !== null;
        return this.each(function () {
            var o = a(this),
                p = o.children(e.rotoSelector).length > 0 ? o.children(e.rotoSelector).first() : o.children().first(),
                r = p.children(),
                s = 0,
                t = e.startOffset,
                u = 0,
                w = 0,
                x = -1,
                y = 0,
                z = 0,
                A = typeof o.attr("id") !== d ? o.attr("id") : "roto" + (new Date).getTime(),
                B = null,
                C = null,
                D = {
                    ready: "ready",
                    tracking: "tracking",
                    drifting: "drifting",
                    shifting: "shifting",
                    bouncing: "bouncing"
                },
                E = D.ready,
                F = !1,
                G = o.find(e.btnPrev),
                H = o.find(e.btnNext),
                I = null,
                J = function (b, c, f, h, i) {
                    var j = i;
                    if (!F || !v) j = function () {
                        S(), i()
                    }, F = !0;
                    if (v) {
                        var k = L();
                        k.timingFunction[h] === d && (k.timingFunction[h] = ["cubic-bezier(", e[h + "_bezier"].join(","), ")"].join(""));
                        var l = {};
                        l[k.durationProp] = f / g + "s", l[k.timingFunctionProp] = C.timingFunction[h], b.css(l), b.data("animationCallback", j), b.unbind(n), b.one(n, function () {
                            b.data("animationCallback", null), j()
                        }), b.css(c)
                    } else b.animate(c, f, a.bez(e[h + "_bezier"]), j)
                },
                K = function (a) {
                    if (v) {
                        var b = N();
                        a.unbind(n), a.css(M(b)), typeof a.data("animationCallback") == "function" && (a.data("animationCallback")(), a.data("animationCallback", null))
                    } else a.stop()
                },
                L = function () {
                    return C === null && (C = {
                        durationProp: m + "-duration",
                        timingFunctionProp: m + "-timing-function",
                        timingFunction: {}
                    }), C
                },
                M = function (a) {
                    var b = {};
                    if (v) {
                        if (B === null) {
                            var c = i ? "3d" : "",
                                d = c === "3d" ? "(Xpx,Ypx,0px)" : "(Xpx,Ypx)",
                                e = {
                                    X: "Y",
                                    Y: "X"
                                };
                            B = ["translate", c, d.replace(e[q.coOrd], "0")].join("")
                        }
                        b[l] = B.replace(q.coOrd, a)
                    } else b[q.offsetName] = a + "px";
                    return b
                },
                N = function () {
                    if (!v) return p.position()[q.offsetName] - s;
                    var a = p.css(l),
                        b = a.match(/\-?[0-9]+/g),
                        c = q.coOrd === "X" ? b[4] : b[5];
                    return parseInt(c)
                },
                O = function (b, c) {
                    var d = t,
                        f, g, h = c > 0 ? r.get().reverse() : r,
                        i, j, k = "outer" + q.measure;
                    return a.each(h, function (h, l) {
                        j = a(l), d = -1 * Math.ceil(j.position()[q.offsetName]), i = l, c < 0 ? (d -= e.startOffset, f = -1 * d + j[k](!0), g = -1 * b) : (d += e.endOffset, f = j.prev().length > 0 ? d + j.prev()[k](!0) : d, g = b);
                        if (d * c >= b * c || f > g) return !1
                    }), [i, d]
                },
                P = function (b, c) {
                    var d = c < 0 ? "next" : "prev",
                        e = a(O(b, c)[0]),
                        f = e;
                    while (f[d]().length > 0 && f.position()[q.offsetName] === e.position()[q.offsetName]) f = f[d]();
                    return f
                },
                Q = function (a, b, c) {
                    var b = b === 0 ? x : b;
                    return c ? -1 * Math.ceil(P(a, b).position()[q.offsetName]) : O(a, b)[1]
                },
                R = function () {
                    var a = N();
                    return a === Q(a, x, !1)
                },
                S = function () {
                    o.trigger("rotoChange", [O(N(), 1)[0]]), F = !1
                },
                T = function () {
                    z = 0, r = p.children(), r.css({
                        display: "block",
                        "float": "left"
                    });
                    if (e.direction === "h") r.each(function (b, c) {
                        z += Math.ceil(a(c)["outer" + q.measure](!0))
                    }), p[q.measure.toLowerCase()](z);
                    else {
                        var b = r.last();
                        z = Math.round(a(b).position()[q.offsetName] + a(b)["outer" + q.measure](!0))
                    }
                    y = Math.ceil(o[q.measure.toLowerCase()]()), u = Math.ceil(z - y + s + e.endOffset) * -1;
                    if (e.snap) {
                        var c = Q(u, -1, !1);
                        u = c > u ? Q(u, -1, !0) : c
                    }
                },
                U = function () {
                    return I === null && (I = typeof G == "object" && typeof G.click == "function" && typeof H == "object" && typeof H.click == "function"), I
                },
                V = function () {
                    if (!U()) return;
                    z > y - N() ? H.show() : H.hide(), N() < t ? G.show() : G.hide()
                },
                W = function (a) {
                    var b = typeof a;
                    switch (b) {
                    case "number":
                        X(a);
                        break;
                    case "object":
                        Y(a);
                        break;
                    case "string":
                        _(a)
                    }
                },
                X = function (b) {
                    if (b < 0 || b >= r.length) return;
                    var c = a(r.get(b));
                    Y(c)
                },
                Y = function (b) {
                    Z(-1 * a(b).position()[q.offsetName] + e.startOffset)
                },
                Z = function (a) {
                    J(p, M(a), e.shift_duration, "shift", function () {
                        V(), E = D.ready
                    })
                },
                _ = function (a) {
                    if (a !== "prev" && a !== "next") return;
                    dir = a === "prev" ? 1 : -1, Y(P(N(), dir))
                },
                ba = function (a) {
                    var b = 0;
                    if (E === D.shifting) return;
                    E = D.shifting, x = a;
                    var c = function (a) {
                            J(p, M(a), e.shift_duration, "shift", function () {
                                V(), E = D.ready
                            })
                        };
                    a < 0 ? b = Math.max(Q(N() - y + e.startOffset, a, !1), u) : b = Math.min(Q(N() + y - e.endOffset, a, !1), t), Z(b)
                },
                bb = function (a) {
                    var b = Math.ceil(a + w),
                        c;
                    if (b < t && b > u) c = b;
                    else var d = b >= t ? b - t : b - u,
                        c = b - d / e.pull_divisor;
                    if (E !== D.tracking) {
                        var f = {},
                            g = L();
                        f[g.durationProp] = "0s", f[g.timingFunctionProp] = "none", p.css(f)
                    }
                    E = D.tracking, p.css(M(c))
                },
                bc = function () {
                    var a = be.getPointerSpeed(),
                        b = a[0],
                        c = a[1],
                        d = N(),
                        f = b * e.drift_factor * c,
                        g = f + d;
                    g > t ? g = t : g < u ? g = u : e.snap && !R() && (g = Q(g, c, !0));
                    if (g === d) {
                        S();
                        return
                    }
                    E = D.drifting, J(p, M(g), e.drift_duration, "drift", function () {
                        E = D.ready, V()
                    })
                },
                bd = function (a) {
                    var b = a < 0 ? u : t;
                    E = D.bouncing, J(p, M(b), e.bounce_duration, "bounce", function () {
                        E = D.ready, V()
                    })
                },
                be = function () {
                    var a = 0,
                        c = 0,
                        d = 0,
                        f = null,
                        g = {
                            startCoOrd: 0,
                            endCoOrd: 0
                        };
                    return {
                        start: function () {
                            d = a = c, f = b.setInterval(function () {
                                g.startCoOrd = a, g.endCoOrd = c, a = c
                            }, e.timer_interval)
                        },
                        stop: function () {
                            clearInterval(f), g.endCoOrd = c
                        },
                        getPointerSpeed: function () {
                            var a = g.endCoOrd - g.startCoOrd,
                                b = Math.abs(a),
                                c = b / e.timer_interval,
                                f = a === 0 ? g.endCoOrd - d : a,
                                h = f <= 0 ? f === 0 ? 0 : -1 : 1;
                            return h !== 0 && (x = h), [c, h]
                        },
                        setCurrentCoOrd: function (a) {
                            c = a
                        }
                    }
                }(),
                bf = function () {
                    T(), V()
                };
            m === "-webkit-transition" && p.css("-webkit-backface-visibility", "hidden"), o.css({
                display: "block",
                overflow: "hidden",
                position: "relative"
            }), p.css({
                position: "relative",
                padding: 0,
                margin: 0
            }), p.css(M(e.startOffset)), G.length === 0 && e.btnPrev === f.btnPrev && o.attr("id") && (G = a("#" + o.attr("id") + "-prev"), H = a("#" + o.attr("id") + "-next")), a(b).resize(function () {
                bf()
            }), p.bind(j.start + ".roto." + A, function (e) {
                E = D.ready, w = N(), K(p);
                var f = p.find("a"),
                    g = {};
                i || (e.preventDefault(), c.ondragstart !== d && p.find("a, img").one("dragstart", function (a) {
                    a.preventDefault()
                }), f.length > 0 && a(c).one(j.move + ".roto." + A, function (b) {
                    f.one("click.roto." + A, function (a) {
                        a.preventDefault()
                    }), a.each(f.data("events"), function (b, c) {
                        g[b] = [], a.each(c, function (a, c) {
                            g[b].push(c)
                        })
                    }), f.unbind(), f.bind("click.roto." + A, function (a) {
                        a.preventDefault()
                    })
                })), e = k(e);
                var l = e[h + q.coOrd];
                be.setCurrentCoOrd(l), a(c).bind(j.move + ".roto." + A, function (a) {
                    a.preventDefault(), a = k(a), be.setCurrentCoOrd(a[h + q.coOrd]), bb(a[h + q.coOrd] - l)
                }), a(c).one(j.end, function () {
                    be.stop(), N() > t || N() < u ? bd(N() - t) : bc(), a(c).unbind(j.move + ".roto." + A), !i && f.length > 0 && b.setTimeout(function () {
                        f.unbind("click.roto." + A), a.each(g, function (b, c) {
                            a.each(c, function (a, b) {
                                f.bind(b.type + "." + b.namespace, b.data, b.handler)
                            })
                        })
                    }, 250)
                }), be.start()
            }), U() && (G.click(function () {
                return ba(1)
            }), H.click(function () {
                return ba(-1)
            })), o.bind("rotoGoto", function (a, b) {
                W(b)
            }), o.bind("rotoShift", function (a, b) {
                ba(b)
            }), o.bind("rotoContentChange", function () {
                bf()
            }), bf(), s = Math.ceil(N()), s !== 0 && T()
        })
    }
})(jQuery, window, document);
