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(){ setPictureHeight(); setTimeout('setRasterHeight()',500); });
 
function resizeOverlay(){ clearTimeout(resizeTimer); setPictureHeight(); setTimeout('setRasterHeight()',500); }
 
function setRasterHeight(){ documentheight = $(document).height(); $(".box_raster").css("height",documentheight+"px"); }
 
function setPictureHeight(){
 	$("#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();
    
	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");			
	}
} 
