//SETTING UP OUR POPUP  
//0 means disabled; 1 means enabled;  
var popupStatus = 0;  

jQuery (document).ready(function() {
	//LOADING POPUP  
	//Click the button event!  
	jQuery("a.loginLink").click(function(e){  
		//centering with css  
		//load popup  

		var windowWidth = document.documentElement.clientWidth;  
		var windowHeight = document.documentElement.clientHeight;  
		var popupHeight = jQuery("#popupLogin").height();  
		var popupWidth = jQuery("#popupLogin").width(); 
		var x = e.pageX-75;
		var y = e.pageY-32;
		if (x < 10) x = 10;
		if (x > windowWidth - popupWidth - 10) x = windowWidth - popupWidth - 10;
		if (y < 10) y = 10;
		if (y > windowWidth - popupHeight - 10) y = windowHeight - popupHeight - 10;
		jQuery("#popupLogin").css({  
			"position": "absolute",  
			"top": y,  
			"left": x  
		});  
		//centerPopup();  
		loadPopup();  
		return false;
	});  

	jQuery("#popupLoginClose").click(function(){ disablePopup(); });  
	jQuery("#backgroundPopup").click(function(){ disablePopup(); });  

	//Press Escape event!  
	jQuery(document).keypress(function(e){  
		if(e.keyCode==27 && popupStatus==1){  
			disablePopup();  
		}  
	});  
});  

function showLoginForm () {
	jQuery ("div#plForgotSection").fadeOut ();
	jQuery ("div#plLoginSection").fadeIn ();
}

function showForgotForm () {
	jQuery ("div#plForgotSection").fadeIn ();
	jQuery ("div#plLoginSection").fadeOut ();
}

//loading popup with jQuery magic!  
function loadPopup(){  
	//loads popup only if it is disabled  
	if(popupStatus==0){  
		jQuery(".pagewrap").css({"z-index": -1});
		jQuery("#backgroundPopup").css({  
			"opacity": "0.5"  
		});  
		jQuery("#backgroundPopup").fadeIn("normal");  
		jQuery("#popupLogin").fadeIn("normal");  
		popupStatus = 1;  
	}  
	showLoginForm();
}  

//disabling popup with jQuery magic!  
function disablePopup(){  
	//disables popup only if it is enabled  
	if(popupStatus==1){  
		jQuery(".pagewrap").css({"z-index": 0});
		jQuery("#backgroundPopup").fadeOut("normal");  
		jQuery("#popupLogin").fadeOut("normal");  
		popupStatus = 0;  
		
	}  
}  

//centering popup  
function centerPopup(){  
	//request data for centering  
	var windowWidth = document.documentElement.clientWidth;  
	var windowHeight = document.documentElement.clientHeight;  
	var popupHeight = jQuery("#popupLogin").height();  
	var popupWidth = jQuery("#popupLogin").width();  
	//centering  
	jQuery("#popupLogin").css({  
		"position": "absolute",  
		"top": windowHeight/2-popupHeight/2,  
		"left": windowWidth/2-popupWidth/2  
	});  
	//only need force for IE6  
	jQuery("#backgroundPopup").css({  
		"height": windowHeight  
	});  
}  



