﻿(function (a) { a.fn.bPopup = function (h, j) { function s() { b.css({ left: !o.follow[1] && k ? d : c.scrollLeft() + d, position: "absolute", top: !o.follow[0] && l ? e : c.scrollTop() + e, "z-index": o.zIndex }).appendTo(o.appendTo).hide(1, function () { a.isFunction(o.onOpen) && o.onOpen.call(b); if (o.loadUrl != null) switch (o.contentContainer = o.contentContainer == null ? b : a(o.contentContainer), o.content) { case "iframe": a('<iframe scrolling="no" frameborder="0"></iframe>').attr("src", o.loadUrl).appendTo(o.contentContainer); break; default: o.contentContainer.load(o.loadUrl) } }).fadeIn(o.fadeSpeed, function () { a.isFunction(j) && j() }); t() } function i() { o.modal && a("#bModal").fadeOut(o.fadeSpeed, function () { a("#bModal").remove() }); b.fadeOut(o.fadeSpeed, function () { o.loadUrl != null && o.contentContainer.empty() }); o.scrollBar || a("html").css("overflow", "auto"); a("." + o.closeClass).die("click"); a("#bModal").die("click"); c.unbind("keydown.bPopup"); f.unbind(".bPopup"); b.data("bPopup", null); a.isFunction(o.onClose) && setTimeout(function () { o.onClose.call(b) }, o.fadeSpeed); return !1 } function u() { if (n || v) { var a = [c.height(), c.width()]; return { "background-color": o.modalColor, height: a[0], left: m(), opacity: 0, position: "absolute", top: 0, width: a[1], "z-index": o.zIndex - 1} } else return { "background-color": o.modalColor, height: "100%", left: 0, opacity: 0, position: "fixed", top: 0, width: "100%", "z-index": o.zIndex - 1} } function t() { a("." + o.closeClass).live("click", i); o.modalClose && a("#bModal").live("click", i).css("cursor", "pointer"); (o.follow[0] || o.follow[1]) && f.bind("scroll.bPopup", function () { b.stop().animate({ left: o.follow[1] ? c.scrollLeft() + d : d, top: o.follow[0] ? c.scrollTop() + e : e }, o.followSpeed) }).bind("resize.bPopup", function () { if (o.modal && n) { var a = [c.height(), c.width()]; p.css({ height: a[0], width: a[1], left: m() }) } g = q(b, o.amsl); o.follow[0] && (e = l ? e : c.scrollTop() + g[0]); o.follow[1] && (d = k ? d : c.scrollLeft() + g[1]); b.stop().animate({ left: d, top: e }, o.followSpeed) }); o.escClose && c.bind("keydown.bPopup", function (a) { a.which == 27 && i() }) } function m() { return f.width() < a("body").width() ? 0 : (a("body").width() - f.width()) / 2 } function q(a, b) { var c = (f.height() - a.outerHeight(!0)) / 2 - b, d = (f.width() - a.outerWidth(!0)) / 2 + m(); return [c < 20 ? 20 : c, d] } a.isFunction(h) && (j = h, h = null); o = a.extend({}, a.fn.bPopup.defaults, h); o.scrollBar || a("html").css("overflow", "hidden"); var b = a(this), p = a('<div id="bModal"></div>'), c = a(document), f = a(window), g = q(b, o.amsl), l = o.position[0] != "auto", k = o.position[1] != "auto", e = l ? o.position[0] : g[0], d = k ? o.position[1] : g[1], r = navigator.userAgent.toLowerCase(), v = r.indexOf("iphone") != -1, n = /msie 6/i.test(r) && typeof window.XMLHttpRequest != "object"; this.close = function () { o = b.data("bPopup"); i() }; return this.each(function () { b.data("bPopup") || (o.modal && p.css(u()).appendTo(o.appendTo).animate({ opacity: o.opacity }, o.fadeSpeed), b.data("bPopup", o), s()) }) }; a.fn.bPopup.defaults = { amsl: 50, appendTo: "body", closeClass: "bClose", content: "ajax", contentContainer: null, escClose: !0, fadeSpeed: 250, follow: [!0, !0], followSpeed: 500, loadUrl: null, modal: !0, modalClose: !0, modalColor: "#000", onClose: null, onOpen: null, opacity: 0.7, position: ["auto", "auto"], scrollBar: !0, zIndex: 9999} })(jQuery);
