/***************************/
//@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 popupStatusRaduno = 0;

//loading popup with jQuery magic!
function loadPopupRaduno(){
	//loads popup only if it is disabled
	if(popupStatusRaduno==0){
		$("#backgroundPopupRaduno").css({
			"opacity": "0"
		});
		$("#backgroundPopupRaduno").fadeIn("slow");
		$("#popupRaduno").fadeIn("slow");
		popupStatusRaduno = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopupRaduno(){
	//disables popup only if it is enabled
	if(popupStatusRaduno==1){
		$("#backgroundPopupRaduno").fadeOut("slow");
		$("#popupRaduno").fadeOut("slow");
		popupStatusRaduno = 0;
	}
}

//centering popup
function centerPopupRaduno(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupRaduno").height();
	var popupWidth = $("#popupRaduno").width();
	//centering
	$("#popupRaduno").css({
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	

	//only need force for IE6
	
	$("#backgroundPopupRaduno").css({
		"height": windowHeight
	});
	
}


//CONTROLLING EVENTS IN jQuery
$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#popuptriggerRaduno").click(function(){
		//centering with css
		centerPopupRaduno();
		//load popup
		loadPopupRaduno();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupRadunoClose").click(function(){
		disablePopupRaduno();
	});
		$("#popupRadunoClose2").click(function(){
		disablePopupRaduno();
	});
	//Click out event!
	$("#backgroundPopupRaduno").click(function(){
		disablePopupRaduno();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatusRaduno==1){
			disablePopupRaduno();
		}
	});

});