/***************************/
//@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_box
//0 means disabled; 1 means enabled;
var popupStatus = 0;

//loading popup_box with jQuery magic!
function loadpopup(){
	//loads popup_box only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.2"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popup_box").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup_box with jQuery magic!
function disablepopup(){
	//disables popup_box only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popup_box").fadeOut("slow");
		popup_boxStatus = 0;
	}
}

//centering popup_box
function centerpopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popup_boxHeight = $("#popup_box").height();
	var popup_boxWidth = $("#popup_box").width();
	//centering
	$("#popup_box").css({
		"position": "absolute",
		"top": 150,
		"left": windowWidth/2-popup_boxWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

$(document).ready(function() {

//centering with css
		centerpopup();
		//load popup_box
		loadpopup();
		
	//CLOSING popup_box
	//Click the x event!
	$("#popupClose").click(function(){
		disablepopup();
	});
	
	
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablepopup();
		}
	});
});
