/*图片自适应大小
接受参数:
img--对象\或对象id
maxW--最大宽
maxH--最大高
auto--是否无论大小，一律取最近指定最大的高宽值

返回类型:无

应用技术：
javascript

制作人：
黄若儒 Roy.Huang

注意:
1、该方法需在加载完毕时才能调用如onload="fitSize(........)"
2、若不想出现先增大然后缩小的现象，需进行设置:对象.style.display="none";
*/
function FitImage(img,maxW,maxH,auto)
{
	if(typeof(img)!='object')
		img=document.getElementById(img);
	if(img==null)
		return;
	var image=document.createElement("img");
	image.onload=function (){
		var scale=1;
		var width=this.width;
		var height=this.height;
		if(auto || width>maxW || height>maxH)
			scale=Math.min(maxW/width,maxH/height);
		width*=scale;
		height*=scale;
		img.width=width;
		img.height=height;
		img.style.display="block";
	};
	image.src=img.src;
}
