(function(S) {
    var V, Z, E = "",
        d = "4.1.0",
        Q = Math.PI,
        J = Q / 2,
        B = "ontouchstart" in window,
        A = (B) ? {
            down: "touchstart",
            move: "touchmove",
            up: "touchend",
            over: "touchstart",
            out: "touchend"
        } : {
            down: "mousedown",
            move: "mousemove",
            up: "mouseup",
            over: "mouseover",
            out: "mouseout"
        },
        T = {
            backward: ["bl", "tl"],
            forward: ["br", "tr"],
            all: ["tl", "bl", "tr", "br", "l", "r"]
        },
        M = ["single", "double"],
        g = ["ltr", "rtl"],
        R = {
            acceleration: true,
            display: "double",
            duration: 600,
            page: 1,
            gradients: true,
            turnCorners: "bl,br",
            when: null
        },
        Y = {
            cornerSize: 400
        },
        G = 6,
        D = {
            init: function(n) {
                V = "WebKitCSSMatrix" in window || "MozPerspective" in document.body.style;
                Z = H();
                E = O();
                var j, l = this,
                    k = 0,
                    p = this.data(),
                    o = this.children();
                var m = S(".flipbook").turn("page");
                n = S.extend({
                    width: this.width(),
                    height: this.height(),
                    direction: this.attr("dir") || this.css("direction") || "ltr"
                }, R, n);
                p.opts = n;
                p.pageObjs = {};
                p.pages = {};
                p.pageWrap = {};
                p.pageZoom = {};
                p.pagePlace = {};
                p.pageMv = [];
                p.zoom = 1;
                p.totalPages = n.pages || 0;
                p.eventHandlers = {
                    touchStart: S.proxy(D._touchStart, this),
                    touchMove: S.proxy(D._touchMove, this),
                    touchEnd: S.proxy(D._touchEnd, this),
                    start: S.proxy(D._eventStart, this)
                };
                if (n.when) {
                    for (j in n.when) {
                        if (N(j, n.when)) {
                            this.bind(j, n.when[j])
                        }
                    }
                }
                this.css({
                    position: "relative",
                    width: n.width,
                    height: n.height
                });
                this.turn("display", n.display);
                if (n.direction !== "") {
                    this.turn("direction", n.direction)
                }
                if (V && !B && n.acceleration) {
                    this.transform(X(0, 0, true))
                }
                for (j = 0; j < o.length; j++) {
                    if (S(o[j]).attr("ignore") != "1") {
                        this.turn("addPage", o[j], ++k)
                    }
                }
                S(this).bind(A.down, p.eventHandlers.touchStart).bind("end", D._eventEnd).bind("pressed", D._eventPressed).bind("released", D._eventReleased).bind("flip", D._flip);
                S(this).parent().bind("start", p.eventHandlers.start);
                S(document).bind(A.move, p.eventHandlers.touchMove).bind(A.up, p.eventHandlers.touchEnd);
                this.turn("page", n.page);
                p.done = true;
                return this
            },
            addPage: function(n, o) {
                var m, i, l = false,
                    k = this.data(),
                    j = k.totalPages + 1;
                if (k.destroying) {
                    return false
                }
                if ((m = /\bp([0-9]+)\b/.exec(S(n).attr("class")))) {
                    o = parseInt(m[1], 10)
                }
                if (o) {
                    if (o == j) {
                        l = true
                    } else {
                        if (o > j) {
                            throw F('Page "' + o + '" cannot be inserted')
                        }
                    }
                } else {
                    o = j;
                    l = true
                }
                if (o >= 1 && o <= j) {
                    if (k.display == "double") {
                        i = (o % 2) ? " odd" : " even"
                    } else {
                        i = ""
                    }
                    if (k.done) {
                        this.turn("stop")
                    }
                    if (o in k.pageObjs) {
                        D._movePages.call(this, o, 1)
                    }
                    if (l) {
                        k.totalPages = j
                    }
                    k.pageObjs[o] = S(n).css({
                        "float": "left"
                    }).addClass("page p" + o + i);
                    if (!C() && k.pageObjs[o].hasClass("hard")) {
                        k.pageObjs[o].removeClass("hard")
                    }
                    D._addPage.call(this, o);
                    D._removeFromDOM.call(this)
                }
                return this
            },
            _addPage: function(l) {
                var i = this.data(),
                    k = i.pageObjs[l];
                if (k) {
                    if (D._necessPage.call(this, l)) {
                        if (!i.pageWrap[l]) {
                            i.pageWrap[l] = S("<div/>", {
                                "class": "page-wrapper",
                                page: l,
                                css: {
                                    position: "absolute",
                                    overflow: "hidden"
                                }
                            });
                            this.append(i.pageWrap[l]);
                            if (!i.pagePlace[l]) {
                                i.pagePlace[l] = l;
                                i.pageObjs[l].appendTo(i.pageWrap[l])
                            }
                            var j = D._pageSize.call(this, l, true);
                            k.css({
                                width: j.width,
                                height: j.height
                            });
                            i.pageWrap[l].css(j)
                        }
                        if (i.pagePlace[l] == l) {
                            D._makeFlip.call(this, l)
                        }
                    } else {
                        i.pagePlace[l] = 0;
                        if (i.pageObjs[l]) {
                            i.pageObjs[l].remove()
                        }
                    }
                }
            },
            hasPage: function(i) {
                return N(i, this.data().pageObjs)
            },
            center: function(m) {
                var k = this.data(),
                    i = S(this).turn("size"),
                    j = 0;
                if (!k.noCenter) {
                    if (k.display == "double") {
                        var l = this.turn("view", m || k.tpage || k.page);
                        if (k.direction == "ltr") {
                            if (!l[0]) {
                                j -= i.width / 4
                            } else {
                                if (!l[1]) {
                                    j += i.width / 4
                                }
                            }
                        } else {
                            if (!l[0]) {
                                j += i.width / 4
                            } else {
                                if (!l[1]) {
                                    j -= i.width / 4
                                }
                            }
                        }
                    }
                    S(this).css({
                        marginLeft: j
                    })
                }
                return this
            },
            destroy: function() {
                var l, k = this,
                    j = this.data(),
                    i = ["end", "first", "flip", "last", "pressed", "released", "start", "turning", "turned", "zooming", "missing"];
                if (a("destroying", this) == "prevented") {
                    return
                }
                j.destroying = true;
                S.each(i, function(n, m) {
                    k.unbind(m)
                });
                this.parent().unbind("start", j.eventHandlers.start);
                S(document).unbind(A.move, j.eventHandlers.touchMove).unbind(A.up, j.eventHandlers.touchEnd);
                while (j.totalPages !== 0) {
                    this.turn("removePage", j.totalPages)
                }
                if (j.fparent) {
                    j.fparent.remove()
                }
                if (j.shadow) {
                    j.shadow.remove()
                }
                this.removeData();
                j = null;
                return this
            },
            is: function() {
                return typeof(this.data().pages) == "object"
            },
            zoom: function(n) {
                var k = this.data();
                if (typeof(n) == "number") {
                    if (n < 0.001 || n > 100) {
                        throw F(n + " is not a value for zoom")
                    }
                    if (a("zooming", this, [n, k.zoom]) == "prevented") {
                        return this
                    }
                    var l = this.turn("size"),
                        p = this.turn("view"),
                        m = 1 / k.zoom,
                        q = Math.round(l.width * m * n),
                        j = Math.round(l.height * m * n);
                    k.zoom = n;
                    S(this).turn("stop").turn("size", q, j);
                    if (k.opts.autoCenter) {
                        this.turn("center")
                    }
                    D._updateShadow.call(this);
                    for (var o = 0; o < p.length; o++) {
                        if (p[o] && k.pageZoom[p[o]] != k.zoom) {
                            this.trigger("zoomed", [p[o], p, k.pageZoom[p[o]], k.zoom]);
                            k.pageZoom[p[o]] = k.zoom
                        }
                    }
                    return this
                } else {
                    return k.zoom
                }
            },
            _pageSize: function(o, l) {
                var j = this.data(),
                    m = {};
                if (j.display == "single") {
                    m.width = this.width();
                    m.height = this.height();
                    if (l) {
                        m.top = 0;
                        m.left = 0;
                        m.right = "auto"
                    }
                } else {
                    var n = this.width() / 2,
                        i = this.height();
                    if (j.pageObjs[o].hasClass("own-size")) {
                        m.width = j.pageObjs[o].width();
                        m.height = j.pageObjs[o].height()
                    } else {
                        m.width = n;
                        m.height = i
                    }
                    if (l) {
                        var k = o % 2;
                        m.top = (i - m.height) / 2;
                        if (j.direction == "ltr") {
                            m[(k) ? "right" : "left"] = n - m.width;
                            m[(k) ? "left" : "right"] = "auto"
                        } else {
                            m[(k) ? "left" : "right"] = n - m.width;
                            m[(k) ? "right" : "left"] = "auto"
                        }
                    }
                }
                return m
            },
            _makeFlip: function(l) {
                var i = this.data();
                if (!i.pages[l] && i.pagePlace[l] == l) {
                    var k = i.display == "single",
                        j = l % 2;
                    i.pages[l] = i.pageObjs[l].css(D._pageSize.call(this, l)).flip({
                        page: l,
                        next: (j || k) ? l + 1 : l - 1,
                        turn: this
                    }).flip("disable", i.disabled);
                    D._setPageLoc.call(this, l);
                    i.pageZoom[l] = i.zoom
                }
                return i.pages[l]
            },
            _makeRange: function() {
                var k, j, i = this.data();
                if (i.totalPages < 1) {
                    return
                }
                j = this.turn("range");
                for (k = j[0]; k <= j[1]; k++) {
                    D._addPage.call(this, k)
                }
            },
            range: function(n) {
                var k, j, i, l, m = this.data();
                n = n || m.tpage || m.page || 1;
                l = D._view.call(this, n);
                if (n < 1 || n > m.totalPages) {
                    throw F('"' + n + '" is not a valid page')
                }
                l[1] = l[1] || l[0];
                if (l[0] >= 1 && l[1] <= m.totalPages) {
                    k = Math.floor((G - 2) / 2);
                    if (m.totalPages - l[1] > l[0]) {
                        j = Math.min(l[0] - 1, k);
                        i = 2 * k - j
                    } else {
                        i = Math.min(m.totalPages - l[1], k);
                        j = 2 * k - i
                    }
                } else {
                    j = G - 1;
                    i = G - 1
                }
                return [Math.max(1, l[0] - j), Math.min(m.totalPages, l[1] + i)]
            },
            _necessPage: function(j) {
                if (j === 0) {
                    return true
                }
                var i = this.turn("range");
                return this.data().pageObjs[j].hasClass("fixed") || (j >= i[0] && j <= i[1])
            },
            _removeFromDOM: function() {
                var j, i = this.data();
                for (j in i.pageWrap) {
                    if (N(j, i.pageWrap) && !D._necessPage.call(this, j)) {
                        D._removePageFromDOM.call(this, j)
                    }
                }
            },
            _removePageFromDOM: function(k) {
                var i = this.data();
                if (i.pages[k]) {
                    var j = i.pages[k].data();
                    b._moveFoldingPage.call(i.pages[k], false);
                    if (j.f && j.f.fwrapper) {
                        j.f.fwrapper.remove()
                    }
                    i.pages[k].removeData();
                    i.pages[k].remove();
                    delete i.pages[k]
                }
                if (i.pageObjs[k]) {
                    i.pageObjs[k].remove()
                }
                if (i.pageWrap[k]) {
                    i.pageWrap[k].remove();
                    delete i.pageWrap[k]
                }
                D._removeMv.call(this, k);
                delete i.pagePlace[k];
                delete i.pageZoom[k]
            },
            removePage: function(j) {
                var i = this.data();
                if (j == "*") {
                    while (i.totalPages !== 0) {
                        this.turn("removePage", i.totalPages)
                    }
                } else {
                    if (j < 1 || j > i.totalPages) {
                        throw F("The page " + j + " doesn't exist")
                    }
                    if (i.pageObjs[j]) {
                        this.turn("stop");
                        D._removePageFromDOM.call(this, j);
                        delete i.pageObjs[j]
                    }
                    D._movePages.call(this, j, -1);
                    i.totalPages = i.totalPages - 1;
                    if (i.page > i.totalPages) {
                        i.page = null;
                        D._fitPage.call(this, i.totalPages)
                    } else {
                        D._makeRange.call(this);
                        this.turn("update")
                    }
                }
                return this
            },
            _movePages: function(i, j) {
                var o, k = this,
                    n = this.data(),
                    l = n.display == "single",
                    m = function(s) {
                        var q = s + j,
                            r = q % 2,
                            p = (r) ? " odd " : " even ";
                        if (n.pageObjs[s]) {
                            n.pageObjs[q] = n.pageObjs[s].removeClass("p" + s + " odd even").addClass("p" + q + p)
                        }
                        if (n.pagePlace[s] && n.pageWrap[s]) {
                            n.pagePlace[q] = q;
                            if (n.pageObjs[q].hasClass("fixed")) {
                                n.pageWrap[q] = n.pageWrap[s].attr("page", q)
                            } else {
                                n.pageWrap[q] = n.pageWrap[s].css(D._pageSize.call(k, q, true)).attr("page", q)
                            }
                            if (n.pages[s]) {
                                n.pages[q] = n.pages[s].flip("options", {
                                    page: q,
                                    next: (l || r) ? q + 1 : q - 1
                                })
                            }
                            if (j) {
                                delete n.pages[s];
                                delete n.pagePlace[s];
                                delete n.pageZoom[s];
                                delete n.pageObjs[s];
                                delete n.pageWrap[s]
                            }
                        }
                    };
                if (j > 0) {
                    for (o = n.totalPages; o >= i; o--) {
                        m(o)
                    }
                } else {
                    for (o = i; o <= n.totalPages; o++) {
                        m(o)
                    }
                }
            },
            display: function(k) {
                var l = this.data(),
                    j = l.display;
                if (k === undefined) {
                    return j
                } else {
                    if (S.inArray(k, M) == -1) {
                        throw F('"' + k + '" is not a value for display')
                    }
                    switch (k) {
                        case "single":
                            if (!l.pageObjs[0]) {
                                this.turn("stop").css({
                                    "overflow": "hidden"
                                });
                                l.pageObjs[0] = S("<div />", {
                                    "class": "page p-temporal"
                                }).css({
                                    width: this.width(),
                                    height: this.height()
                                }).appendTo(this)
                            }
                            this.addClass("shadow");
                            break;
                        case "double":
                            if (l.pageObjs[0]) {
                                this.turn("stop").css({
                                    "overflow": ""
                                });
                                l.pageObjs[0].remove();
                                delete l.pageObjs[0]
                            }
                            this.removeClass("shadow");
                            break
                    }
                    l.display = k;
                    if (j) {
                        var i = this.turn("size");
                        D._movePages.call(this, 1, 0);
                        this.turn("size", i.width, i.height).turn("update")
                    }
                    return this
                }
            },
            direction: function(i) {
                var j = this.data();
                if (i === undefined) {
                    return j.direction
                } else {
                    i = i.toLowerCase();
                    if (S.inArray(i, g) == -1) {
                        throw F('"' + i + '" is not a value for direction')
                    }
                    if (i == "rtl") {
                        S(this).attr("dir", "ltr").css({
                            direction: "ltr"
                        })
                    }
                    j.direction = i;
                    if (j.done) {
                        this.turn("size", S(this).width(), S(this).height())
                    }
                    return this
                }
            },
            animating: function() {
                return this.data().pageMv.length > 0
            },
            corner: function() {
                var j, k, i = this.data();
                for (k in i.pages) {
                    if (N(k, i.pages)) {
                        if ((j = i.pages[k].flip("corner"))) {
                            return j
                        }
                    }
                }
                return false
            },
            data: function() {
                return this.data()
            },
            disable: function(j) {
                var l, i = this.data(),
                    k = this.turn("view");
                i.disabled = j === undefined || j === true;
                for (l in i.pages) {
                    if (N(l, i.pages)) {
                        i.pages[l].flip("disable", (i.disabled) ? true : S.inArray(parseInt(l, 10), k) == -1)
                    }
                }
                return this
            },
            disabled: function(i) {
                if (i === undefined) {
                    return this.data().disabled === true
                } else {
                    return this.turn("disable", i)
                }
            },
            size: function(m, i) {
                if (m === undefined || i === undefined) {
                    return {
                        width: this.width(),
                        height: this.height()
                    }
                } else {
                    this.turn("stop");
                    var n, k, j = this.data(),
                        l = (j.display == "double") ? m / 2 : m;
                    this.css({
                        width: m,
                        height: i
                    });
                    if (j.pageObjs[0]) {
                        j.pageObjs[0].css({
                            width: l,
                            height: i
                        })
                    }
                    for (n in j.pageWrap) {
                        if (!N(n, j.pageWrap)) {
                            continue
                        }
                        k = D._pageSize.call(this, n, true);
                        j.pageObjs[n].css({
                            width: k.width,
                            height: k.height
                        });
                        j.pageWrap[n].css(k);
                        if (j.pages[n]) {
                            j.pages[n].css({
                                width: k.width,
                                height: k.height
                            })
                        }
                    }
                    this.turn("resize");
                    return this
                }
            },
            resize: function() {
                var j, i = this.data();
                if (i.pages[0]) {
                    i.pageWrap[0].css({
                        left: -this.width()
                    });
                    i.pages[0].flip("resize", true)
                }
                for (j = 1; j <= i.totalPages; j++) {
                    if (i.pages[j]) {
                        i.pages[j].flip("resize", true)
                    }
                }
                D._updateShadow.call(this);
                if (i.opts.autoCenter) {
                    this.turn("center")
                }
            },
            _removeMv: function(l) {
                var j, k = this.data();
                for (j = 0; j < k.pageMv.length; j++) {
                    if (k.pageMv[j] == l) {
                        k.pageMv.splice(j, 1);
                        return true
                    }
                }
                return false
            },
            _addMv: function(j) {
                var i = this.data();
                D._removeMv.call(this, j);
                i.pageMv.push(j)
            },
            _view: function(j) {
                var i = this.data();
                j = j || i.page;
                if (i.display == "double") {
                    return (j % 2) ? [j - 1, j] : [j, j + 1]
                } else {
                    return [j]
                }
            },
            view: function(k) {
                var i = this.data(),
                    j = D._view.call(this, k);
                if (i.display == "double") {
                    return [(j[0] > 0) ? j[0] : 0, (j[1] <= i.totalPages) ? j[1] : 0]
                } else {
                    return [(j[0] > 0 && j[0] <= i.totalPages) ? j[0] : 0]
                }
            },
            stop: function(m, l) {
                if (this.turn("animating")) {
                    var j, k, o, n = this.data();
                    if (n.tpage) {
                        n.page = n.tpage;
                        delete n["tpage"]
                    }
                    for (j = 0; j < n.pageMv.length; j++) {
                        if (!n.pageMv[j] || n.pageMv[j] === m) {
                            continue
                        }
                        o = n.pages[n.pageMv[j]];
                        k = o.data().f.opts;
                        o.flip("hideFoldedPage", l);
                        if (!l) {
                            b._moveFoldingPage.call(o, false)
                        }
                        if (k.force) {
                            k.next = (k.page % 2 === 0) ? k.page - 1 : k.page + 1;
                            delete k["force"]
                        }
                    }
                }
                this.turn("update");
                return this
            },
            pages: function(i) {
                var k = this.data();
                if (i) {
                    if (i < k.totalPages) {
                        for (var j = k.totalPages; j > i; j--) {
                            this.turn("removePage", j)
                        }
                    }
                    k.totalPages = i;
                    D._fitPage.call(this, k.page);
                    return this
                } else {
                    return k.totalPages
                }
            },
            _missing: function(m) {
                var j = this.data();
                if (j.totalPages < 1) {
                    return
                }
                var k, l = this.turn("range", m),
                    i = [];
                for (k = l[0]; k <= l[1]; k++) {
                    if (!j.pageObjs[k]) {
                        i.push(k)
                    }
                }
                if (i.length > 0) {
                    this.trigger("missing", [i])
                }
            },
            _fitPage: function(m) {
                var k = this.data(),
                    l = this.turn("view", m);
                D._missing.call(this, m);
                if (!k.pageObjs[m]) {
                    return
                }
                k.page = m;
                this.turn("stop");
                for (var j = 0; j < l.length; j++) {
                    if (l[j] && k.pageZoom[l[j]] != k.zoom) {
                        this.trigger("zoomed", [l[j], l, k.pageZoom[l[j]], k.zoom]);
                        k.pageZoom[l[j]] = k.zoom
                    }
                }
                D._removeFromDOM.call(this);
                D._makeRange.call(this);
                D._updateShadow.call(this);
                this.trigger("turned", [m, l]);
                this.turn("update");
                if (k.opts.autoCenter) {
                    this.turn("center")
                }
            },
            _turnPage: function(m) {
                var l, t, s = this.data(),
                    o = s.pagePlace[m],
                    i = this.turn("view"),
                    r = this.turn("view", m);
                if (s.page != m) {
                    var j = s.page;
                    if (a("turning", this, [m, r]) == "prevented") {
                        if (j == s.page && S.inArray(o, s.pageMv) != -1) {
                            s.pages[o].flip("hideFoldedPage", true)
                        }
                        return
                    }
                    if (S.inArray(1, r) != -1) {
                        this.trigger("first")
                    }
                    if (S.inArray(s.totalPages, r) != -1) {
                        this.trigger("last")
                    }
                }
                if (s.display == "single") {
                    l = i[0];
                    t = r[0]
                } else {
                    if (i[1] && m > i[1]) {
                        l = i[1];
                        t = r[0]
                    } else {
                        if (i[0] && m < i[0]) {
                            l = i[0];
                            t = r[1]
                        }
                    }
                }
                var k = s.opts.turnCorners.split(","),
                    q = s.pages[l].data().f,
                    p = q.opts,
                    n = q.point;
                D._missing.call(this, m);
                if (!s.pageObjs[m]) {
                    return
                }
                this.turn("stop");
                s.page = m;
                D._makeRange.call(this);
                s.tpage = t;
                if (p.next != t) {
                    p.next = t;
                    p.force = true
                }
                this.turn("update");
                q.point = n;
                if (q.effect == "hard") {
                    if (s.direction == "ltr") {
                        s.pages[l].flip("turnPage", (m > l) ? "r" : "l")
                    } else {
                        s.pages[l].flip("turnPage", (m > l) ? "l" : "r")
                    }
                } else {
                    if (s.direction == "ltr") {
                        s.pages[l].flip("turnPage", k[(m > l) ? 1 : 0])
                    } else {
                        s.pages[l].flip("turnPage", k[(m > l) ? 0 : 1])
                    }
                }
            },
            page: function(j) {
                var i = this.data();
                if (j === undefined) {
                    return i.page
                } else {
                    if (!i.disabled && !i.destroying) {
                        j = parseInt(j, 10);
                        if (j > 0 && j <= i.totalPages) {
                            if (j != i.page) {
                                if (!i.done || S.inArray(j, this.turn("view")) != -1) {
                                    D._fitPage.call(this, j)
                                } else {
                                    D._turnPage.call(this, j)
                                }
                            }
                            return this
                        } else {
                            throw F("The page " + j + " does not exist")
                        }
                    }
                }
            },
            next: function() {
                return this.turn("page", Math.min(this.data().totalPages, D._view.call(this, this.data().page).pop() + 1))
            },
            previous: function() {
                return this.turn("page", Math.max(1, D._view.call(this, this.data().page).shift() - 1))
            },
            peel: function(l, i) {
                var m = this.data(),
                    k = this.turn("view");
                i = (i === undefined) ? true : i === true;
                if (l === false) {
                    this.turn("stop", null, i)
                } else {
                    if (m.display == "single") {
                        m.pages[m.page].flip("peel", l, i)
                    } else {
                        var j;
                        if (m.direction == "ltr") {
                            j = (l.indexOf("l") != -1) ? k[0] : k[1]
                        } else {
                            j = (l.indexOf("l") != -1) ? k[1] : k[0]
                        }
                        if (m.pages[j]) {
                            m.pages[j].flip("peel", l, i)
                        }
                    }
                }
                return this
            },
            _addMotionPage: function() {
                var i = S(this).data().f.opts,
                    j = i.turn,
                    k = j.data();
                D._addMv.call(j, i.page)
            },
            _eventStart: function(i, j, l) {
                var m = j.turn.data(),
                    k = m.pageZoom[j.page];
                if (i.isDefaultPrevented()) {
                    D._updateShadow.call(j.turn);
                    return
                }
                if (k && k != m.zoom) {
                    j.turn.trigger("zoomed", [j.page, j.turn.turn("view", j.page), k, m.zoom]);
                    m.pageZoom[j.page] = m.zoom
                }
                if (m.display == "single" && l) {
                    if ((l.charAt(1) == "l" && m.direction == "ltr") || (l.charAt(1) == "r" && m.direction == "rtl")) {
                        j.next = (j.next < j.page) ? j.next : j.page - 1;
                        j.force = true
                    } else {
                        j.next = (j.next > j.page) ? j.next : j.page + 1
                    }
                }
                D._addMotionPage.call(i.target);
                D._updateShadow.call(j.turn)
            },
            _eventEnd: function(i, o, p) {
                var n = S(i.target),
                    l = n.data().f,
                    k = o.turn,
                    m = k.data();
                if (p) {
                    var j = m.tpage || m.page;
                    if (j == o.next || j == o.page) {
                        delete m.tpage;
                        D._fitPage.call(k, j || o.next, true)
                    }
                } else {
                    D._removeMv.call(k, o.page);
                    D._updateShadow.call(k);
                    k.turn("update")
                }
            },
            _eventPressed: function(i) {
                var n, j = S(i.target).data().f,
                    l = j.opts.turn,
                    m = l.data(),
                    k = m.pages;
                m.mouseAction = true;
                l.turn("update");
                return j.time = new Date().getTime()
            },
            _eventReleased: function(i, j) {
                var n, o = S(i.target),
                    l = o.data().f,
                    k = l.opts.turn,
                    m = k.data();
                if (m.display == "single") {
                    n = (j.corner == "br" || j.corner == "tr") ? j.x < o.width() / 2 : j.x > o.width() / 2
                } else {
                    n = j.x < 0 || j.x > o.width()
                }
                if ((new Date()).getTime() - l.time < 200 || n) {
                    i.preventDefault();
                    D._turnPage.call(k, l.opts.next)
                }
                m.mouseAction = false
            },
            _flip: function(i) {
                i.stopPropagation();
                var j = S(i.target).data().f.opts;
                var k = i.target.id;
                j.turn.trigger("turn", [j.next]);
                if (j.turn.data().opts.autoCenter) {
                    j.turn.turn("center", j.next)
                }
                S(".fanye").show();
                if (k == "last") {
                    S("#loading").remove();
                    S(".flipbook-viewport").hide();
                    S("#end").show()
                }
            },
            _touchStart: function() {
                var j = this.data();
                for (var i in j.pages) {
                    if (N(i, j.pages) && b._eventStart.apply(j.pages[i], arguments) === false) {
                        return false
                    }
                }
            },
            _touchMove: function() {
                var j = this.data();
                for (var i in j.pages) {
                    if (N(i, j.pages)) {
                        b._eventMove.apply(j.pages[i], arguments)
                    }
                }
            },
            _touchEnd: function() {
                var j = this.data();
                if (S(".fanye").css("display") == "block") {
                    S(".fanye").hide()
                } else {
                    S(".fanye").show()
                }
                for (var i in j.pages) {
                    if (N(i, j.pages)) {
                        b._eventEnd.apply(j.pages[i], arguments)
                    }
                }
            },
            calculateZ: function(w) {
                var q, n, v, k, t, s = this,
                    m = this.data(),
                    j = this.turn("view"),
                    u = j[0] || j[1],
                    o = w.length - 1,
                    l = {
                        pageZ: {},
                        partZ: {},
                        pageV: {}
                    },
                    p = function(r) {
                        var i = s.turn("view", r);
                        if (i[0]) {
                            l.pageV[i[0]] = true
                        }
                        if (i[1]) {
                            l.pageV[i[1]] = true
                        }
                    };
                for (q = 0; q <= o; q++) {
                    n = w[q];
                    v = m.pages[n].data().f.opts.next;
                    k = m.pagePlace[n];
                    p(n);
                    p(v);
                    t = (m.pagePlace[v] == v) ? v : n;
                    l.pageZ[t] = m.totalPages - Math.abs(u - t);
                    l.partZ[k] = m.totalPages * 2 - o + q
                }
                return l
            },
            update: function() {
                var l, k = this.data();
                if (this.turn("animating") && k.pageMv[0] !== 0) {
                    var i, q, o, m = this.turn("calculateZ", k.pageMv),
                        j = this.turn("corner"),
                        n = this.turn("view"),
                        r = this.turn("view", k.tpage);
                    for (l in k.pageWrap) {
                        if (!N(l, k.pageWrap)) {
                            continue
                        }
                        o = k.pageObjs[l].hasClass("fixed");
                        k.pageWrap[l].css({
                            display: (m.pageV[l] || o) ? "" : "none",
                            zIndex: (k.pageObjs[l].hasClass("hard") ? m.partZ[l] : m.pageZ[l]) || (o ? -1 : 0)
                        });
                        if ((i = k.pages[l])) {
                            i.flip("z", m.partZ[l] || null);
                            if (m.pageV[l]) {
                                i.flip("resize")
                            }
                            if (k.tpage) {
                                i.flip("hover", false).flip("disable", S.inArray(parseInt(l, 10), k.pageMv) == -1 && l != r[0] && l != r[1])
                            } else {
                                i.flip("hover", j === false).flip("disable", l != n[0] && l != n[1])
                            }
                        }
                    }
                } else {
                    for (l in k.pageWrap) {
                        if (!N(l, k.pageWrap)) {
                            continue
                        }
                        var s = D._setPageLoc.call(this, l);
                        if (k.pages[l]) {
                            k.pages[l].flip("disable", k.disabled || s != 1).flip("hover", true).flip("z", null)
                        }
                    }
                }
                return this
            },
            _updateShadow: function() {
                var j, p, m, l = this.data(),
                    o = this.width(),
                    k = this.height(),
                    q = (l.display == "single") ? o : o / 2;
                j = this.turn("view");
                if (!l.shadow) {
                    l.shadow = S("<div />", {
                        "class": "shadow",
                        "css": f(0, 0, 0).css
                    }).appendTo(this)
                }
                for (var n = 0; n < l.pageMv.length; n++) {
                    if (!j[0] || !j[1]) {
                        break
                    }
                    j = this.turn("view", l.pages[l.pageMv[n]].data().f.opts.next);
                    p = this.turn("view", l.pageMv[n]);
                    j[0] = j[0] && p[0];
                    j[1] = j[1] && p[1]
                }
                if (!j[0]) {
                    m = (l.direction == "ltr") ? 1 : 2
                } else {
                    if (!j[1]) {
                        m = (l.direction == "ltr") ? 2 : 1
                    } else {
                        m = 3
                    }
                }
                switch (m) {
                    case 1:
                        l.shadow.css({
                            width: q,
                            height: k,
                            top: 0,
                            left: q
                        });
                        break;
                    case 2:
                        l.shadow.css({
                            width: q,
                            height: k,
                            top: 0,
                            left: 0
                        });
                        break;
                    case 3:
                        l.shadow.css({
                            width: o,
                            height: k,
                            top: 0,
                            left: 0
                        });
                        break
                }
            },
            _setPageLoc: function(l) {
                var i = this.data(),
                    j = this.turn("view"),
                    k = 0;
                if (l == j[0] || l == j[1]) {
                    k = 1
                } else {
                    if ((i.display == "single" && l == j[0] + 1) || (i.display == "double" && l == j[0] - 2 || l == j[1] + 2)) {
                        k = 2
                    }
                }
                if (!this.turn("animating")) {
                    switch (k) {
                        case 1:
                            i.pageWrap[l].css({
                                zIndex: i.totalPages,
                                display: ""
                            });
                            break;
                        case 2:
                            i.pageWrap[l].css({
                                zIndex: i.totalPages - 1,
                                display: ""
                            });
                            break;
                        case 0:
                            i.pageWrap[l].css({
                                zIndex: 0,
                                display: (i.pageObjs[l].hasClass("fixed")) ? "" : "none"
                            });
                            break
                    }
                }
                return k
            },
            options: function(j) {
                if (j === undefined) {
                    return this.data().opts
                } else {
                    var k = this.data();
                    S.extend(k.opts, j);
                    if (j.pages) {
                        this.turn("pages", j.pages)
                    }
                    if (j.page) {
                        this.turn("page", j.page)
                    }
                    if (j.display) {
                        this.turn("display", j.display)
                    }
                    if (j.direction) {
                        this.turn("direction", j.direction)
                    }
                    if (j.width && j.height) {
                        this.turn("size", j.width, j.height)
                    }
                    if (j.when) {
                        for (var i in j.when) {
                            if (N(i, j.when)) {
                                this.unbind(i).bind(i, j.when[i])
                            }
                        }
                    }
                    return this
                }
            },
            version: function() {
                return d
            }
        },
        b = {
            init: function(i) {
                this.data({
                    f: {
                        disabled: false,
                        hover: false,
                        effect: (this.hasClass("hard")) ? "hard" : "sheet"
                    }
                });
                this.flip("options", i);
                b._addPageWrapper.call(this);
                return this
            },
            setData: function(i) {
                var j = this.data();
                j.f = S.extend(j.f, i);
                return this
            },
            options: function(i) {
                var j = this.data().f;
                if (i) {
                    b.setData.call(this, {
                        opts: S.extend({}, j.opts || Y, i)
                    });
                    return this
                } else {
                    return j.opts
                }
            },
            z: function(i) {
                var j = this.data().f;
                j.opts["z-index"] = i;
                if (j.fwrapper) {
                    j.fwrapper.css({
                        zIndex: i || parseInt(j.parent.css("z-index"), 10) || 0
                    })
                }
                return this
            },
            _cAllowed: function() {
                var l = this.data().f,
                    j = l.opts.page,
                    i = l.opts.turn.data(),
                    k = j % 2;
                if (l.effect == "hard") {
                    return (i.direction == "ltr") ? [(k) ? "r" : "l"] : [(k) ? "l" : "r"]
                } else {
                    if (i.display == "single") {
                        if (j == 1) {
                            return (i.direction == "ltr") ? T["forward"] : T["backward"]
                        } else {
                            if (j == i.totalPages) {
                                return (i.direction == "ltr") ? T["backward"] : T["forward"]
                            } else {
                                return T["all"]
                            }
                        }
                    } else {
                        return (i.direction == "ltr") ? T[(k) ? "forward" : "backward"] : T[(k) ? "backward" : "forward"]
                    }
                }
            },
            _cornerActivated: function(k) {
                var o = this.data().f,
                    m = this.width(),
                    j = this.height(),
                    l = {
                        x: k.x,
                        y: k.y,
                        corner: ""
                    },
                    n = o.opts.cornerSize;
                if (l.x <= 0 || l.y <= 0 || l.x >= m || l.y >= j) {
                    return false
                }
                var i = b._cAllowed.call(this);
                switch (o.effect) {
                    case "hard":
                        if (l.x > m - n / 2) {
                            l.corner = "r"
                        } else {
                            if (l.x < n) {
                                l.corner = "l"
                            } else {
                                return false
                            }
                        }
                        break;
                    case "sheet":
                        if (l.y < n) {
                            l.corner += "t"
                        } else {
                            if (l.y >= j - n) {
                                l.corner += "b"
                            } else {
                                return false
                            }
                        }
                        if (l.x <= n / 2) {
                            l.corner += "l"
                        } else {
                            if (l.x >= m - n / 2) {
                                l.corner += "r"
                            } else {
                                return false
                            }
                        }
                        break
                }
                return (!l.corner || S.inArray(l.corner, i) == -1) ? false : l
            },
            _isIArea: function(i) {
                var j = this.data().f.parent.offset();
                i = (B && i.originalEvent) ? i.originalEvent.touches[0] : i;
                return b._cornerActivated.call(this, {
                    x: i.pageX - j.left,
                    y: i.pageY - j.top
                })
            },
            _c: function(j, i) {
                i = i || 0;
                switch (j) {
                    case "tl":
                        return L(i, i);
                    case "tr":
                        return L(this.width() - i, i);
                    case "bl":
                        return L(i, this.height() - i);
                    case "br":
                        return L(this.width() - i, this.height() - i);
                    case "l":
                        return L(i, 0);
                    case "r":
                        return L(this.width() - i, 0)
                }
            },
            _c2: function(i) {
                switch (i) {
                    case "tl":
                        return L(this.width() * 2, 0);
                    case "tr":
                        return L(-this.width(), 0);
                    case "bl":
                        return L(this.width() * 2, this.height());
                    case "br":
                        return L(-this.width(), this.height());
                    case "l":
                        return L(this.width() * 2, 0);
                    case "r":
                        return L(-this.width(), 0)
                }
            },
            _foldingPage: function() {
                var j = this.data().f;
                if (!j) {
                    return
                }
                var i = j.opts;
                if (i.turn) {
                    j = i.turn.data();
                    if (j.display == "single") {
                        return (i.next > 1 || i.page > 1) ? j.pageObjs[0] : null
                    } else {
                        return j.pageObjs[i.next]
                    }
                }
            },
            _backGradient: function() {
                var k = this.data().f,
                    i = k.opts.turn.data(),
                    j = i.opts.gradients && (i.display == "single" || (k.opts.page != 2 && k.opts.page != i.totalPages - 1));
                if (j && !k.bshadow) {
                    k.bshadow = S("<div/>", f(0, 0, 1)).css({
                        "position": "",
                        width: this.width(),
                        height: this.height()
                    }).appendTo(k.parent)
                }
                return j
            },
            type: function() {
                return this.data().f.effect
            },
            resize: function(n) {
                var o = this.data().f,
                    k = o.opts.turn.data(),
                    m = this.width(),
                    j = this.height();
                switch (o.effect) {
                    case "hard":
                        if (n) {
                            o.wrapper.css({
                                width: m,
                                height: j
                            });
                            o.fpage.css({
                                width: m,
                                height: j
                            });
                            if (k.opts.gradients) {
                                o.ashadow.css({
                                    width: m,
                                    height: j
                                });
                                o.bshadow.css({
                                    width: m,
                                    height: j
                                })
                            }
                        }
                        break;
                    case "sheet":
                        if (n) {
                            var i = Math.round(Math.sqrt(Math.pow(m, 2) + Math.pow(j, 2)));
                            o.wrapper.css({
                                width: i,
                                height: i
                            });
                            o.fwrapper.css({
                                width: i,
                                height: i
                            }).children(":first-child").css({
                                width: m,
                                height: j
                            });
                            o.fpage.css({
                                width: m,
                                height: j
                            });
                            if (k.opts.gradients) {
                                o.ashadow.css({
                                    width: m,
                                    height: j
                                })
                            }
                            if (b._backGradient.call(this)) {
                                o.bshadow.css({
                                    width: m,
                                    height: j
                                })
                            }
                        }
                        if (o.parent.is(":visible")) {
                            var l = K(o.parent[0]);
                            o.fwrapper.css({
                                top: l.top,
                                left: l.left
                            });
                            l = K(o.opts.turn[0]);
                            o.fparent.css({
                                top: -l.top,
                                left: -l.left
                            })
                        }
                        this.flip("z", o.opts["z-index"]);
                        break
                }
            },
            _addPageWrapper: function() {
                var m, k = this.data().f,
                    i = k.opts.turn.data(),
                    p = this.parent();
                k.parent = p;
                if (!k.wrapper) {
                    switch (k.effect) {
                        case "hard":
                            var l = {};
                            l[E + "transform-style"] = "preserve-3d";
                            l[E + "backface-visibility"] = "hidden";
                            k.wrapper = S("<div/>", f(0, 0, 2)).css(l).appendTo(p).prepend(this);
                            k.fpage = S("<div/>", f(0, 0, 1)).css(l).appendTo(p);
                            if (i.opts.gradients) {
                                k.ashadow = S("<div/>", f(0, 0, 0)).hide().appendTo(p);
                                k.bshadow = S("<div/>", f(0, 0, 0))
                            }
                            break;
                        case "sheet":
                            var n = this.width(),
                                q = this.height(),
                                j = Math.round(Math.sqrt(Math.pow(n, 2) + Math.pow(q, 2)));
                            k.fparent = k.opts.turn.data().fparent;
                            if (!k.fparent) {
                                var o = S("<div/>", {
                                    css: {
                                        "pointer-events": "none"
                                    }
                                }).hide();
                                o.data().flips = 0;
                                o.css(f(0, 0, "auto", "visible").css).appendTo(k.opts.turn);
                                k.opts.turn.data().fparent = o;
                                k.fparent = o
                            }
                            this.css({
                                position: "absolute",
                                top: 0,
                                left: 0,
                                bottom: "auto",
                                right: "auto"
                            });
                            k.wrapper = S("<div/>", f(0, 0, this.css("z-index"))).appendTo(p).prepend(this);
                            k.fwrapper = S("<div/>", f(p.offset().top, p.offset().left)).hide().appendTo(k.fparent);
                            k.fpage = S("<div/>", f(0, 0, 0, "visible")).css({
                                cursor: "default"
                            }).appendTo(k.fwrapper);
                            if (i.opts.gradients) {
                                k.ashadow = S("<div/>", f(0, 0, 1)).appendTo(k.fpage)
                            }
                            b.setData.call(this, k);
                            break
                    }
                }
                b.resize.call(this, true)
            },
            _fold: function(Ag) {
                var Ao = this.data().f,
                    Ac = Ao.opts.turn.data(),
                    Ar = b._c.call(this, Ag.corner),
                    n = this.width(),
                    s = this.height();
                switch (Ao.effect) {
                    case "hard":
                        if (Ag.corner == "l") {
                            Ag.x = Math.min(Math.max(Ag.x, 0), n * 2)
                        } else {
                            Ag.x = Math.max(Math.min(Ag.x, n), -n)
                        }
                        var Am, Aa, z, Ab, Ad, Aq = Ac.totalPages,
                            At = Ao.opts["z-index"] || Aq,
                            Aj = {
                                "overflow": "visible"
                            },
                            k = (Ar.x) ? (Ar.x - Ag.x) / n : Ag.x / n,
                            w = k * 90,
                            i = w < 90;
                        switch (Ag.corner) {
                            case "l":
                                Ab = "0% 50%";
                                Ad = "100% 50%";
                                if (i) {
                                    Am = 0;
                                    Aa = Ao.opts.next - 1 > 0;
                                    z = 1
                                } else {
                                    Am = "100%";
                                    Aa = Ao.opts.page + 1 < Aq;
                                    z = 0
                                }
                                break;
                            case "r":
                                Ab = "100% 50%";
                                Ad = "0% 50%";
                                w = -w;
                                n = -n;
                                if (i) {
                                    Am = 0;
                                    Aa = Ao.opts.next + 1 < Aq;
                                    z = 0
                                } else {
                                    Am = "-100%";
                                    Aa = Ao.opts.page != 1;
                                    z = 1
                                }
                                break
                        }
                        Aj[E + "perspective-origin"] = Ad;
                        Ao.wrapper.transform("rotateY(" + w + "deg)translate3d(0px, 0px, " + (this.attr("depth") || 0) + "px)", Ad);
                        Ao.fpage.transform("translateX(" + n + "px) rotateY(" + (180 + w) + "deg)", Ab);
                        Ao.parent.css(Aj);
                        if (i) {
                            k = -k + 1;
                            Ao.wrapper.css({
                                zIndex: At + 1
                            });
                            Ao.fpage.css({
                                zIndex: At
                            })
                        } else {
                            k = k - 1;
                            Ao.wrapper.css({
                                zIndex: At
                            });
                            Ao.fpage.css({
                                zIndex: At + 1
                            })
                        }
                        if (Ac.opts.gradients) {
                            if (Aa) {
                                Ao.ashadow.css({
                                    display: "",
                                    left: Am,
                                    backgroundColor: "rgba(0,0,0," + (0.5 * k) + ")"
                                }).transform("rotateY(0deg)")
                            } else {
                                Ao.ashadow.hide()
                            }
                            Ao.bshadow.css({
                                opacity: -k + 1
                            });
                            if (i) {
                                if (Ao.bshadow.parent()[0] != Ao.wrapper[0]) {
                                    Ao.bshadow.appendTo(Ao.wrapper)
                                }
                            } else {
                                if (Ao.bshadow.parent()[0] != Ao.fpage[0]) {
                                    Ao.bshadow.appendTo(Ao.fpage)
                                }
                            }
                            U(Ao.bshadow, L(z * 100, 0), L((-z + 1) * 100, 0), [
                                [0, "rgba(0,0,0,0.3)"],
                                [1, "rgba(0,0,0,0)"]
                            ], 2)
                        }
                        break;
                    case "sheet":
                        var p = this,
                            Au = 0,
                            Af = 0,
                            l, Ae, As, q, x, Al, y, u, v = L(0, 0),
                            j = L(0, 0),
                            m = L(0, 0),
                            Ah = b._foldingPage.call(this),
                            Ai = Math.tan(Af),
                            An = Ac.opts.acceleration,
                            Ap = Ao.wrapper.height(),
                            t = Ag.corner.substr(0, 1) == "t",
                            Ak = Ag.corner.substr(1, 1) == "l",
                            Av = function() {
                                var AG = L(0, 0);
                                var AF = L(0, 0);
                                AG.x = (Ar.x) ? Ar.x - Ag.x : Ag.x;
                                if (!Z) {
                                    AG.y = 0
                                } else {
                                    AG.y = (Ar.y) ? Ar.y - Ag.y : Ag.y
                                }
                                AF.x = (Ak) ? n - AG.x / 2 : Ag.x + AG.x / 2;
                                AF.y = AG.y / 2;
                                var AA = J - Math.atan2(AG.y, AG.x),
                                    AC = AA - Math.atan2(AF.y, AF.x),
                                    AB = Math.max(0, Math.sin(AC) * Math.sqrt(Math.pow(AF.x, 2) + Math.pow(AF.y, 2)));
                                Au = c(AA);
                                m = L(AB * Math.sin(AA), AB * Math.cos(AA));
                                if (AA > J) {
                                    m.x = m.x + Math.abs(m.y * AG.y / AG.x);
                                    m.y = 0;
                                    if (Math.round(m.x * Math.tan(Q - AA)) < s) {
                                        Ag.y = Math.sqrt(Math.pow(s, 2) + 2 * AF.x * AG.x);
                                        if (t) {
                                            Ag.y = s - Ag.y
                                        }
                                        return Av()
                                    }
                                }
                                if (AA > J) {
                                    var Ay = Q - AA,
                                        Aw = Ap - s / Math.sin(Ay);
                                    v = L(Math.round(Aw * Math.cos(Ay)), Math.round(Aw * Math.sin(Ay)));
                                    if (Ak) {
                                        v.x = -v.x
                                    }
                                    if (t) {
                                        v.y = -v.y
                                    }
                                }
                                Ae = Math.round(m.y / Math.tan(AA) + m.x);
                                var Ax = n - Ae,
                                    AD = Ax * Math.cos(AA * 2),
                                    o = Ax * Math.sin(AA * 2);
                                j = L(Math.round((Ak ? Ax - AD : Ae + AD)), Math.round((t) ? o : s - o));
                                if (Ac.opts.gradients) {
                                    Al = Ax * Math.sin(AA);
                                    var AE = b._c2.call(p, Ag.corner),
                                        Az = Math.sqrt(Math.pow(AE.x - Ag.x, 2) + Math.pow(AE.y - Ag.y, 2)) / n;
                                    u = Math.sin(J * ((Az > 1) ? 2 - Az : Az));
                                    y = Math.min(Az, 1);
                                    x = Al > 100 ? (Al - 100) / Al : 0;
                                    As = L(Al * Math.sin(AA) / n * 100, Al * Math.cos(AA) / s * 100);
                                    if (b._backGradient.call(p)) {
                                        q = L(Al * 1.2 * Math.sin(AA) / n * 100, Al * 1.2 * Math.cos(AA) / s * 100);
                                        if (!Ak) {
                                            q.x = 100 - q.x
                                        }
                                        if (!t) {
                                            q.y = 100 - q.y
                                        }
                                    }
                                }
                                m.x = Math.round(m.x);
                                m.y = Math.round(m.y);
                                return true
                            },
                            r = function(Ay, AC, o, AD) {
                                var AE = ["0", "auto"],
                                    AF = (n - Ap) * o[0] / 100,
                                    Ax = (s - Ap) * o[1] / 100,
                                    Aw = {
                                        left: AE[AC[0]],
                                        top: AE[AC[1]],
                                        right: AE[AC[2]],
                                        bottom: AE[AC[3]]
                                    },
                                    AB = {},
                                    AA = (AD != 90 && AD != -90) ? (Ak ? -1 : 1) : 0,
                                    Az = o[0] + "% " + o[1] + "%";
                                p.css(Aw).transform(P(AD) + X(Ay.x + AA, Ay.y, An), Az);
                                Ao.fpage.css(Aw).transform(P(AD) + X(Ay.x + j.x - v.x - n * o[0] / 100, Ay.y + j.y - v.y - s * o[1] / 100, An) + P((180 / AD - 2) * AD), Az);
                                Ao.wrapper.transform(X(-Ay.x + AF - AA, -Ay.y + Ax, An) + P(-AD), Az);
                                Ao.fwrapper.transform(X(-Ay.x + v.x + AF, -Ay.y + v.y + Ax, An) + P(-AD), Az);
                                if (Ac.opts.gradients) {
                                    if (o[0]) {
                                        As.x = 100 - As.x
                                    }
                                    if (o[1]) {
                                        As.y = (100 - As.y)
                                    }
                                    AB["box-shadow"] = "0 0 20px rgba(0,0,0," + (0.5 * u) + ")";
                                    Ah.css(AB);
                                    U(Ao.ashadow, L(Ak ? 100 : 0, t ? 0 : 100), L(As.x, As.y), [
                                        [x, "rgba(0,0,0,0)"],
                                        [((1 - x) * 0.8) + x, "rgba(0,0,0," + (0.2 * y) + ")"],
                                        [1, "rgba(255,255,255," + (0.2 * y) + ")"]
                                    ], 3, Af);
                                    if (b._backGradient.call(p)) {
                                        U(Ao.bshadow, L(Ak ? 0 : 100, t ? 0 : 100), L(q.x, q.y), [
                                            [0.6, "rgba(0,0,0,0)"],
                                            [0.8, "rgba(0,0,0," + (0.3 * y) + ")"],
                                            [1, "rgba(0,0,0,0)"]
                                        ], 3)
                                    }
                                }
                            };
                        switch (Ag.corner) {
                            case "l":
                                break;
                            case "r":
                                break;
                            case "tl":
                                Ag.x = Math.max(Ag.x, 1);
                                Av();
                                r(m, [1, 0, 0, 1], [100, 0], Au);
                                break;
                            case "tr":
                                Ag.x = Math.min(Ag.x, n - 1);
                                Av();
                                r(L(-m.x, m.y), [0, 0, 0, 1], [0, 0], -Au);
                                break;
                            case "bl":
                                Ag.x = Math.max(Ag.x, 1);
                                Av();
                                r(L(m.x, -m.y), [1, 1, 0, 0], [100, 100], -Au);
                                break;
                            case "br":
                                Ag.x = Math.min(Ag.x, n - 1);
                                Av();
                                r(L(-m.x, -m.y), [0, 1, 1, 0], [0, 100], Au);
                                break
                        }
                        break
                }
                Ao.point = Ag
            },
            _moveFoldingPage: function(o) {
                var j = this.data().f;
                if (!j) {
                    return
                }
                var i = j.opts.turn,
                    m = i.data(),
                    k = m.pagePlace;
                if (o) {
                    var n = j.opts.next;
                    if (k[n] != j.opts.page) {
                        if (j.folding) {
                            b._moveFoldingPage.call(this, false)
                        }
                        var p = b._foldingPage.call(this);
                        p.appendTo(j.fpage);
                        k[n] = j.opts.page;
                        j.folding = n
                    }
                    i.turn("update")
                } else {
                    if (j.folding) {
                        if (m.pages[j.folding]) {
                            var l = m.pages[j.folding].data().f;
                            m.pageObjs[j.folding].appendTo(l.wrapper)
                        } else {
                            if (m.pageWrap[j.folding]) {
                                m.pageObjs[j.folding].appendTo(m.pageWrap[j.folding])
                            }
                        }
                        if (j.folding in k) {
                            k[j.folding] = j.folding
                        }
                        delete j.folding
                    }
                }
            },
            _showFoldedPage: function(o, l) {
                var q = b._foldingPage.call(this),
                    i = this.data(),
                    k = i.f,
                    m = k.visible;
                if (q) {
                    if (!m || !k.point || k.point.corner != o.corner) {
                        var j = (k.status == "hover" || k.status == "peel" || k.opts.turn.data().mouseAction) ? o.corner : null;
                        m = false;
                        if (a("start", this, [k.opts, j]) == "prevented") {
                            return false
                        }
                    }
                    if (l) {
                        var n = this,
                            p = (k.point && k.point.corner == o.corner) ? k.point : b._c.call(this, o.corner, 1);
                        this.animatef({
                            from: [p.x, p.y],
                            to: [o.x, o.y],
                            duration: 500,
                            frame: function(r) {
                                o.x = Math.round(r[0]);
                                o.y = Math.round(r[1]);
                                b._fold.call(n, o)
                            }
                        })
                    } else {
                        b._fold.call(this, o);
                        if (i.effect && !i.effect.turning) {
                            this.animatef(false)
                        }
                    }
                    if (!m) {
                        switch (k.effect) {
                            case "hard":
                                k.visible = true;
                                b._moveFoldingPage.call(this, true);
                                k.fpage.show();
                                if (k.opts.shadows) {
                                    k.bshadow.show()
                                }
                                break;
                            case "sheet":
                                k.visible = true;
                                k.fparent.show().data().flips++;
                                b._moveFoldingPage.call(this, true);
                                k.fwrapper.show();
                                if (k.bshadow) {
                                    k.bshadow.show()
                                }
                                break
                        }
                    }
                    return true
                }
                return false
            },
            hide: function() {
                var k = this.data().f,
                    i = k.opts.turn.data(),
                    j = b._foldingPage.call(this);
                switch (k.effect) {
                    case "hard":
                        if (i.opts.gradients) {
                            k.bshadowLoc = 0;
                            k.bshadow.remove();
                            k.ashadow.hide()
                        }
                        k.wrapper.transform("");
                        k.fpage.hide();
                        break;
                    case "sheet":
                        if ((--k.fparent.data().flips) === 0) {
                            k.fparent.hide()
                        }
                        this.css({
                            left: 0,
                            top: 0,
                            right: "auto",
                            bottom: "auto"
                        }).transform("");
                        k.wrapper.transform("");
                        k.fwrapper.hide();
                        if (k.bshadow) {
                            k.bshadow.hide()
                        }
                        j.transform("");
                        break
                }
                k.visible = false;
                return this
            },
            hideFoldedPage: function(k) {
                var j = this.data().f;
                if (!j.point) {
                    return
                }
                var n = this,
                    i = j.point,
                    m = function() {
                        j.point = null;
                        j.status = "";
                        n.flip("hide");
                        n.trigger("end", [j.opts, false])
                    };
                if (k) {
                    var r = b._c.call(this, i.corner),
                        l = (i.corner.substr(0, 1) == "t"),
                        p = (l) ? Math.min(0, i.y - r.y) / 2 : Math.max(0, i.y - r.y) / 2,
                        o = L(i.x, i.y + p),
                        q = L(r.x, r.y - p);
                    this.animatef({
                        from: 0,
                        to: 1,
                        frame: function(t) {
                            var s = h(i, o, q, r, t);
                            i.x = s.x;
                            i.y = s.y;
                            b._fold.call(n, i)
                        },
                        complete: m,
                        duration: 800,
                        hiding: true
                    })
                } else {
                    this.animatef(false);
                    m()
                }
            },
            turnPage: function(m) {
                var k = this,
                    n = this.data().f,
                    j = n.opts.turn.data();
                m = {
                    corner: (n.corner) ? n.corner.corner : m || b._cAllowed.call(this)[0]
                };
                var l = n.point || b._c.call(this, m.corner, (n.opts.turn) ? j.opts.elevation : 0),
                    i = b._c2.call(this, m.corner);
                this.trigger("flip").animatef({
                    from: 0,
                    to: 1,
                    frame: function(p) {
                        var o = h(l, l, i, i, p);
                        m.x = o.x;
                        m.y = o.y;
                        b._showFoldedPage.call(k, m)
                    },
                    complete: function() {
                        k.trigger("end", [n.opts, true])
                    },
                    duration: j.opts.duration,
                    turning: true
                });
                n.corner = null
            },
            moving: function() {
                return "effect" in this.data()
            },
            isTurning: function() {
                return this.flip("moving") && this.data().effect.turning
            },
            corner: function() {
                return this.data().f.corner
            },
            _eventStart: function(i) {
                var k = this.data().f,
                    j = k.opts.turn;
                if (!k.corner && !k.disabled && !this.flip("isTurning") && k.opts.page == j.data().pagePlace[k.opts.page]) {
                    k.corner = b._isIArea.call(this, i);
                    if (k.corner && b._foldingPage.call(this)) {
                        this.trigger("pressed", [k.point]);
                        b._showFoldedPage.call(this, k.corner);
                        return false
                    } else {
                        k.corner = null
                    }
                }
            },
            _eventMove: function(i) {
                var m = this.data().f;
                if (!m.disabled) {
                    i = (B) ? i.originalEvent.touches : [i];
                    if (m.corner) {
                        var k = m.parent.offset();
                        m.corner.x = i[0].pageX - k.left;
                        m.corner.y = i[0].pageY - k.top;
                        b._showFoldedPage.call(this, m.corner)
                    } else {
                        if (m.hover && !this.data().effect && this.is(":visible")) {
                            var j = b._isIArea.call(this, i[0]);
                            if (j) {
                                if ((m.effect == "sheet" && j.corner.length == 2) || m.effect == "hard") {
                                    m.status = "hover";
                                    var l = b._c.call(this, j.corner, m.opts.cornerSize / 2);
                                    j.x = l.x;
                                    j.y = l.y;
                                    b._showFoldedPage.call(this, j, true)
                                }
                            } else {
                                if (m.status == "hover") {
                                    m.status = "";
                                    b.hideFoldedPage.call(this, true)
                                }
                            }
                        }
                    }
                }
            },
            _eventEnd: function() {
                var j = this.data().f,
                    i = j.corner;
                if (!j.disabled && i) {
                    if (a("released", this, [j.point || i]) != "prevented") {
                        b.hideFoldedPage.call(this, true)
                    }
                }
                j.corner = null
            },
            disable: function(i) {
                b.setData.call(this, {
                    "disabled": i
                });
                return this
            },
            hover: function(i) {
                b.setData.call(this, {
                    "hover": i
                });
                return this
            },
            peel: function(k, j) {
                var l = this.data().f;
                if (k) {
                    if (S.inArray(k, T.all) == -1) {
                        throw F("Corner " + k + " is not permitted")
                    }
                    if (S.inArray(k, b._cAllowed.call(this)) != -1) {
                        var i = b._c.call(this, k, l.opts.cornerSize / 2);
                        l.status = "peel";
                        b._showFoldedPage.call(this, {
                            corner: k,
                            x: i.x,
                            y: i.y
                        }, j)
                    }
                } else {
                    l.status = "";
                    b.hideFoldedPage.call(this, j)
                }
                return this
            }
        };

    function e(i, j, k) {
        if (!k[0] || typeof(k[0]) == "object") {
            return j.init.apply(i, k)
        } else {
            if (j[k[0]]) {
                return j[k[0]].apply(i, Array.prototype.slice.call(k, 1))
            } else {
                throw F(k[0] + " is not a method or property")
            }
        }
    }

    function f(j, i, l, k) {
        return {
            "css": {
                position: "absolute",
                top: j,
                left: i,
                "overflow": k || "hidden",
                zIndex: l || "auto"
            }
        }
    }

    function h(i, m, l, k, j) {
        var p = 1 - j,
            n = p * p * p,
            o = j * j * j;
        return L(Math.round(n * i.x + 3 * j * p * p * m.x + 3 * j * j * p * l.x + o * k.x), Math.round(n * i.y + 3 * j * p * p * m.y + 3 * j * j * p * l.y + o * k.y))
    }

    function I(i) {
        return i / 180 * Q
    }

    function c(i) {
        return i / Q * 180
    }

    function L(i, j) {
        return {
            x: i,
            y: j
        }
    }

    function H() {
        var i;
        if ((i = /AppleWebkit\/([0-9\.]+)/i.exec(navigator.userAgent))) {
            var j = parseFloat(i[1]);
            return (j > 534.3)
        } else {
            return true
        }
    }

    function X(j, k, i) {
        return (V && i) ? " translate3d(" + j + "px," + k + "px, 0px) " : " translate(" + j + "px, " + k + "px) "
    }

    function P(i) {
        return " rotate(" + i + "deg) "
    }

    function N(j, i) {
        return Object.prototype.hasOwnProperty.call(i, j)
    }

    function O() {
        var i = ["Moz", "Webkit", "Khtml", "O", "ms"],
            j = i.length,
            k = "";
        while (j--) {
            if ((i[j] + "Transform") in document.body.style) {
                k = "-" + i[j].toLowerCase() + "-"
            }
        }
        return k
    }

    function W() {
        var k, i = document.createElement("fakeelement"),
            j = {
                "transition": "transitionend",
                "OTransition": "oTransitionEnd",
                "MSTransition": "transitionend",
                "MozTransition": "transitionend",
                "WebkitTransition": "webkitTransitionEnd"
            };
        for (k in j) {
            if (i.style[k] !== undefined) {
                return j[k]
            }
        }
    }

    function U(l, q, Ab, t, k) {
        var v, y = [];
        if (E == "-webkit-") {
            for (v = 0; v < k; v++) {
                y.push("color-stop(" + t[v][0] + ", " + t[v][1] + ")")
            }
            l.css({
                "background-image": "-webkit-gradient(linear, " + q.x + "% " + q.y + "%," + Ab.x + "% " + Ab.y + "%, " + y.join(",") + " )"
            })
        } else {
            q = {
                x: q.x / 100 * l.width(),
                y: q.y / 100 * l.height()
            };
            Ab = {
                x: Ab.x / 100 * l.width(),
                y: Ab.y / 100 * l.height()
            };
            var p = Ab.x - q.x,
                u = Ab.y - q.y,
                n = Math.atan2(u, p),
                r = n - Math.PI / 2,
                w = Math.abs(l.width() * Math.sin(r)) + Math.abs(l.height() * Math.cos(r)),
                m = Math.sqrt(u * u + p * p),
                Ac = L((Ab.x < q.x) ? l.width() : 0, (Ab.y < q.y) ? l.height() : 0),
                s = Math.tan(n),
                i = -1 / s,
                z = (i * Ac.x - Ac.y - s * q.x + q.y) / (i - s),
                o = {
                    x: z,
                    y: i * z - i * Ac.x + Ac.y
                },
                Aa = (Math.sqrt(Math.pow(o.x - q.x, 2) + Math.pow(o.y - q.y, 2)));
            for (v = 0; v < k; v++) {
                y.push(" " + t[v][1] + " " + ((Aa + m * t[v][0]) * 100 / w) + "%")
            }
            l.css({
                "background-image": E + "linear-gradient(" + (-n) + "rad," + y.join(",") + ")"
            })
        }
    }

    function a(j, i, l) {
        var k = S.Event(j);
        i.trigger(k, l);
        if (k.isDefaultPrevented()) {
            return "prevented"
        } else {
            if (k.isPropagationStopped()) {
                return "stopped"
            } else {
                return ""
            }
        }
    }

    function F(j) {
        function i(k) {
            this.name = "TurnJsError";
            this.message = k
        }
        i.prototype = new Error();
        i.prototype.constructor = i;
        return new i(j)
    }

    function K(j) {
        var i = {
            top: 0,
            left: 0
        };
        do {
            i.left += j.offsetLeft;
            i.top += j.offsetTop
        } while ((j = j.offsetParent));
        return i
    }

    function C() {
        return (navigator.userAgent.indexOf("MSIE 9.0") == -1)
    }
    window.requestAnim = (function() {
        return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame || function(i) {
            window.setTimeout(i, 1000 / 60)
        }
    })();
    S.extend(S.fn, {
        flip: function() {
            return e(S(this[0]), b, arguments)
        },
        turn: function() {
            return e(S(this[0]), D, arguments)
        },
        transform: function(k, j) {
            var i = {};
            if (j) {
                i[E + "transform-origin"] = j
            }
            i[E + "transform"] = k;
            return this.css(i)
        },
        animatef: function(r) {
            var k = this.data();
            if (k.effect) {
                k.effect.stop()
            }
            if (r) {
                if (!r.to.length) {
                    r.to = [r.to]
                }
                if (!r.from.length) {
                    r.from = [r.from]
                }
                var m = [],
                    q = r.to.length,
                    n = true,
                    p = this,
                    j = (new Date()).getTime(),
                    l = function() {
                        if (!k.effect || !n) {
                            return
                        }
                        var t = [],
                            u = Math.min(r.duration, (new Date()).getTime() - j);
                        for (var s = 0; s < q; s++) {
                            t.push(k.effect.easing(1, u, r.from[s], m[s], r.duration))
                        }
                        r.frame((q == 1) ? t[0] : t);
                        if (u == r.duration) {
                            delete k["effect"];
                            p.data(k);
                            if (r.complete) {
                                r.complete()
                            }
                        } else {
                            window.requestAnim(l)
                        }
                    };
                for (var o = 0; o < q; o++) {
                    m.push(r.to[o] - r.from[o])
                }
                k.effect = S.extend({
                    stop: function() {
                        n = false
                    },
                    easing: function(i, s, u, v, w) {
                        return v * Math.sqrt(1 - (s = s / w - 1) * s) + u
                    }
                }, r);
                this.data(k);
                l()
            } else {
                delete k["effect"]
            }
        }
    });
    S.isTouch = B;
    S.mouseEvents = A;
    S.cssPrefix = O;
    S.cssTransitionEnd = W;
    S.findPos = K
})(jQuery);
