/***************************/
// @implementing and optimizing for ACA: Alex Baskov, 2010
/***************************/

//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatusThankYou = 0;


//loading popup with jQuery magic!
function loadPopupThankYou()
{
	//loads popup only if it is disabled
	if(popupStatusThankYou == 0)
	{
		$("#popupThankYouBackground").css({
			"opacity": "0.4" // set to zero, if you don't want to have a background
		});
		$("#popupThankYouBackground").fadeIn("slow");
		$("#popupThankYou").fadeIn("slow");
		popupStatusThankYou = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopupThankYou()
{
	//disables popup only if it is enabled
	if(popupStatusThankYou == 1)
	{
		$("#popupThankYouBackground").fadeOut("slow");
		$("#popupThankYou").fadeOut("slow");
		popupStatusThankYou = 0;
	}
}

//centering popup
function centerPopupThankYou()
{
	//request data for centering
	//var windowWidth = document.documentElement.clientWidth;
	//var windowHeight = document.documentElement.clientHeight;
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupThankYou").height();
	var popupWidth = $("#popupThankYou").width();

	//centering
	$("#popupThankYou").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#popupThankYouBackground").css({
		"height": windowHeight
	});
	
}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function() {

	//LOADING POPUP
	//Click the button event!
	
	$("#buttonThankYou").click(function() {
		centerPopupThankYou();
		loadPopupThankYou();
	});
	
	$("#popupThankYouClose, #thankYouButtonClose").click(function() {
		disablePopupThankYou();
	});
			
	//Click out event!
	$("#popupThankYouBackground").click(function() {
		disablePopupThankYou();
	});
	
	//Press Escape event!
	$(document).keypress(function(e) {
		if (e.keyCode == 27 && popupStatusThankYou == 1) {
			disablePopupThankYou();
		}
	});
	
});


