(function(a) {
    var j, s, q, k, D, W, i, n, Z, d = 0,
        h = {},
        H = [],
        E = 0,
        f = {},
        Y = [],
        F = null,
        M = new Image(),
        G = /\.(jpg|gif|png|bmp|jpeg)(.*)?$/i,
        K = /[^\.]\.(swf)\s*$/i,
        Q, l = 1,
        A, C, o = false,
        c = 20,
        T = a.extend(a("<div/>")[0], {
            prop: 0
        }),
        J = 0,
        r = !a.support.opacity && !window.XMLHttpRequest,
        I = function() {
            s.hide();
            M.onerror = M.onload = null;
            if (F) {
                F.abort()
            }
            j.empty()
        },
        P = function() {
            a.fancybox('<p id="fancybox_error">The requested content cannot be loaded.<br />Please try again later.</p>', {
                scrolling: "no",
                padding: 20,
                transitionIn: "none",
                transitionOut: "none"
            })
        },
        e = function() {
            return [a(window).width(), a(window).height(), a(document).scrollLeft(), a(document).scrollTop()]
        },
        B = function() {
            var v = e(),
                AC = {},
                AA = f.margin,
                w = f.autoScale,
                AB = (c + AA) * 2,
                z = (c + AA) * 2,
                x = (f.padding * 2),
                y;
            if (f.width.toString().indexOf("%") > -1) {
                AC.width = ((v[0] * parseFloat(f.width)) / 100) - (c * 2);
                w = false
            } else {
                AC.width = f.width + x
            }
            if (f.height.toString().indexOf("%") > -1) {
                AC.height = ((v[1] * parseFloat(f.height)) / 100) - (c * 2);
                w = false
            } else {
                AC.height = f.height + x
            }
            if (w && (AC.width > (v[0] - AB) || AC.height > (v[1] - z))) {
                if (h.type == "image" || h.type == "swf") {
                    AB += x;
                    z += x;
                    y = Math.min(Math.min(v[0] - AB, f.width) / f.width, Math.min(v[1] - z, f.height) / f.height);
                    AC.width = Math.round(y * (AC.width - x)) + x;
                    AC.height = Math.round(y * (AC.height - x)) + x
                } else {
                    AC.width = Math.min(AC.width, (v[0] - AB));
                    AC.height = Math.min(AC.height, (v[1] - z))
                }
            }
            AC.top = v[3] + ((v[1] - (AC.height + (c * 2))) * 0.5);
            AC.left = v[2] + ((v[0] - (AC.width + (c * 2))) * 0.5);
            if (f.autoScale === false) {
                AC.top = Math.max(v[3] + AA, AC.top);
                AC.left = Math.max(v[2] + AA, AC.left)
            }
            if (a(".ros").length > 0) {
                AC.top = AC.top - a("#headerWrapper").height()
            }
            return AC
        },
        m = function(v) {
            if (v && v.length) {
                switch (f.titlePosition) {
                    case "inside":
                        return v;
                    case "over":
                        return '<span id="fancybox-title-over">' + v + "</span>";
                    default:
                        return '<span id="fancybox-title-wrap"><span id="fancybox-title-left"></span><span id="fancybox-title-main">' + v + '</span><span id="fancybox-title-right"></span></span>'
                }
            }
            return false
        },
        S = function() {
            var x = f.title,
                w = C.width - (f.padding * 2),
                v = "fancybox-title-" + f.titlePosition;
            a("#fancybox-title").remove();
            J = 0;
            if (f.titleShow === false) {
                return
            }
            x = a.isFunction(f.titleFormat) ? f.titleFormat(x, Y, E, f) : m(x);
            if (!x || x === "") {
                return
            }
            a('<div id="fancybox-title" class="' + v + '" />').css({
                width: w,
                paddingLeft: f.padding,
                paddingRight: f.padding
            }).html(x).appendTo(".formPageWrapper");
            switch (f.titlePosition) {
                case "inside":
                    J = a("#fancybox-title").outerHeight(true) - f.padding;
                    C.height += J;
                    break;
                case "over":
                    a("#fancybox-title").css("bottom", f.padding);
                    break;
                default:
                    a("#fancybox-title").css("bottom", a("#fancybox-title").outerHeight(true) * -1);
                    break
            }
            a("#fancybox-title").appendTo(D).hide()
        },
        O = function() {
            a(document).unbind("keydown.fb").bind("keydown.fb", function(v) {
                if (v.keyCode == 27 && f.enableEscapeButton) {
                    v.preventDefault();
                    a.fancybox.close()
                } else {
                    if (v.keyCode == 37) {
                        v.preventDefault();
                        a.fancybox.prev()
                    } else {
                        if (v.keyCode == 39) {
                            v.preventDefault();
                            a.fancybox.next()
                        }
                    }
                }
            });
            if (a.fn.mousewheel) {
                k.unbind("mousewheel.fb");
                if (Y.length > 1) {
                    k.bind("mousewheel.fb", function(v, w) {
                        v.preventDefault();
                        if (o || w === 0) {
                            return
                        }
                        if (w > 0) {
                            a.fancybox.prev()
                        } else {
                            a.fancybox.next()
                        }
                    })
                }
            }
            if (!f.showNavArrows) {
                return
            }
            if ((f.cyclic && Y.length > 1) || E !== 0) {
                n.show()
            }
            if ((f.cyclic && Y.length > 1) || E != (Y.length - 1)) {
                Z.show()
            }
        },
        t = function() {
            var v, w;
            if ((Y.length - 1) > E) {
                v = Y[E + 1].href;
                if (typeof v !== "undefined" && v.match(G)) {
                    w = new Image();
                    w.src = v
                }
            }
            if (E > 0) {
                v = Y[E - 1].href;
                if (typeof v !== "undefined" && v.match(G)) {
                    w = new Image();
                    w.src = v
                }
            }
        },
        V = function() {
            W.css("overflow", (f.scrolling == "auto" ? (f.type == "image" || f.type == "iframe" || f.type == "swf" ? "hidden" : "auto") : (f.scrolling == "yes" ? "auto" : "visible")));
            if (!a.support.opacity) {
                W.get(0).style.removeAttribute("filter");
                k.get(0).style.removeAttribute("filter")
            }
            a("#fancybox-title").show();
            if (f.hideOnContentClick) {
                W.one("click", a.fancybox.close)
            }
            if (f.hideOnOverlayClick) {
                q.one("click", a.fancybox.close)
            }
            if (f.showCloseButton) {
                i.show()
            }
            O();
            a(window).bind("resize.fb", a.fancybox.center);
            if (f.centerOnScroll) {
                a(window).bind("scroll.fb", a.fancybox.center)
            } else {
                a(window).unbind("scroll.fb")
            }
            if (a.isFunction(f.onComplete)) {
                f.onComplete(Y, E, f)
            }
            o = false;
            t()
        },
        g = function(z) {
            var w = Math.round(A.width + (C.width - A.width) * z),
                v = Math.round(A.height + (C.height - A.height) * z),
                y = Math.round(A.top + (C.top - A.top) * z),
                x = Math.round(A.left + (C.left - A.left) * z);
            k.css({
                width: w + "px",
                height: v + "px",
                top: y + "px",
                left: x + "px"
            });
            w = Math.max(w - f.padding * 2, 0);
            v = Math.max(v - (f.padding * 2 + (J * z)), 0);
            W.css({
                width: w + "px",
                height: v + "px"
            });
            if (typeof C.opacity !== "undefined") {
                k.css("opacity", (z < 0.5 ? 0.5 : z))
            }
        },
        X = function(v) {
            var w = v.offset();
            w.top += parseFloat(v.css("paddingTop")) || 0;
            w.left += parseFloat(v.css("paddingLeft")) || 0;
            w.top += parseFloat(v.css("border-top-width")) || 0;
            w.left += parseFloat(v.css("border-left-width")) || 0;
            w.width = v.width();
            w.height = v.height();
            return w
        },
        u = function() {
            var y = h.orig ? a(h.orig) : false,
                x = {},
                w, v;
            if (y && y.length) {
                w = X(y);
                x = {
                    width: (w.width + (f.padding * 2)),
                    height: (w.height + (f.padding * 2)),
                    top: (w.top - f.padding - c),
                    left: (w.left - f.padding - c)
                }
            } else {
                v = e();
                x = {
                    width: 1,
                    height: 1,
                    top: v[3] + v[1] * 0.5,
                    left: v[2] + v[0] * 0.5
                }
            }
            return x
        },
        U = function() {
            s.hide();
            a(".formPageWrapper").css("z-index", "1000");
            if (k.is(":visible") && a.isFunction(f.onCleanup)) {
                if (f.onCleanup(Y, E, f) === false) {
                    a.event.trigger("fancybox-cancel");
                    o = false;
                    return
                }
            }
            Y = H;
            E = d;
            f = h;
            W.get(0).scrollTop = 0;
            W.get(0).scrollLeft = 0;
            if (f.overlayShow) {
                if (r) {
                    a("select:not(#fancybox-tmp select)").filter(function() {
                        return this.style.visibility !== "hidden"
                    }).css({
                        visibility: "hidden"
                    }).one("fancybox-cleanup", function() {
                        this.style.visibility = "inherit"
                    })
                }
                q.css({
                    "background-color": f.overlayColor,
                    opacity: f.overlayOpacity
                }).unbind().show()
            }
            C = B();
            S();
            if (k.is(":visible")) {
                a(i.add(n).add(Z)).hide();
                var w = k.position(),
                    v;
                A = {
                    top: w.top,
                    left: w.left,
                    width: k.width(),
                    height: k.height()
                };
                v = (A.width == C.width && A.height == C.height);
                W.fadeOut(f.changeFade, function() {
                    var x = function() {
                        W.html(j.contents()).fadeIn(f.changeFade, V)
                    };
                    a.event.trigger("fancybox-change");
                    W.empty().css("overflow", "hidden");
                    if (v) {
                        W.css({
                            top: f.padding,
                            left: f.padding,
                            width: Math.max(C.width - (f.padding * 2), 1),
                            height: Math.max(C.height - (f.padding * 2) - J, 1)
                        });
                        x()
                    } else {
                        W.css({
                            top: f.padding,
                            left: f.padding,
                            width: Math.max(A.width - (f.padding * 2), 1),
                            height: Math.max(A.height - (f.padding * 2), 1)
                        });
                        T.prop = 0;
                        a(T).animate({
                            prop: 1
                        }, {
                            duration: f.changeSpeed,
                            easing: f.easingChange,
                            step: g,
                            complete: x
                        })
                    }
                });
                return
            }
            k.css("opacity", 1);
            if (f.transitionIn == "elastic") {
                A = u();
                W.css({
                    top: f.padding,
                    left: f.padding,
                    width: Math.max(A.width - (f.padding * 2), 1),
                    height: Math.max(A.height - (f.padding * 2), 1)
                }).html(j.contents());
                k.css(A).show();
                if (f.opacity) {
                    C.opacity = 0
                }
                T.prop = 0;
                a(T).animate({
                    prop: 1
                }, {
                    duration: f.speedIn,
                    easing: f.easingIn,
                    step: g,
                    complete: V
                })
            } else {
                W.css({
                    top: f.padding,
                    left: f.padding,
                    width: Math.max(C.width - (f.padding * 2), 1),
                    height: Math.max(C.height - (f.padding * 2) - J, 1)
                }).html(j.contents());
                k.css(C).fadeIn(f.transitionIn == "none" ? 0 : f.speedIn, V)
            }
        },
        R = function() {
            j.width(h.width);
            j.height(h.height);
            if (h.width == "auto") {
                h.width = j.width()
            }
            if (h.height == "auto") {
                h.height = j.height()
            }
            U()
        },
        p = function() {
            o = true;
            h.width = M.width;
            h.height = M.height;
            a("<img />").attr({
                id: "fancybox-img",
                src: M.src,
                alt: h.title
            }).appendTo(j);
            U()
        },
        L = function() {
            I();
            var AA = H[d],
                x, y, AC, AB, w, v, z;
            h = a.extend({}, a.fn.fancybox.defaults, (typeof a(AA).data("fancybox") == "undefined" ? h : a(AA).data("fancybox")));
            AC = AA.title || a(AA).title || h.title || "";
            if (AA.nodeName && !h.orig) {
                h.orig = a(AA).children("img:first").length ? a(AA).children("img:first") : a(AA)
            }
            if (AC === "" && h.orig) {
                AC = h.orig.attr("alt")
            }
            if (AA.nodeName && (/^(?:javascript|#)/i).test(AA.href)) {
                x = h.href || null
            } else {
                x = h.href || AA.href || null
            }
            if (h.type) {
                y = h.type;
                if (!x) {
                    x = h.content
                }
            } else {
                if (h.content) {
                    y = "html"
                } else {
                    if (x) {
                        if (x.match(G)) {
                            y = "image"
                        } else {
                            if (x.match(K)) {
                                y = "swf"
                            } else {
                                if (a(AA).hasClass("iframe")) {
                                    y = "iframe"
                                } else {
                                    if (x.match(/#/)) {
                                        AA = x.substr(x.indexOf("#"));
                                        y = a(AA).length > 0 ? "inline" : "ajax"
                                    } else {
                                        y = "ajax"
                                    }
                                }
                            }
                        }
                    } else {
                        y = "inline"
                    }
                }
            }
            h.type = y;
            h.href = x;
            h.title = AC;
            if (h.autoDimensions && h.type !== "iframe" && h.type !== "swf") {
                h.width = "auto";
                h.height = "auto"
            }
            if (h.modal) {
                h.overlayShow = true;
                h.hideOnOverlayClick = false;
                h.hideOnContentClick = false;
                h.enableEscapeButton = false;
                h.showCloseButton = false
            }
            if (a.isFunction(h.onStart)) {
                if (h.onStart(H, d, h) === false) {
                    o = false;
                    return
                }
            }
            j.css("padding", (c + h.padding + h.margin));
            a(".fancybox-inline-tmp").unbind("fancybox-cancel").bind("fancybox-change", function() {
                a(this).replaceWith(W.children())
            });
            switch (y) {
                case "html":
                    j.html(h.content);
                    R();
                    break;
                case "inline":
                    a('<div class="fancybox-inline-tmp" />').hide().insertBefore(a(AA)).bind("fancybox-cleanup", function() {
                        a(this).replaceWith(W.children())
                    }).bind("fancybox-cancel", function() {
                        a(this).replaceWith(j.children())
                    });
                    a(AA).appendTo(j);
                    R();
                    break;
                case "image":
                    o = false;
                    a.fancybox.showActivity();
                    M = new Image();
                    M.onerror = function() {
                        P()
                    };
                    M.onload = function() {
                        M.onerror = null;
                        M.onload = null;
                        p()
                    };
                    M.src = x;
                    break;
                case "swf":
                    AB = '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="' + h.width + '" height="' + h.height + '"><param name="movie" value="' + x + '"></param>';
                    w = "";
                    a.each(h.swf, function(AD, AE) {
                        AB += '<param name="' + AD + '" value="' + AE + '"></param>';
                        w += " " + AD + '="' + AE + '"'
                    });
                    AB += '<embed src="' + x + '" type="application/x-shockwave-flash" width="' + h.width + '" height="' + h.height + '"' + w + "></embed></object>";
                    j.html(AB);
                    R();
                    break;
                case "ajax":
                    v = x.split("#", 2);
                    z = h.ajax.data || {};
                    if (v.length > 1) {
                        x = v[0];
                        if (typeof z == "string") {
                            z += "&selector=" + v[1]
                        } else {
                            z.selector = v[1]
                        }
                    }
                    o = false;
                    a.fancybox.showActivity();
                    F = a.ajax(a.extend(h.ajax, {
                        url: x,
                        data: z,
                        error: P,
                        success: function(AE, AF, AD) {
                            if (F.status == 200) {
                                j.html(AE);
                                R()
                            }
                        }
                    }));
                    break;
                case "iframe":
                    a('<iframe id="fancybox-frame" name="fancybox-frame' + new Date().getTime() + '" frameborder="0" hspace="0" scrolling="' + h.scrolling + '" src="' + h.href + '"></iframe>').appendTo(j);
                    U();
                    break
            }
        },
        N = function() {
            if (!s.is(":visible")) {
                clearInterval(Q);
                return
            }
            a("div", s).css("top", (l * -40) + "px");
            l = (l + 1) % 12
        },
        b = function() {
            if (a("#fancybox-wrap").length) {
                return
            }
            a(".formPageWrapper").append(j = a('<div id="fancybox-tmp"></div>'), s = a('<div id="fancybox-loading"><div></div></div>'), q = a('<div id="fancybox-overlay"></div>'), k = a('<div id="fancybox-wrap"></div>'));
            if (!a.support.opacity) {
                k.addClass("fancybox-ie");
                s.addClass("fancybox-ie")
            }
            D = a('<div id="fancybox-outer"></div>').append('<div class="fancy-bg" id="fancy-bg-n"></div><div class="fancy-bg" id="fancy-bg-ne"></div><div class="fancy-bg" id="fancy-bg-e"></div><div class="fancy-bg" id="fancy-bg-se"></div><div class="fancy-bg" id="fancy-bg-s"></div><div class="fancy-bg" id="fancy-bg-sw"></div><div class="fancy-bg" id="fancy-bg-w"></div><div class="fancy-bg" id="fancy-bg-nw"></div>').appendTo(k);
            D.append(W = a('<div id="fancybox-inner"></div>'), i = a('<a id="fancybox-close"></a>'), n = a('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'), Z = a('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>'));
            i.click(a.fancybox.close);
            s.click(a.fancybox.cancel);
            n.click(function(v) {
                v.preventDefault();
                a.fancybox.prev()
            });
            Z.click(function(v) {
                v.preventDefault();
                a.fancybox.next()
            });
            if (r) {
                q.get(0).style.setExpression("height", "document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px'");
                s.get(0).style.setExpression("top", "(-20 + (document.documentElement.clientHeight ? document.documentElement.clientHeight/2 : document.body.clientHeight/2 ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop )) + 'px'");
                D.prepend('<iframe id="fancybox-hide-sel-frame" src="javascript:\'\';" scrolling="no" frameborder="0" ></iframe>')
            }
        };
    a.fn.fancybox = function(v) {
        a(this).data("fancybox", a.extend({}, v, (a.metadata ? a(this).metadata() : {}))).unbind("click.fb").bind("click.fb", function(x) {
            x.preventDefault();
            if (o) {
                return
            }
            o = true;
            a(this).blur();
            H = [];
            d = 0;
            var w = a(this).attr("rel") || "";
            if (!w || w == "" || w === "nofollow") {
                H.push(this)
            } else {
                H = a("a[rel=" + w + "], area[rel=" + w + "]");
                d = H.index(this)
            }
            L();
            return false
        });
        return this
    };
    a.fancybox = function(y) {
        if (o) {
            return
        }
        o = true;
        var x = typeof arguments[1] !== "undefined" ? arguments[1] : {};
        H = [];
        d = x.index || 0;
        if (a.isArray(y)) {
            for (var w = 0, v = y.length; w < v; w++) {
                if (typeof y[w] == "object") {
                    a(y[w]).data("fancybox", a.extend({}, x, y[w]))
                } else {
                    y[w] = a({}).data("fancybox", a.extend({
                        content: y[w]
                    }, x))
                }
            }
            H = jQuery.merge(H, y)
        } else {
            if (typeof y == "object") {
                a(y).data("fancybox", a.extend({}, x, y))
            } else {
                y = a({}).data("fancybox", a.extend({
                    content: y
                }, x))
            }
            H.push(y)
        }
        if (d > H.length || d < 0) {
            d = 0
        }
        L()
    };
    a.fancybox.showActivity = function() {
        clearInterval(Q);
        s.show();
        Q = setInterval(N, 66)
    };
    a.fancybox.hideActivity = function() {
        s.hide()
    };
    a.fancybox.next = function() {
        return a.fancybox.pos(E + 1)
    };
    a.fancybox.prev = function() {
        return a.fancybox.pos(E - 1)
    };
    a.fancybox.pos = function(v) {
        if (o) {
            return
        }
        v = parseInt(v, 10);
        if (v > -1 && Y.length > v) {
            d = v;
            L()
        }
        if (f.cyclic && Y.length > 1 && v < 0) {
            d = Y.length - 1;
            L()
        }
        if (f.cyclic && Y.length > 1 && v >= Y.length) {
            d = 0;
            L()
        }
        return
    };
    a.fancybox.cancel = function() {
        if (o) {
            return
        }
        o = true;
        a.event.trigger("fancybox-cancel");
        I();
        if (h && a.isFunction(h.onCancel)) {
            h.onCancel(H, d, h)
        }
        o = false
    };
    a.fancybox.close = function() {
        if (o || k.is(":hidden")) {
            return
        }
        o = true;
        if (f && a.isFunction(f.onCleanup)) {
            if (f.onCleanup(Y, E, f) === false) {
                o = false;
                return
            }
        }
        I();
        a(i.add(n).add(Z)).hide();
        a("#fancybox-title").remove();
        k.add(W).add(q).unbind();
        a(window).unbind("resize.fb scroll.fb");
        a(document).unbind("keydown.fb");

        function v() {
            q.fadeOut("fast");
            k.hide();
            a.event.trigger("fancybox-cleanup");
            W.empty();
            if (a.isFunction(f.onClosed)) {
                f.onClosed(Y, E, f)
            }
            Y = h = [];
            E = d = 0;
            f = h = {};
            o = false
        }
        W.css("overflow", "hidden");
        if (f.transitionOut == "elastic") {
            A = u();
            var w = k.position();
            C = {
                top: w.top,
                left: w.left,
                width: k.width(),
                height: k.height()
            };
            if (f.opacity) {
                C.opacity = 1
            }
            T.prop = 1;
            a(T).animate({
                prop: 0
            }, {
                duration: f.speedOut,
                easing: f.easingOut,
                step: g,
                complete: v
            })
        } else {
            k.fadeOut(f.transitionOut == "none" ? 0 : f.speedOut, v)
        }
        a(".formPageWrapper").css("z-index", "1")
    };
    a.fancybox.resize = function() {
        var w, v;
        if (o || k.is(":hidden")) {
            return
        }
        o = true;
        w = W.wrapInner("<div style='overflow:auto'></div>").children();
        v = w.height();
        k.css({
            height: v + (f.padding * 2) + J
        });
        W.css({
            height: v
        });
        w.replaceWith(w.children());
        a.fancybox.center()
    };
    a.fancybox.center = function() {
        o = true;
        var v = e(),
            w = f.margin,
            x = {};
        x.top = v[3] + ((v[1] - ((k.height() - J) + (c * 2))) * 0.5);
        x.left = v[2] + ((v[0] - (k.width() + (c * 2))) * 0.5);
        x.top = Math.max(v[3] + w, x.top);
        if (a(".ros").length > 0) {
            x.top = x.top - a("#headerWrapper").height()
        }
        x.left = Math.max(v[2] + w, x.left);
        k.css(x);
        o = false
    };
    a.fn.fancybox.defaults = {
        padding: 10,
        margin: 20,
        opacity: false,
        modal: false,
        cyclic: false,
        scrolling: "auto",
        width: 560,
        height: 340,
        autoScale: true,
        autoDimensions: true,
        centerOnScroll: false,
        ajax: {},
        swf: {
            wmode: "transparent"
        },
        hideOnOverlayClick: true,
        hideOnContentClick: false,
        overlayShow: true,
        overlayOpacity: 0.75,
        overlayColor: "#222",
        titleShow: true,
        titlePosition: "outside",
        titleFormat: null,
        transitionIn: "fade",
        transitionOut: "fade",
        speedIn: 300,
        speedOut: 300,
        changeSpeed: 300,
        changeFade: "fast",
        easingIn: "swing",
        easingOut: "swing",
        showCloseButton: true,
        showNavArrows: true,
        enableEscapeButton: true,
        onStart: null,
        onCancel: null,
        onComplete: null,
        onCleanup: null,
        onClosed: null
    };
    a(document).ready(function() {
        b()
    })
})(jQuery);
