var popupStatus=0;
var isLoaded=false;

function displayPopupUrl(url, data) {
	if(popupStatus==0){
		jQuery("#backgroundPopup").css({
			"opacity": "0.7"
		});
		
		jQuery("#popupContent")
			.html('<img class="throbber" src="/images/throbber.gif" alt="Loading..." />')
			.load(url, data);
		
		jQuery("#backgroundPopup").fadeIn("slow");
		jQuery("#popup").fadeIn("slow");
		
		//document.body.style.overflow = 'none';
		
		popupStatus = 1;
	}
}

function loadPopup(productId, url) {
	if(popupStatus==0){
		jQuery("#backgroundPopup").css({
			"opacity": "0.7"
		});
		
		jQuery("#popupContent")
			.html('<img class="throbber" src="/images/throbber.gif" alt="Loading..." />')
			.load(url, {productid: productId, popup: true });
		
		jQuery("#backgroundPopup").fadeIn("slow");
		jQuery("#popup").fadeIn("slow");
		
		//document.body.style.overflow = 'none';
		
		popupStatus = 1;
	}
}

function showPopup(popupDiv, popupContentDiv, content)
{
	if(popupStatus==0){
		jQuery("#backgroundPopup").css({
			"opacity": "0.7"
		});
		
		jQuery(popupContentDiv)
		.html('')
		.html(content);
		
		jQuery("#backgroundPopup").fadeIn("slow");
		jQuery(popupDiv).fadeIn("slow");
		
		//document.body.style.overflow = 'none';
		
		popupStatus = 1;
	}
}

function disablePopup(popupDiv) {
	//disables popup only if it is enabled
	if(popupStatus==1){
		jQuery("#backgroundPopup," + popupDiv).fadeOut("slow");
		
		//document.body.style.overflow = 'scroll';
		
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(popupDiv) {
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = jQuery(popupDiv).height();
	var popupWidth = jQuery(popupDiv).width();
	//centering
	jQuery(popupDiv).css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2 + jQuery(window).scrollTop(),
		"left": windowWidth/2-popupWidth/2 + jQuery(window).scrollLeft()
	});
	//only need force for IE6
	
	jQuery("#backgroundPopup").css({
		"height": windowHeight
	});
}


jQuery(document).ready(function() {
	 jQuery("#popupClose, #backgroundPopup").click(function(){  
		disablePopup("#popup");  
	});  
	
	//Press Escape event!  
	jQuery(document).keypress(function(e){  
		if(e.keyCode==27 && popupStatus==1){  
			disablePopup("#popup");  
		}  
	}); 
});
