// JavaScript Document
/***************************/
//@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 loadBilling(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundBilling").css({
			"opacity": "0.7"
		});
		$("#backgroundBilling").fadeIn("slow");
		$("#popupBilling").fadeIn("slow");
		popupStatus = 1;
	}
}

//loading popup with jQuery magic!
function loadVari(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundVari").css({
			"opacity": "0.7"
		});
		$("#backgroundVari").fadeIn("slow");
		$("#popupVari").fadeIn("slow");
		popupStatus = 1;
	}
}

//loading popup with jQuery magic!
function loadDelivery(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundDelivery").css({
			"opacity": "0.7"
		});
		$("#backgroundDelivery").fadeIn("slow");
		$("#popupDelivery").fadeIn("slow");
		popupStatus = 1;
	}
}



//disabling popup with jQuery magic!
function disableBilling(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundBilling").fadeOut("slow");
		$("#popupBilling").fadeOut("slow");
		popupStatus = 0;
		
	
	}
}
//disabling popup with jQuery magic!
function disableVari(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundVari").fadeOut("slow");
		$("#popupVari").fadeOut("slow");
		popupStatus = 0;
		
	
	}
}


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


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

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




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

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP

$(".update_delivery").click(function(){
		//centering with css
		centerDelivery();
		//load popup
		loadDelivery();
	});

$(".update_billing").click(function(){
		//centering with css
		centerBilling();
		//load popup
		loadBilling();
	});

$(".update_vari").click(function(){
		//centering with css
		centerVari();
		//load popup
		loadVari();
	});

	//CLOSING POPUP
	//Click the x event!
	$("#popupDeliveryClose").click(function(){
		disableDelivery();
	});
		$("#popupVariClose").click(function(){
		disableVari();
	});
	$("#popupBillingClose").click(function(){
		disableBilling();
	});

	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disableDelivery();
			disableBilling();
			disableVari();
		}
	});

});
