//this popup opens add-to-cart popup
function loadPopup(){
	//loads popup only if it is disabled

	if(popupStatus==0){
		jQuery(popupBackIdStr).fadeIn("slow");
		jQuery(popupShadowStr).show();
		jQuery(popupIdStr).fadeIn("slow");
		jQuery("body").css("overflow","hidden");
		popupStatus = 1;
	}
}

function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		jQuery(popupBackIdStr).fadeOut("slow");
		jQuery(popupShadowStr).fadeOut();
		jQuery(popupIdStr).fadeOut("slow");
		jQuery("body").css("overflow","auto");
		popupStatus = 0;
	}
}

var popupTopPosition;

//centering popup
function centerPopup(popupInerID){
	//request data for centering
	jQuery("body").css("overflow","hidden");
	var windowWidth = jQuery(window).width();//document.documentElement.clientWidth;
	var windowHeight = jQuery(window).height();//document.documentElement.clientHeight;
	var popupHeight  = jQuery(popupIdStr).height();
	var popupWidth;
	
	popupTopPosition = windowHeight/2-popupHeight/2;
	
	if (popupInerID) {
		popupWidth	= jQuery("#" + popupInerID).width();		
	}
	else {
		popupWidth = jQuery(popupIdStr).width();
	}
	//centering
	jQuery(popupIdStr).css({
		"position": "absolute",
		"top": getBodyScrollTop() + windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2,
		"width": popupWidth
	});
	
	
	jQuery(popupShadowStr).css({
		"width": "440",
		"height": "270",
		"top": (getBodyScrollTop() + windowHeight/2-popupHeight/2)+10,
		"left": (windowWidth/2-popupWidth/2)-20
	});
	
	//only need force for IE6
	jQuery(popupBackIdStr).css({
		"height": jQuery(document).height(),
		"width":windowWidth
	});

}
function getBodyScrollTop()
{
  return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}



jQuery(document).ready(function(){
	//Click out event!  
	jQuery("#popbackground").click(function(){  
		disablePopup(); 
	});  
	
	//Press Escape event!  
	jQuery(document).keypress(function(e){  
		if(popupStatus==1){  
			disablePopup();  
		}
	});
	
	jQuery(window).scroll(function (ev) { 
	       if (popupStatus == 1){
	    	   jQuery(popupIdStr).css("top", (popupTopPosition+$(document).scrollTop())+"px");
	    	   jQuery(popupShadowStr).css("top", (popupTopPosition+$(document).scrollTop()+10)+"px");
	       }
	    });

});


var popupStatus = 0;
var popupId = "popbord";
var popupIdStr = "#"+popupId;
var popupBackgroundId = "popbackground";
var popupBackIdStr = "#popbackground";
var popupShadowStr = "#popbordbackground";

function loadCartPopup(response)
{
jQuery(popupBackIdStr).remove();
jQuery(popupIdStr).css({"visibility":"visible"});
jQuery("#popbody").html(response);
jQuery("body").append("<div onclick='disablePopup();return false;' id='"+popupBackgroundId+"'></div>");

centerPopup();
loadPopup();

jQuery("#popbord").show();
}