
/*  codice per i popup della home page - copiato da ttmilano */

function POPup_Open() {
    $("#POPup_cover").fadeTo("slow", 0.8, function () {
        $("#POPup_contenitore").show();
    });
}

$(document).ready(function(){
	var winWidth = $(window).width();
	var winHeight  = $(window).height();

	$("#POPup_contenitore").css("top", ((winHeight) / 2) - ($("#POPup_contenitore").height() / 2));
	$("#POPup_contenitore").css("left", ((winWidth) / 2) - ($("#POPup_contenitore").width() / 2));	
	
	if (winHeight < document.body.clientHeight)
	    $("#POPup_cover").css("height", document.body.clientHeight);
	else
	    $("#POPup_cover").css("height", winHeight);
	
	if (winWidth < document.body.clientWidth)
	    $("#POPup_cover").css("width", document.body.clientWidth);
	else
	    $("#POPup_cover").css("width", winWidth);		

	$(window).resize( function() {
		winWidth = $(window).width();
		winHeight  = $(window).height();

		$("#POPup_contenitore").css("top", ((winHeight) / 2) - ($("#POPup_contenitore").height() / 2));
		$("#POPup_contenitore").css("left", ((winWidth) / 2) - ($("#POPup_contenitore").width() / 2));

		if (winHeight < document.body.clientHeight)
		    $("#POPup_cover").css("height", document.body.clientHeight);
		else
		    $("#POPup_cover").css("height", winHeight);
			
	    if (winWidth < document.body.clientWidth)
	        $("#POPup_cover").css("width", document.body.clientWidth);
	    else
	        $("#POPup_cover").css("width", winWidth);						
	});		

	$(window).scroll( function() { 
	    winHeight  = $(window).height();

	    $("#POPup_cover").css("top", document.body.scrollTop);

	    $("#POPup_contenitore").css("top", ((winHeight) / 2) - ($("#POPup_contenitore").height() / 2) + document.body.scrollTop);

	});
    
	$("#POPup_close_link").click(function () {
	    $("#POPup_contenitore").fadeTo("slow", 0, function () {
	        $("#POPup_cover").fadeTo("slow", 0);
	        $("#POPup_cover").css("display", "none");
			$("#POPup_contenitore").css("display", "none");
			$("#POPup_contenitore").remove();
			$("#POPup_cover").remove();
		});
	});
    
    POPup_Open();
});




