var plArr = new Array();
var plArrCnt = 0;

function PrintResizedPicture(url,MaxX,MaxY){
	var Img = new Image();
	Img.src = url;
	propX = MaxX/Img.width;;
	propY = MaxY/Img.height;
	if (propX > propY){
		prop = MaxY/Img.height;
	}else{
		prop = MaxX/Img.width;
	}
	width = Math.round(Img.width*prop);
	height = Math.round(Img.height*prop);
	document.write("<img src='"+url+"' width='"+width+"' height='"+height+"'>");
}

function imgOnError(Img,MaxX,MaxY){
	Img.width = MaxX;
	Img.height= MaxY;
}

function ResizePicture(Img,MaxX,MaxY){
	if (typeof(Img) != 'object') {
		Img = plArr[Img];
	}

 	if (Img.width == 0){
 		if (!(lc = Img.getAttribute('loadCount'))) {
 			lc = 0;
 		} else {
			lc ++;
 		}
// 		alert('zero width = '+lc);
 		Img.setAttribute('loadCount',lc);
 		if (lc == 10) {
 			Img.width = MaxX;
 			return;
 		}
		plArr[plArrCnt] = Img;
// 		window.setTimeout(ResizePicture(Img,MaxX,MaxY), 300);
//		window.setTimeout("ResizePicture("+plArrCnt+","+MaxX+","+MaxY+")", 300);
		window.setTimeout(function() {ResizePicture(Img,MaxX,MaxY)}, 300);
		plArrCnt++;
   	return;
 		width = MaxX;
 		height = MaxY;
 	}else{
 		propX = MaxX/Img.width;
 		propY = MaxY/Img.height;
//  		alert("MaxX:"+MaxX+";Img.width:"+Img.width+";propX:"+propX);
 		if (propX > propY){
 			prop = MaxY/Img.height;
 		}else{
 			prop = MaxX/Img.width;
 		}
 		width = Math.round(Img.width*prop);
 		height = Math.round(Img.height*prop);
 	}
 	Img.width = width;
 	Img.height = height;
}


function ResizePictureNotMore(Img,MaxX,MaxY){
	propX = MaxX/Img.width;;
	propY = MaxY/Img.height;
	if (propX > propY){
		prop = MaxY/Img.height;
	}else{
		prop = MaxX/Img.width;
	}
	width = Math.round(Img.width*prop);
	height = Math.round(Img.height*prop);
	if(Img.width>width || Img.height>height){
		Img.width = width;
		Img.height = height;
	}
}

