/***************************/
//@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 popupStatu = 0;

//loading popup with jQuery magic!
function loadPopu(){
	//loads popup only if it is disabled
	if(popupStatu==0){
		$("#backgroundPopu").css({
			"opacity": "0.8"
		});
		$("#backgroundPopu").fadeIn("slow");
		$("#popupBilling").fadeIn("slow");
		popupStatu = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopu(){
	//disables popup only if it is enabled
	if(popupStatu==1){
		$("#backgroundPopu").fadeOut("slow");
		$("#popupBilling").fadeOut("slow");
		popupStatu = 0;
	}
}

//centering popup
function centerPopu(){
	//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": 50,
		"left": windowWidth/2-popupWidth/2,
		"z-index": 5,
	});
	//only need force for IE6
	
	$("#backgroundPopu").css({
		"height": windowHeight,
		"z-index": 4,
	});
	
}



//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#menu-item-17").click(function(){
		//centering with css
		centerPopu();
		//load popup
		loadPopu();
	});
	
	
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupBillingClos").click(function(){
		disablePopu();
	});
	//Click out event!
	$("#backgroundPopu").click(function(){
		disablePopu();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopu();
		}
	});

});
