 var resizeTimer = null;
 var pic_width = 1440;
 var pic_height = 960;
 var old_height;
 var old_width;

 $(window).bind('resize', function() { if (resizeTimer) clearTimeout(resizeTimer); resizeTimer = setTimeout(resizeOverlay, 10); });

 $(document).ready(function(){ 
 
 	$("#box_foto").css("position","fixed");
 	$("#box_raster").css("position","fixed");

	screenheight = ($(window).height()< $(document.body).height())? $(document.body).height() : $(window).height();
	screenwidth = ($(window).width()< $(document.body).width())? $(document.body).width() : $(window).width();

    documentheight = $(document).height();
  	$(".box_raster").css("height",documentheight+"px");			
    
	old_width  = 0;
	old_height = 0;

	if((screenheight<=old_height)&&(screenwidth<=old_width)){
	
	}else{
		hf= screenheight/pic_height;
		wf= screenwidth/pic_width; 
		
		nw= Math.round(hf*pic_width);
		nh= Math.round(wf*pic_height);
		
		distw = screenwidth-nw;
		disth = screenheight-nh;
		
		if(disth < distw){
			neww= (Math.round(wf*pic_width));	// +100
			newh= (Math.round(wf*pic_height));	// +100
		}else{
			neww= (Math.round(hf*pic_width));	// +100
			newh= (Math.round(hf*pic_height));	// +100
		}
 	  	$("#box_foto").css("width",neww+"px");
 	  	$("#box_foto").css("height",newh+"px");			
	}
 });
 
 function resizeOverlay(){ 	  
 
	clearTimeout(resizeTimer);

 	screenheight = ($(window).height()< $(document.body).height())? $(document.body).height() : $(window).height();
	screenwidth  = ($(window).width() < $(document.body).width())?  $(document.body).width()  : $(window).width();

    documentheight = $(document).height();
  	$(".box_raster").css("height",documentheight+"px");			

	old_width  = $("#box_foto").css("width");
	old_height = $("#box_foto").css("height");

	if((screenheight<=old_height)&&(screenwidth<=old_width)){
	
	}else{
		hf= screenheight/pic_height;
		wf= screenwidth/pic_width; 
		
		nw= Math.round(hf*pic_width);
		nh= Math.round(wf*pic_height);
		
		distw = screenwidth-nw;
		disth = screenheight-nh;
		
		if(disth < distw){
			neww= Math.round(wf*pic_width);
			newh= Math.round(wf*pic_height);
		}else{
			neww= Math.round(hf*pic_width);
			newh= Math.round(hf*pic_height);
		}
 	  	$("#box_foto").css("width",neww+"px");
 	  	$("#box_foto").css("height",newh+"px");	 	  	
	}
 }
 
 
 
 
 


