 var resizeTimer = null;
 var pic_width = 1280;
 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");	 	  	
	}
 }

/*
 function resizeOverlay(){ 	  
 
 	screenheight = ($(window).height()< $(document.body).height())? $(document.body).height() : $(window).height();
	screenwidth  = ($(window).width() < $(document.body).width())?  $(document.body).width()  : $(window).width();

	$("#infofeld").html("("+$(window).height()+" - "+$(document.body).height()+") / ("+$(window).width()+" - "+$(document.body).width()+")  ("+screenheight+"/"+screenwidth+")");

	if(screenheight > screenwidth){
		
		hf = screenheight/pic_height;
		next_width = math.round(hf*pic_width);
		
		if(next_width < screenwidth){
			screenwidth = screenwidth + 100;
	 	  	$("#box_foto").css("width",screenwidth+"px");
	 	  	$("#box_foto").css("height","");
		}else{
		  	screenheight = screenheight + 100;
	 	  	$("#box_foto").css("height",screenheight+"px");
	 	  	$("#box_foto").css("width","");
		}
	}else{
		
		wf = screenwidth/pic_width;
		next_height = wf*pic_height;
		
		if(next_height < screenheight){
		  	screenheight = screenheight + 100;
	 	  	$("#box_foto").css("height",screenheight+"px");
	 	  	$("#box_foto").css("width","");
		}else{
			screenwidth = screenwidth + 100;
	 	  	$("#box_foto").css("width",screenwidth+"px");
	 	  	$("#box_foto").css("height","");
		}
	}	

 }
*/