﻿(function($)
{
    var ModalWindow = function()
    {
        var
windowStatus = 0, backgroundId = "#windowBackground", windowId = "#windowMain", closeId = "#windowMainClose", welcomeUrl = resSiteRoot + "/ModalWindow/welcome.htm", windowHTML = '<div id="windowMain"><div id="popupTitle"><a id="windowMainClose" title="关闭窗口">x</a><h1>3G世界会员中心</h1></div><iframe scrolling="no" width="375" height="225" frameborder="0" src="' + welcomeUrl + '"></iframe></div><div id="windowBackground"></div>', init = function(url, title, width, height)
{
    if (url)
    {
        if ($.browser.msie)
        {
            if (url.indexOf("?") > -1)
            { url += "&rnd=" + Math.random(); }
            else
            { url += "?rnd=" + Math.random(); } 
        }
        $("#windowMain iframe").attr("src", url);
    }
    if (width)
    { $("#windowMain iframe").attr("width", width); $(windowId).css("width", width + "px"); }
    if (height)
    { $("#windowMain iframe").attr("height", height - 25); $(windowId).css("height", height + "px"); }
    if (title) $("#windowMain #popupTitle h1").html(title);
}, loadWindow = function()
{
    if (windowStatus == 0)
    { $(backgroundId).height($(document).height()); $(backgroundId).css({ "opacity": "0.7" }); $(backgroundId).fadeIn("slow"); $(windowId).fadeIn("slow"); windowStatus = 1; } 
}, hideWindow = function()
{
    if (windowStatus == 1)
    { $("#windowMain iframe").attr("src", welcomeUrl); $(backgroundId).fadeOut("slow"); $(windowId).fadeOut("slow"); windowStatus = 0; } 
}, centerWindow = function()
{ var windowWidth = document.documentElement.clientWidth; var windowHeight = document.documentElement.clientHeight; var popupHeight = $(windowId).height(); var popupWidth = $(windowId).width(); $(windowId).css({ "position": "absolute", "top": windowHeight / 3 - popupHeight / 3 + $(document).scrollTop(), "left": windowWidth / 2 - popupWidth / 2 }); $(backgroundId).css({ "height": windowHeight }); }; return { ready: function()
{
    $(document).ready(function()
    {
        $(windowHTML).appendTo(document.body); $(closeId).click(function()
        { hideWindow(); }); $(backgroundId).click(function()
        { hideWindow(); }); $(document).keypress(function(e)
        {
            if (e.keyCode == 27 && windowStatus == 1)
            { hideWindow(); } 
        });
    });
}, show: function(url, title, width, height)
{ init(url, title, width, height); centerWindow(); loadWindow(); }, hide: function()
{ hideWindow(); } 
};
    } (); ModalWindow.ready(); $.extend({ showModalWindow: ModalWindow.show, hideModalWindow: ModalWindow.hide });
})(jQuery);