//SETTING UP OUR POPUP
//0 means disabled; 1 means enabled;
var popupStatusSignup = 0;

//loading popup with jQuery magic!
function loadOverlaySignup(){
	//loads popup only if it is disabled
	if(popupStatusSignup==0){
		$(".backgroundOverlaySignup").css({
			"opacity": "0.8"
		});
		$(".backgroundOverlaySignup").fadeIn("slow");
		$(".overlaySignup").fadeIn("slow");
		popupStatusSignup = 1;
	}
}

//disabling popup with jQuery magic!
function disableOverlaySignup(){
	//disables popup only if it is enabled
	if(popupStatusSignup==1){
		$(".backgroundOverlaySignup").fadeOut("slow");
		$(".overlaySignup").fadeOut("slow");
		popupStatusSignup = 0;
	}
}

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


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	$('.signup').click(function(){
	
	//centering with css
	centerOverlaySignup();
	//load popup
	loadOverlaySignup();
	
	});
				
	//CLOSING POPUP
	//Click the x event!
	$(".overlaySignupClose").click(function(){
		disableOverlaySignup();
	});
	//Click out event!
	$(".backgroundOverlaySignup").click(function(){
		disableOverlaySignup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatusSignup==1){
			disableOverlaySignup();
		}
	});

});

