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

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

//disabling popup with jQuery magic!
function disablePersRegistrate(){
	//disables popup only if it is enabled
	if(popupStatusPersRegistrate==1){
		$("#backgroundPersRegistrateOverviewPopup").fadeOut("slow");
		$("#PersRegistrate-box").fadeOut("slow");
		popupStatusPersRegistrate = 0;
	}
}

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

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

}

function runPopupRegister()
{
	//hide all other popups
	disablePopupRegister();
	disablePopupOverview();
	disablePopupSucces();
	disablePersLogin();
	//centering with css
	centerPersRegistrate();
	//load popup
	disablePopup();
	
	loadPersRegistrate();
}

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

	if(urlParameters[1] != undefined && urlParameters[1] == 'PersRegistrate')
	{
		runPopupRegister()
	}

	//LOADING POPUP
	//Click the button event!
	$(".pop-persregistrate").click(function(){
		runPopupRegister()
	});

	//CLOSING POPUP
	//Click the x event!
	$("#close-PersRegistrate").click(function(){
		disablePersRegistrate();
	});
	//Click out event!
	$("#backgroundPersregistratePopup").click(function(){
		centerPersRegistrate();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disableeePopup();
		}
	});

});
