﻿/***************************/
//@Author: Adrian "yEnS" Mato Gondelle	
/***************************/

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

//loading popup with jQuery magic!
function loadPROFPopup(){
	//loads popup only if it is disabled
	if(PROFpopupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.8"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#loginPopUp").fadeIn("slow");
		PROFpopupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePROFPopup(){
	//disables popup only if it is enabled
	if(PROFpopupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#loginPopUp").fadeOut("slow");
		PROFpopupStatus = 0;
	}
}

//centering popup
function centerPROFPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var PROFpopupHeight = $("#loginPopUp").height();
	var PROFpopupWidth = $("#loginPopUp").width();
	//centering
	$("#loginPopUp").css({
		
		"top": windowHeight/2-PROFpopupHeight/2,
		"left": windowWidth/2-PROFpopupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#PROFPOPbutton").click(function(){
		//centering with css
		centerPROFPopup();
		//load popup
		loadPROFPopup();
		/*disablePopup();
		disablePopup2();
		disablePopup3();
		disableREGPopup();
		disableREGPopup2();
		disableREGPopup3();*/
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#loginPopUpClose").click(function(){
		disablePROFPopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePROFPopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && PROFpopupStatus==1){
			disablePROFPopup();
		}
	});

});
