// JavaScript Document
/***************************/
//@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 popupStatuszz = 8888;
//loading popup with jQuery magic!
function loadPopupzz(){
	//loads popup only if it is disabled
	if(popupStatuszz==8888){
		$("#elfeljthatter").css({
			"opacity": "0.6"
		});
		$("#elfeljthatter").fadeIn("slow");
		$("#elfelejtett").fadeIn("slow");
		popupStatuszz = 9999;
	}
}
//disabling popup with jQuery magic!
function disablePopupzz(){
	//disables popup only if it is enabled
	if(popupStatuszz==9999){
		$("#elfeljthatter").fadeOut("slow");
		$("#elfelejtett").fadeOut("slow");
		popupStatuszz = 8888;
	}
}
//centering popup
function centerPopupzz(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#elfelejtett").height();
	var popupWidth = $("#elfelejtett").width();
	//centering
	$("#elfelejtett").css({
		"position": "absolute",
		"top": 50,
		"left": 320
	});
	//only need force for IE6
	$("#elfeljthatter").css({
		"height": windowHeight
	});
}
//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	//LOADING POPUP
	//Click the button event!
	$("#elf").click(function(){
		//centering with css
		centerPopupzz();
		//load popup
		loadPopupzz();
	});				
	//CLOSING POPUP
	//Click the x event!
	$("#elfelejt").click(function(){
		disablePopupzz();
	});
	//Click out event!
	$("#elfeljthatter").click(function(){
		disablePopupzz();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatuszz==9999){
			disablePopupzz();
		}
	});
});