var popupStatus = 0;  

$(document).ready(function() {
	$("#popupWinClose").click(function() {  
		disablePopup();  
	});  
	$("#popupBackground").click(function() {  
		disablePopup();  
	});  
	
	$(document).keypress(function(e) {  
		if ((e.keyCode==27) && (popupStatus==1)) {  
			disablePopup();  
		}  
	}); 
	
});



function loadPopup() {  
  	if(popupStatus==0) {  
		$("#popupBackground").css({  
		"opacity": "0.7"  
		});  
		$("#popupBackground").fadeIn("slow");  
		$("#popupWin").fadeIn("slow");  
		popupStatus = 1;  
  	}  
} 

function disablePopup(){  
	//disables popup only if it is enabled  
	if(popupStatus==1) {  
		$("#popupBackground").fadeOut("slow");  
		$("#popupWin").fadeOut("slow");  
		popupStatus = 0;  
	}  
} 

function centerPopup() {  
	//request data for centering  
	var windowWidth = document.documentElement.clientWidth;  
	var windowHeight = document.documentElement.clientHeight;  
	var popupHeight = $("#popupWin").height();  
	var popupWidth = $("#popupWin").width();  
	//centering  
	$("#popupWin").css({  
		"position": "absolute",  
		"top": windowHeight/2-popupHeight/2,  
		"left": windowWidth/2-popupWidth/2  
	});  
	//only need force for IE6  
  
	$("#popupBackground").css({  
		"height": windowHeight  
	});  
}


