$(document).ready(function(){
	
	centerPopup();
	
	$('#backgroundPopUp').click(function(){
		disablePopup();
	});
	
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});	
});

// 1 = on , 0 = off ...
var popupStatus = 0;

function enablePopup(data){
	if(popupStatus==0){
		$('#backgroundPopUp').css({'opacity' : '0.7'});
		$('#backgroundPopUp').fadeIn('slow');
		if(data){
			$('#popup').html(data).fadeIn('slow');	
		} else {
			$('#popup').fadeIn('slow');	
		}			
		popupStatus = 1;
	}
}

function disablePopup(){
	if(popupStatus==1){
		$('#backgroundPopUp').fadeOut('slow');
		$('#popup').fadeOut('slow');
		popupStatus = 0;
	}
}

function centerPopup(){
	var windowWidth  = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $('#popup').height();
	var popupWidth = $('#popup').width();
	
	$('#popup').css({
		'position' : 'absolute',   
		'top'   : windowHeight / 12 -  popupHeight / 6,
		'left' :  windowWidth / 2.20 - popupWidth / 2 
	});
}
