//弹出层,在同一个页面可以弹出多个层
function loadPopup(objPopupContact,objBackground){
    objBackground.css({
	    "opacity": "0.3"
    });
    objBackground.fadeIn("fast");
    objPopupContact.fadeIn("fast");
    centerPopup(objPopupContact,objBackground);
};

function centerPopup(objPopupContact,objBackground){
    var documentWidth = $(document).width();
    var documentHeight = $(document).height();
    var windowWidth = $(window).width();
    var windowheight = $(window).height();
    var popupHeight = objPopupContact.height();
    var popupWidth = objPopupContact.width();
    objPopupContact.css({
	    "position": "absolute",
	    "left": windowWidth/2-popupWidth/2
    });
    objBackground.css({"height": documentHeight,"width": documentWidth});    
};

function disablePopup(objPopupContact,objBackground){
    objPopupContact.fadeOut("fast");
    if(objBackground){objBackground.fadeOut("fast");};
    $("select").css('visibility','visible');
};

(function($){
    $.fn.popup=function(options){
        var settings={width:400,height:400,top:50,left:0,isFixed:false,objbackground:'backgroundPopup',popupHead:'popupHead',btnClose:'popupClose'};
        if(options){$.extend(settings,options)};
        var objPopup = $(this);
        var objBackground = $('#'+settings.objbackground);
        objBackground.addClass('bgshowStatus')
        objPopup.addClass('contentShowStatus');
        
		
        if($.browser.msie && $.browser.version=='6.0'){
			var heightPercent = 100;
            var tmpHeight = settings.height;
            if(tmpHeight.indexOf('%') != -1){
                heightPercent = tmpHeight.substring(0,tmpHeight.length-1);
                tmpHeight = ($(window).height() * heightPercent) / 100;
            };
            settings.height = tmpHeight;
            objPopup.height(tmpHeight);
        }
        objPopup.css({
            "width":settings.width,
            "height":settings.height,
            "top":Number(settings.top) + Number(settings.isFixed ? document.documentElement.scrollTop : 0)
        });

        if(settings.isFixed){
            $(window).scroll(function(){
                objPopup.css('top',Number(settings.top)+Number(document.documentElement.scrollTop));
            });
        };
        
        loadPopup(objPopup,objBackground);
        //$("select").hide();
		$("select").css('visibility','hidden');
        $("select",objPopup).css('visibility','visible');
        objPopup.easydrag();
        objPopup.setHandler(settings.popupHead);
        
        var objClose;
        if($('#'+settings.btnClose,objPopup).length != 0){
            objClose = $('#'+settings.btnClose,objPopup);
        }else if($('.'+settings.btnClose,objPopup).length != 0){
            objClose = $('.'+settings.btnClose,objPopup);
        };
        objClose.click(function(){
            alert('asdf');
            disablePopup(objPopup,objBackground);
        });
    }
})
(jQuery);
$(document).keypress(function(e){if(e.keyCode==27){disablePopup($('.contentShowStatus'),$('.bgshowStatus'));}});
$(window).resize(function(){centerPopup($('.contentShowStatus'),$('.bgshowStatus'));});