//****************************************
//onload="ImgZoom(this,300,300,1)"
//Author：jemen
//****************************************

function  ImgZoom(imgID,imgW,imgH){ 
//是否显示图片尺寸
var showSize=false;
if(arguments.length==4)
   if(arguments[3]) showSize=true;
if(imgW==0)
	BaseH_Zoom(imgID,imgH,showSize);
else
	if(imgH==0)
		BaseW_Zoom(imgID,imgW,showSize);
	else
	   ZoomWH(imgID,imgW,imgH,showSize);

}

////////以高度为准缩放///////
function BaseH_Zoom(imgID,imgH,showSize){  
   var image=new Image();  
   image.src=imgID.src; 
   if(image.width>0 && image.height>0)
   {
	   imgID.height=imgH;imgID.width=image.width*imgH/image.height;
	   if(showSize){
	   if(imgID.title!="")
		 imgID.title=imgID.title+"\n图片尺寸："+image.width+"×"+image.height;
	   else
		 imgID.title="图片尺寸："+image.width+"×"+image.height; 
	   }
   }
	 
} 

////////以宽度为准缩放///////
function BaseW_Zoom(imgID,imgW,showSize){  
   var image=new Image();  
   image.src=imgID.src; 
   if(image.width>0 && image.height>0)
   {
	   imgID.width=imgW;imgID.height=imgW*image.height/image.width;
	   if(showSize){
	   if(imgID.title!="")
		 imgID.title=imgID.title+"\n图片尺寸："+image.width+"×"+image.height;
	   else
		 imgID.title="图片尺寸："+image.width+"×"+image.height; 
	   }
	}
}  
 
////////按原始大小缩放/////////
function ZoomWH(imgID,imgW,imgH,showSize){
   var image=new Image();
   image.src=imgID.src; 
   if(image.width>0 && image.height>0)
   { 
      if(image.width/image.height>=imgW/imgH){  
			if(image.width>imgW)
				{imgID.width=imgW;imgID.height=image.height/image.width*imgW;}
	 		else
				{imgID.width=image.width;imgID.height=image.height;} 
	  } 
  	else
		{  
      		if(image.height>imgH)
				{imgID.height=imgH;imgID.width=image.width/image.height*imgH;}
	   		else
				{imgID.width=image.width;imgID.height=image.height;}
     	} 
	 if(showSize){
			if(imgID.title!="")
				{imgID.title=imgID.title+"\n图片尺寸："+image.width+"×"+image.height;}
			else
				{imgID.title="图片尺寸："+image.width+"×"+image.height;}
		}
	}
}