// JavaScript Document
function CaricaFoto(img,maxwidth,maxheight){
 var foto1;
 foto1 = new Image();
 foto1.src=(img);
 Controlla(foto1,img,maxwidth,maxheight);
}
function Controlla(foto1,img,maxwidth,maxheight){
//	var foto1 = new Image();	
	if((foto1.width!=0)&&(foto1.height!=0)){
	   viewFoto(foto1,img,maxwidth,maxheight);
	}
	else{
    funzione="Controlla('"+img+"')";
    intervallo=setTimeout(funzione,20);
  }
}

/////////////////////////////////
//function viewFoto(foto1,img,maxwidth,maxheight){
//	var foto1;
//	foto1 = new Image();
/*	var	width = foto1.width;
	var	height = foto1.height;
	
	if (((maxwidth && width) > maxwidth) || ((maxheight && height) > maxheight)){
		if ((maxwidth && width) > maxwidth){
			widthratio = maxwidth/width;
			RESIZEWIDTH=true;
		}
		if ((maxheight && height) > maxheight){
			heightratio = maxheight/height;
			RESIZEHEIGHT=true;
		}
		if ((RESIZEWIDTH) && (RESIZEHEIGHT)){
			if(widthratio < heightratio){
				ratio = widthratio;
			}else{
				ratio = heightratio;
			}
		}else {
			if(RESIZEWIDTH){
			ratio = widthratio;
			}
			if(RESIZEHEIGHT){
			ratio = heightratio;
			}
		}
    	newwidth = width * ratio;
        newheight = height * ratio;
	 	string="width="+newwidth+" height="+newheight;
		this.document.write("<IMG SRC='"+img+"' BORDER='0'"+ string +" >");
	}
}
//  End --> */
function viewFoto(foto1,img,maxwidth,maxheight){
	var	width = foto1.width;
	var	height = foto1.height;
	var ratio;
	if ((width > maxwidth) || (height > maxheight)){
		if (width > maxwidth){
			widthratio = maxwidth/width;
			RESIZEWIDTH=true;
		}else{
			widthratio = width/maxwidth;
			RESIZEWIDTH=true;
		}
		if (height > maxheight){
			heightratio = maxheight/height;
			RESIZEHEIGHT=true;
		}else{
			heightratio = height/maxheight;
			RESIZEHEIGHT=true;
		}
		if ((RESIZEWIDTH) && (RESIZEHEIGHT)){
			if(widthratio < heightratio){
				ratio = widthratio;
			}else{
				ratio = heightratio;
			}
		}else {
			if(RESIZEWIDTH){
			ratio = widthratio;
			}
			if(RESIZEHEIGHT){
			ratio = heightratio;
			}
		}

		newwidth = width * ratio;
        newheight = height * ratio;

		}else{
			newwidth = width;
			newheight = height;
		}
	 	string="width="+newwidth+" height="+newheight;
		this.document.write("<IMG SRC='"+img+"' BORDER='0'"+ string +" >");
//	}
}
