/***************************/
//@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 popupStatusPersLogin = 0;

//loading popup with jQuery magic!
function loadPersLogin(){
	//loads popup only if it is disabled
	if(popupStatusPersLogin==0){
		$("#backgroundPersLoginOverviewPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPersLoginOverviewPopup").fadeIn("slow");
		$("#PersLogin-box").fadeIn("slow");
		popupStatusPersLogin = 1;
	}
}

//disabling popup with jQuery magic!
function disablePersLogin(){
	//disables popup only if it is enabled
	if(popupStatusPersLogin==1){
		$("#backgroundPersLoginOverviewPopup").fadeOut("slow");
		$("#PersLogin-box").fadeOut("slow");
		popupStatusPersLogin = 0;
	}
}

//centering popup
function centerPersLogin(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = $(document).height();
	var popupHeight = $("#PersLogin-box").height();
	var popupWidth = $("#PersLogin-box").width();
	//centering
	$("#PersLogin-box").css({
		"position": "absolute",
		"top": 20,//windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6

	$("#backgroundPersLoginOverviewPopup").css({
		"height": windowHeight
	});

}

//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	// URL
	var urlParameters = document.location;
	urlParameters = (urlParameters.href).split('#');

	if(urlParameters[1] != undefined && urlParameters[1] == 'PersLogin')
	{
		//hide all other popups
		disablePopupRegister();
		disablePopupOverview();
		disablePopupSucces();
		disablePersRegistrate();
		//centering with css
		centerPersLogin();
		//load popup
		disablePopup();
		
		loadPersLogin();
	}

	//LOADING POPUP
	//Click the button event!
	$(".pop-perslogin").click(function(){
		//hide all other popups
		disablePopupRegister();
		disablePopupOverview();
		disablePopupSucces();
		disablePersRegistrate();
		//centering with css
		centerPersLogin();
		//load popup
		loadPersLogin();
	});

	//CLOSING POPUP
	//Click the x event!
	$("#close-PersLogin").bind('click', function(){
		disablePersLogin();
	});
	//Click out event!
	$("#backgroundPersLoginPopup").click(function(){
		centerPersLogin();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disableeePopup();
		}
	});

});
