var popupStatus = '0';
function loadPopup()
{
	//loads popup only if it is disabled
	var width=document.body.clientWidth;
	if(popupStatus=='0')
	{
		//alert(popupStatus)
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").css({
			"width": width
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupReplay").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup()
{
	//disables popup only if it is enabled
	if(popupStatus==1)
	{
		$("#backgroundPopup").fadeOut("slow");
		$("#popupReplay").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup()
{
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY)
	{	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight)
	{ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} 
	else
	{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight)
	{	// all except Explorer

		if(document.documentElement.clientWidth)
		{
			windowWidth = document.documentElement.clientWidth; 
		}
		else
		{
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	{ // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;

	} else if (document.body)
	{ // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	if(yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	} 
	else 
	{ 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth)
	{	
		pageWidth = xScroll;		
	} 
	else 
	{
		pageWidth = windowWidth;
	}
	
	var popupHeight = $("#popupReplay").height();
	var popupWidth = $("#popupReplay").width();

	
	
	if(windowWidth==0 || windowHeight==0)
	{
			//centering  in IE
			$("#popupReplay").css({
				
				"top": 115,
				"left": 188
				
			});
	}
	else
	{
			// centering in firefox
			$("#popupReplay").css({
				
				"position": "absolute",
				"top": windowHeight/2-popupHeight/2,
				"left": windowWidth/2-popupWidth/2
				
			});
	}
	//winheight=document.body.scrollHeight;
	
	$("#backgroundPopup").css({
		"height": pageHeight
	});
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function()
{
	
	//Click out event!
	$("#backgroundPopup").click(function()
	{
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e)
	{
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});