$(document).ready(	
function()
{
	/* PopUp */
	$('#popup-mask').click(function () { $('#popup #chiudi').click(); });
	$('#popup #chiudi').hide().click(function () { closePopUp(); });
});

/* PopUp */
function loadPopUp(url, data)
{
	$('#popup #chiudi').hide().click(function () { closePopUp(); });

	//Get the screen height and width  
	var maskHeight = $(document).height();  
	var maskWidth = $(window).width();  

	//Set height and width to mask to fill up the whole screen  
	$('#popup-mask').css({'width':maskWidth,'height':maskHeight});  
	  
	//transition effect   
	$('#popup-mask').fadeTo("fast",0.7);    

	//Get the window height and width  
	var winH = $(window).height();
	var winW = $(window).width();  
	        
	//Set the popup window to center  
	$('#popup').css('top',  winH/2-$('#popup').height()/2);
	$('#popup').css('left', winW/2-$('#popup').width()/2);
	
	loadingPopUp();
	$("#popup").show();
	if (url == '')
	{
		$('#contentAjax').html(data);
		posPopUp();
	}
	else $('#contentAjax').load(url+"?a", function() { posPopUp(); });

}

function posPopUp()
{
	var winH = $(window).height();
	var winW = $(window).width();
	newwidth = $('#contentAjax .content').width()>300?$('#contentAjax .content').width():300;
	newheight = $('#contentAjax .content').height();

	$('#popup').animate( {width: newwidth, height: newheight, left: (winW/2)-(newwidth/2), top: (winH/2)-(newheight/2) }, 600, "easeInOutCirc", function() { $('#popup #chiudi').show() });
}
function loadingPopUp()
{
	$('#popup #contentAjax').css("height", "100%");
	$('#popup #contentAjax').html("<div style='text-align:center; padding-top:20%'><img src='"+baseurl+"lib/img/site/loader.gif'><"+"/div>");
}
function closePopUp()
{
	$('#popup #contentAjax').html("");
	$('#popup-mask').fadeOut("fast");
	$('#popup').hide();
	$('#popup #chiudi').hide()
}
