function impostaSize()
{
    img = $('#background');
    
    if (img) {
		img.width('');
		img.height('');
		img.css('top', 0);
		img.css('left', 0);
		
		
		win = $(window);
		img_p = img.width() / img.height();
		win_p = win.width() / win.height();
		
		
		if ( img_p > win_p )
		{
		  img.height(win.height());
		}
		else
		{
		  img.width(win.width());
		}
	
		if (img.is('.hidden')) $(img.fadeIn());
	
	}

	t = setTimeout("impostaSize()",300);

}

	


   function sfondo() {
   
   $('#bg_container').css('display','none');

   $('#bg_container').html("<img src=\"/img/ajax-loader.gif\" alt=\"Caricamento in corso\" id=\"carica_bg\" />");
   
   $('#carica_bg').css('position','absolute');
   $('#carica_bg').css('left',($(window).width()/2)-110);
   $('#carica_bg').css('top',($(window).height()/2));
   
   $('#bg_container').css('display','block');
   
   
   	var preLoad;
	
	preLoad = new Image()
	preLoad.src = img_background;
	
   
	$('#bg_container').html("<img id='background' style='display:none' name='SlideShow' src='" + img_background + "' alt='' />").show('fast',
	function() {
				
			$('#background').load(function() {
			impostaSize();
			$('#background').css('display','block');
			});
				
	});
   

   
 
 
    
    }
	
	var isprivacyopen = 0;
	var iscopyrightopen = 0;
	
	$(document).ready(function() {
		
		$('#privacy').click(function(e) {
		
		var mousex = e.pageX;
		var mousey = e.pageY;
		var posizioni = $("#privacy .overlay").offset();

		if (mousex < posizioni.left || mousey < posizioni.top || 
			mousex > posizioni.left+$('#privacy .overlay').width() ||
			mousey > posizioni.top+$('#privacy .overlay').height()
			)
		{	
			
			isprivacyopen = 0;
			$(this).fadeOut();

		}
	});
	
		$('#copyright').click(function(e) {
		
		var mousex = e.pageX;
		var mousey = e.pageY;
		var posizioni = $("#copyright .overlay").offset();

		if (mousex < posizioni.left || mousey < posizioni.top || 
			mousex > posizioni.left+$('#copyright .overlay').width() ||
			mousey > posizioni.top+$('#copyright .overlay').height()
			)
		{	
			
			iscopyrightopen = 0;
			$(this).fadeOut();

		}
	});
	
		
	});
	
   function top_privacy() {

	   $("#privacy").width($(document).width());
	   $("#privacy").height($(document).height());

   }
   
   function top_copyright() {
	   $("#copyright").width($(document).width());
	   $("#copyright").height($(document).height());

   }
    
   $(window).scroll(top_privacy);
   $(window).scroll(top_copyright);
   $(window).resize(top_privacy);
   $(window).resize(top_copyright);

   $(document).ready(sfondo);
   $(window).resize(impostaSize);


