/***************************/
//@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 loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7",
			"z-index": "100000000"
		});
		//$(this).attr('id')
		$("#LoginBlock").css({
			"z-index": "200000000"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#LoginBlock").fadeIn("slow");
		popupStatus = 1;
	}
}


//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#LoginBlock").fadeOut("slow");
		popupStatus = 0;
	}
}




//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#LoginBlock").height();
	var popupWidth = $("#LoginBlock").width();
	//centering
	$("#LoginBlock").css({
		"position": "absolute",
		"top": windowHeight/3+200-popupHeight/1,
		"left": windowWidth/3+150-popupWidth/3
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}



//loading popup with jQuery magic!
function loadPopupSignupBlock(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7",
			"z-index": "100000000"
		});
		//$(this).attr('id')
		$("#SignupBlock").css({
			"z-index": "200000000"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#SignupBlock").fadeIn("slow");
		popupStatus = 1;
	}
}


//disabling popup with jQuery magic!
function disablePopupSignupBlock(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#SignupBlock").fadeOut("slow");
		popupStatus = 0;
	}
}




//centering popup
function centerPopupSignupBlock(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#SignupBlock").height();
	var popupWidth = $("#SignupBlock").width();
	//centering
	$("#SignupBlock").css({
		"position": "absolute",
		"top": windowHeight/3+550-popupHeight/1,
		"left": windowWidth/3+60-popupWidth/3
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}




//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){

//$('.popupShow').attr('id');
 
	  // loeading confirmation poopup
	   $("#loginPopup").click(function(){
		 
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
	
	
		  // loeading confirmation poopup
	   $("#signupPopup").click(function(){
		 
	//	  $(".body-table").css({ "height":"400px" });
		//centering with css
		centerPopupSignupBlock();
		//load popup
		loadPopupSignupBlock();
	});
	
	
	 $("#signupPopup2").click(function(){

		//centering with css
		disablePopup();
		//load popup
		
		centerPopupSignupBlock();
		loadPopupSignupBlock();
	//	$(".body-table").css({ "height":"400px" });
	});
	 
	  $("#loginPopup2").click(function(){

		//centering with css
		disablePopupSignupBlock();
		//load popup
		
		centerPopup();
		//load popup
		loadPopup();
	//	$(".body-table").css({ "height":"200px" });
	});
	
	  // loeading confirmation poopup
	   $(".LoginBlockClose").click(function(){
		disablePopup();
		//disablePopupEmailSending();
	});
	
	 // loeading confirmation poopup
	   $(".SignupBlockClose").click(function(){
	//	$(".body-table").css({ "height":"200px" });									 
		//disablePopup();
		disablePopupSignupBlock();
	});
	
	
	//Press Escape event to close all popus!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
			disablePopupSignupBlock();
			$("#SignupBlock").fadeOut("slow");
		}
		
	});
	
	

});