﻿if (typeof basePath == "undefined") {
    var basePath = "";
}
(function($) {
    $.fn.alertwindow = function(options) {
        var C = null, badObjects = ["select"], l = null, B = [], refTags = ["a", "area"], k = null, c = null, m = 50, I, showTimer;
        if (!document.getElementsByTagName) { return; }
        options = $.extend({
            zindex: 9999,
            size: [400, 60],
            title: '系统提示信息',
            mode: 'info',
            prefix: '',
            animate: true,
            borderSize: 51,
            overlayDuration: 0.2,
            overlayOpacity: 0.1,
            resizeSpeed: 7,
            okFun: null,
            cancelFun: null,
            iframesrc: '',
            content: {
                title: '信息标题',
                text: '在这里显示你的信息。。。',
                moretext: '在这里显示你的更多信息'
            },
            footer: {
                show: true,
                Info: '&copy; <a href="http://www.p5w.net" target="_blank">Panorama Network Co., Ltd</a>, All Rights Reserved.'
            },
            featBrowser: true,
            breathingSize: 20,
            fadeOut: true ,
            floating: true
        }, options);
        if (options.animate) {
            var overlayDuration = Math.max(options.overlayDuration, 0);
            options.resizeSpeed = Math.max(Math.min(options.resizeSpeed, 10), 1);
            var resizeDuration = (11 - options.resizeSpeed) * 0.15;
        } else {
            var overlayDuration = 0;
            var resizeDuration = 0;
        }

        var me = this;
        options.overlayOpacity = Math.max(Math.min(options.overlayOpacity, 1), 0);
        var isAlertWindow = (options.mode == "alert" || options.mode == "info" || options.mode == "error" || options.mode == "query");

        var n = document.createElement("div");
        n.setAttribute("id", getID("overlay"));
        n.style.display = "none";
        n.style.zIndex = options.zindex;
        document.body.appendChild(n);
        // $(n).click(end);
        var W = document.createElement("div");
        W.setAttribute("id", getID("alertwindow"));
        W.style.display = "none";
        W.style.zIndex = options.zindex + 1;
        document.body.appendChild(W);
        //$(W).click(end);
        if (isAlertWindow) {
            var U = document.createElement("div");
            U.setAttribute("id", getID("footerDataContainer"));
            // U.className = getID("clearfix");
            var p = document.createElement("div");
            p.setAttribute("id", getID("buttonsData"));
            U.appendChild(p);
            var g = document.createElement("div");
            g.setAttribute("id", getID("controlPanel"));
            p.appendChild(g);
            var BTN_SWITCH = document.createElement("input");
            BTN_SWITCH.setAttribute("id", getID("btn_switch"));
            BTN_SWITCH.setAttribute("type", "button");
            BTN_SWITCH.setAttribute("value", "");
            BTN_SWITCH.setAttribute("title", "显示/隐藏更多信息");
            BTN_SWITCH.className = "btn_switch";
            BTN_SWITCH.setAttribute("hidefocus", "true");

            g.appendChild(BTN_SWITCH);


            var g = document.createElement("div");
            g.setAttribute("id", getID("buttonsPanel"));
            p.appendChild(g);
            var BTN_CLOSE = document.createElement("input");
            BTN_CLOSE.setAttribute("id", getID("btn_Close"));
            BTN_CLOSE.setAttribute("type", "button");
            BTN_CLOSE.setAttribute("value", "关闭");
            BTN_CLOSE.className = "button";
            BTN_CLOSE.setAttribute("hidefocus", "true");
            g.appendChild(BTN_CLOSE);

            var BTN_OK = document.createElement("input");
            BTN_OK.setAttribute("id", getID("btn_OK"));
            BTN_OK.setAttribute("type", "button");
            BTN_OK.setAttribute("value", "确定");
            BTN_OK.className = "button";
            BTN_OK.setAttribute("hidefocus", "true");
            g.appendChild(BTN_OK);
            var BTN_CANCEL = document.createElement("input");
            BTN_CANCEL.setAttribute("id", getID("btn_Cancel"));
            BTN_CANCEL.setAttribute("type", "button");
            BTN_CANCEL.setAttribute("value", "取消");
            BTN_CANCEL.className = "button";
            BTN_CANCEL.setAttribute("hidefocus", "true");
            g.appendChild(BTN_CANCEL);

            var foot = document.createElement("div");
            foot.setAttribute("id", getID("footData"));
            //foot.className = getID("clearfix");
            U.appendChild(foot);
            var fl = document.createElement("div");
            fl.className = "line";
            fl.appendChild(document.createTextNode(' '));
            foot.appendChild(fl);
            var txt = document.createElement("span");
            $(txt).html(options.footer.Info);
            foot.appendChild(txt);
        }

        var P = document.createElement("table");
        P.setAttribute("id", getID("outerWindowContainer"));
        P.cellSpacing = 0;
        W.appendChild(P);
        var AG = P.insertRow(-1);
        var AY = AG.insertCell(-1);
        AY.className = "tl";
        var Ac = AG.insertCell(-1);
        Ac.className = "tc";
        var caP = document.createElement("div");
        caP.setAttribute("id", getID("captionPanel"));
        Ac.appendChild(caP);
        var AP = document.createElement("h2");
        AP.setAttribute("id", getID("caption"));
        AP.className = 'caption';
        caP.appendChild(AP);
        var AI = AG.insertCell(-1);
        AI.className = "tr";
        var AF = P.insertRow(-1);
        var Af = AF.insertCell(-1);
        Af.className = "ml";
        var b = AF.insertCell(-1);
        b.setAttribute("id", getID("windowFrameBody"));
        //b.innerHTML = "&nbsp;";
        var Ag = AF.insertCell(-1);
        Ag.className = "mr";
        var AD = P.insertRow(-1);
        var AZ = AD.insertCell(-1);
        AZ.className = "bl";
        var Ab = AD.insertCell(-1);
        Ab.className = "bc";
        var Ad = AD.insertCell(-1);
        Ad.className = "br";

        var h = document.createElement("div");
        h.setAttribute("id", getID("windowContainer"));
        b.appendChild(h);
        if (isAlertWindow) {
            b.appendChild(U);
        }
        var AJ = document.createElement("div");
        AJ.setAttribute("id", getID("windowContent"));
        h.appendChild(AJ);

        if (isAlertWindow) {
            var ctable = document.createElement("table");
            ctable.cellSpacing = 0;
            ctable.setAttribute("border", 0);
            ctable.setAttribute("width", "100%");
            AJ.appendChild(ctable);
            var row = ctable.insertRow(-1);
            var imgtd = row.insertCell(-1);
            imgtd.className = "icon";
            //imgtd.setAttribute("rowspan", 2);
            var img = document.createElement("img");
            img.className = 'pngfix';
            img.src = basePath + "css/images/alertwindow/vista/" + options.mode + ".png";
            imgtd.appendChild(img);
            var contenttd = row.insertCell(-1);
            var contentPanel = document.createElement("div");
            contenttd.appendChild(contentPanel);
            if (options.content.title != "") {
                var title = document.createElement("h2");
                contentPanel.appendChild(title);
                $(title).html(options.content.title);
            }
            var pc = document.createElement("p");
            contentPanel.appendChild(pc);
            if (options.content.text == "") {
                options.content.text = "&nbsp;";
            }
            $(pc).html(options.content.text);

            var row = ctable.insertRow(-1);
            var moretd = row.insertCell(-1);
            var moretd = row.insertCell(-1);
            var morePanel = document.createElement("div");
            morePanel.setAttribute("id", getID("morePanel"));
            moretd.appendChild(morePanel);

            if (options.content.moretext != "") {
                var mp = document.createElement("p");
                mp.setAttribute("id", getID("moreText"));
                morePanel.appendChild(mp);
                $(mp).hide().html(options.content.moretext);
            }
        } else {
            if (options.mode == "iframe") {
                $(AJ).html('<iframe id="' + getID("alertwindow_iframe") + '" src="blank.htm" frameborder="0" scrolling="no" align="center"></iframe>');
            }
        }

        var AE = document.createElement("div");
        AE.setAttribute("id", getID("loading"));
        h.appendChild(AE);
        var loadingLink = document.createElement("a");
        loadingLink.setAttribute("id", getID("loadingLink"));
        loadingLink.setAttribute("href", "javascript:void(0);");
        loadingLink.innerHTML = "正在加裁中...";
        AE.appendChild(loadingLink);
        $(loadingLink).bind('click', function() { closeme(); });
        var close_div = document.createElement("div");
        close_div.setAttribute("id", getID("close"));

        AI.appendChild(close_div);

        var Z = document.createElement("a");
        Z.setAttribute("id", getID("closeLink"));
        Z.setAttribute("href", "javascript:void(0);");
        Z.innerHTML = "";
        close_div.appendChild(Z);
        $(Z).bind('click', function() { closeme(); });

        if (isAlertWindow) {
            $(BTN_OK).bind("click", function() { okfun(); });
            $(BTN_CLOSE).bind("click", function() { closeme(); });
            $(BTN_CANCEL).bind("click", function() { cancelfun(); });
            $(BTN_OK).bind("mouseover", function() { this.className = 'button-hover' });
            $(BTN_OK).bind("mouseout", function() { this.className = 'button' });
            $(BTN_OK).bind("mousedown", function() { this.className = 'button-down' });
            $(BTN_CLOSE).bind("mouseover", function() { this.className = 'button-hover' });
            $(BTN_CLOSE).bind("mouseout", function() { this.className = 'button' });
            $(BTN_CLOSE).bind("mousedown", function() { this.className = 'button-down' });
            $(BTN_CANCEL).bind("mouseover", function() { this.className = 'button-hover' });
            $(BTN_CANCEL).bind("mouseout", function() { this.className = 'button' });
            $(BTN_CANCEL).bind("mousedown", function() { this.className = 'button-down' });
            var showmore = options.content.moretext != "";

            $(BTN_SWITCH).bind("click", function() { SW(); });
            $(BTN_SWITCH).bind("mouseover", function() { SMV(); });
            $(BTN_SWITCH).bind("mouseout", function() { SMO(); });
            //$(BTN_SWITCH).bind("mousedown", function() { SMV(); });
            if (options.mode == "alert" || options.mode == "info" || options.mode == "error") {
                $(BTN_OK).hide();
                $(BTN_CLOSE).show();
                $(BTN_CANCEL).hide();
            } else if (options.mode == "query") {
                $(BTN_OK).show();
                $(BTN_CLOSE).hide();
                $(BTN_CANCEL).show();
            }
        }
        $('#alertwindow').Drags({
            handler: '.caption',
            opacity: .9
        });

        var show = this.show = function(o) {
            this.start(o);
        }
        var start = this.start = function(G) {
            Aa();
            var pageSize = w();
            $$("overlay").css({ height: pageSize.pageHeight + "px" });
            $$("footerDataContainer").hide();
            $$("windowContent").hide();
            $$("overlay").css({ opacity: 0 }).show().fadeTo(overlayDuration * 1000, options.overlayOpacity);
            $$("alertwindow").show();

            if (options.featBrowser) {
                $(window).resize(v);
            }
            if (options.floating) {
                $(window).scroll(v);
            }
            $(window).resize(adjustOverlay);
            $(window).scroll(adjustOverlay);
            changeContent();
        };
        var closeme = this.closeme = function closeme(Event) {
            $$("windowContainer").stop(true, false);
            $$("windowContent").stop(true, false);
            if (I) {
                I.onload = null;
            }
            V();
            $$("alertwindow").hide();
            if (options.overlayOpacity) {
                $$("overlay").fadeOut(overlayDuration * 1000);
            } else {
                $$("overlay").hide();
            }
            $(window).unbind("resize", v);
            $(window).unbind("scroll", v);
            $(window).unbind("resize", adjustOverlay);
            $(window).unbind("scroll", adjustOverlay);
            $$("windowContainer").remove();
            $$("windowContent").remove();
            $$("alertwindow").remove();
            $$("overlay").remove();
            AU();
        }
        function changeContent() {
            V();
            showLoading();
            if (isAlertWindow) {
                $$("footerDataContainer").hide();
                $$("footData").hide();
            }
            AC(false);
        }
        function AC(recall, J) {
            var imgWidth = options.size[0];
            var imgHeight = options.size[1];
            var L = w();
            var r = imgWidth / imgHeight;
            if (options.featBrowser) {
                var AX = L.AL / L.s;
                if (r > AX) {
                    var t = L.AL - options.borderSize * 2 - options.breathingSize * 2;
                    var z = Math.round(t / r);
                } else {
                    var z = L.s - options.borderSize * 2 - options.breathingSize * 2 - m;
                    var t = Math.round(z * r);
                }
                if (imgWidth > t || imgHeight > z) { imgWidth = t; imgHeight = z; }
            }
            var K = AM().y + (w().s - (imgHeight + m + options.borderSize * 2)) / 2;
            var Q = $$("windowContainer");
            if (recall == true) {
                Q.css({ width: imgWidth + "px" });
                if (options.floating) {
                    moveEffect($$("alertwindow"), K);
                } else {
                    $$("alertwindow").css({ top: K + "px" });
                }
            }
            else {
                var F = $$("windowContent");
                Q.stop(true, false);
                F.stop(true, false);
                var H;
                with (Q) {
                    var D = r / (width() / height());
                }
                AV(K, imgWidth, imgHeight, D, J);
            }
            if (isAlertWindow) {
                $$("footerDataContainer").css({ width: imgWidth + "px" });
            }
        }
        function AV(K, imgWidth, imgHeight, D, J) {
            var Q = $$("windowContainer");
            var lightbox = $$("alertwindow");
            moveEffect(lightbox, K);
            SW();
            if (options.mode == "iframe") {
                $$('alertwindow_iframe').css({ height: imgHeight + "px", width: imgWidth + "px" });
            }
            if (!options.fadeOut) {
                Q.animate({ height: imgHeight + "px", width: imgWidth + "px" }, { queue: false, duration: resizeDuration * 1000, complete: !J ? function() {
                    if (isAlertWindow) {
                        $$("windowContainer").css({ height: "auto" });
                    }
                    updateDetails();
                    AS();
                } : null
                });
            }
            else {
                Q.css({ height: imgHeight + "px", width: imgWidth + "px" });
                if (isAlertWindow) {
                    $$("windowContainer").css({ height: "auto" });
                }
                updateDetails();
                AS();
            }
        }
        function moveEffect(lightbox, K) {
            if (options.fadeOut) {
                $$("windowContent").css({ opacity: 0 }).show().fadeTo(overlayDuration * 1000, 1);
            }
            lightbox.css({ width: '100%', left: 0, top: K });
        }
        function showLoading() {
            clearTimeout(showTimer);
            var loading = $$("loading");
            loading.show();
            loading.css({ visibility: "hidden" });
            showTimer = setTimeout(function() {
                $$("loading").css({ visibility: "visible" });
            }, 300);
        }
        function hideLoading() {
            clearTimeout(showTimer);
            $$("loading").hide();
        }

        function updateDetails() {
            hideLoading();
            $$("caption").show();
            $$("caption").text(options.title || "");
            if (isAlertWindow) {
                $$("footerDataContainer").show();
                if (options.footer.show) {
                    $$("footData").show();
                }
                if (showmore) {
                    $$("moreText").show();
                } else {
                    $$("moreText").hide();
                }
                if (options.content.moretext == "") {
                    $(BTN_SWITCH).hide();
                }
            }
            else {
                if (options.mode == "iframe") {
                    $$('alertwindow_iframe').attr("src", options.iframesrc);

                }
            }
            $$("windowContent").show();
            if (options.mode == "widget") {
                try {
                    if (typeof window[options.widgetname] == "function") {

                        window[options.widgetname](me, AJ);
                    }
                } catch (e) {
                }
            }

        }
        function okfun() {
            closeme();
            if (typeof options.okFun == "function") {
                options.okFun();
            }
        }
        function cancelfun() {
            closeme();
            if (typeof options.cancelFun == "function") {
                options.cancelFun();
            }
        }
        function SMV() {
            $(BTN_SWITCH).removeClass("btn_switch_dw").removeClass("btn_switch_up");
            if (showmore) {
                $(BTN_SWITCH).addClass("btn_switch_up_h");
            } else {
                $(BTN_SWITCH).addClass("btn_switch_dw_h");
            }
        }
        function SMO() {
            $(BTN_SWITCH).removeClass("btn_switch_dw_h").removeClass("btn_switch_up_h");
            if (showmore) {
                $(BTN_SWITCH).addClass("btn_switch_up");
            } else {
                $(BTN_SWITCH).addClass("btn_switch_dw");
            }
        }
        function SW() {
            if (showmore) {
                showmore = false;
                $$("morePanel").animate({ height: "hide", opacity: "hide" }, 250, null, function() {
                    $$("moreText").hide();
                });
            } else {
                showmore = true;
                $$("moreText").show();
                $$("morePanel").animate({ height: "show", opacity: "show" }, 250, null, function() {

                });
            }
        }

        function AS() {
            //to do more
        }

        function v() {
            AC(true);
        }
        function V() {
            if (k) {
                k = clearTimeout(k);
            }
        }
        function adjustOverlay() {
            var L = w();
            $$("overlay").css({ left: AM().x + "px", top: 0, width: "100%", height: Math.max(L.s, L.pageHeight) + "px" });
        }
        function AU() {
            var els; var tags = badObjects;
            for (var i = 0; i < tags.length; i++) {
                els = document.getElementsByTagName(tags[i]);
                for (var j = 0; j < els.length; j++) {
                    $(els[j]).css({ visibility: "visible" });
                }
            }
        }
        function Aa() {
            var tags = badObjects;
            for (var i = 0; i < tags.length; i++) {
                $(tags[i]).css({ visibility: "hidden" });
            }
        }
        function AM() {
            var x, y; if (self.pageYOffset) {
                x = self.pageXOffset; y = self.pageYOffset;
            } else if (document.documentElement && document.documentElement.scrollTop) {
                x = document.documentElement.scrollLeft;
                y = document.documentElement.scrollTop;
            } else if (document.body) {
                x = document.body.scrollLeft; y = document.body.scrollTop;
            } return { x: x, y: y };
        }
        function w() {
            var scrollX, scrollY, N, M, pageX, pageY;
            if (window.innerHeight && window.scrollMaxY) {
                scrollX = document.body.scrollWidth;
                scrollY = window.innerHeight + window.scrollMaxY;
            } else if (document.body.scrollHeight > document.body.offsetHeight) {
                scrollX = document.body.scrollWidth;
                scrollY = document.body.scrollHeight;
            } else {
                scrollX = document.body.offsetWidth;
                scrollY = document.body.offsetHeight;
            }
            if (self.innerHeight) {
                N = self.innerWidth; M = self.innerHeight;
            } else if (document.documentElement && document.documentElement.clientHeight) {
                N = document.documentElement.clientWidth;
                M = document.documentElement.clientHeight;
            } else if (document.body) {
                N = document.body.clientWidth;
                M = document.body.clientHeight;
            }
            pageY = scrollY < M ? M : scrollY; pageX = scrollX < N ? N : scrollX;
            return { pageWidth: pageX, pageHeight: pageY, AL: N, s: M };
        }
        function getID(id) {
            return options.prefix + id;
        }
        function $$(name) {
            return $("#" + getID(name));
        }
        return this;
    };
})(jQuery);
var $AlertWindowParams$ = {  };

