﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle
//@website: www.yensdesign.com
//@email: yensamg@gmail.com
//@license: Feel free to use it, but keep this credits please!					
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(popupLayer){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#bgPopup").css({
			"opacity": "0.8"
		});
		$("#bgPopup").fadeIn(200);
		$(popupLayer).fadeIn(200);
		popupStatus = 1;		
		var iframeShim = document.getElementById('bgPopup');  
		$iframeShim = $(iframeShim);	 
		$iframeShim.css('z-index','998'); 
        var iFrm = document.createElement("IFRAME");
            $iFrm = $(iFrm);
            $(iFrm).css(
                    {
                        "position":"absolute",
                        "width":"100%",
                        "height":"100%",
                        "border":"0",
                        "margin":"0",
                        "padding":"0",
                        "opacity":"0",
                        "frameborder":"0",
                        "left":"0",
                        "top":"0"                    
                    }
                )
    	iFrm.style.zindex = iframeShim.style.zindex; 
        iframeShim.appendChild(iFrm);
		return $iframeShim;
	}
}

//disabling popup with jQuery magic!
function disablePopup(popupLayer){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#bgPopup").fadeOut(200);
		$(popupLayer).fadeOut(200);
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(popupLayer, popupHeight){
	//request data for centering
	var windowWidth = $(window).width();
	var windowHeight = $(window).height();
	if (popupHeight == null)
	    popupHeight = $(popupLayer).height();
	var popupWidth = $(popupLayer).width();
	//centering
	$(popupLayer).css({
	    "display": "block",
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2,
		"z-index": "999"
	});
	//only need force for IE6
	
	$("#bgPopup").css({
		"height": windowHeight
	});	
}
