//window.onerror = function() {return true;}
//图片按比例缩放
function img_size(img)
{
	//获取设置尺寸		防止图片src改变width/height变化问题
	var pw=parseInt(img.offsetWidth);							//获取设置尺寸 无设置为原始尺寸
	var ph=parseInt(img.offsetHeight);						//style和css class设置的作用级别高于img 标签width/height设置
	var temp_img=new Image();
	temp_img.src=img.src;
	var img_w=parseInt(temp_img.width);			//获取原始尺寸
	var img_h=parseInt(temp_img.height);
//	img.src=temp_img.src;					//防止随机图片失效
//	alert("原始尺寸：W="+img_w+" h="+img_h+" ,设置尺寸:W="+pw+" h="+ph);
//	alert("img_w="+img_w+";pw="+pw+";img_h="+img_h+";ph="+ph);
	if(img_w>0 && img_h>0)
	{
		if (img_w<pw&&img_h<ph)
		{
			img.style.height=img_h;
			img.style.width=img_w; 
		}
		else
		{
			if(img_w/img_h>= pw/ph)
			{
				img.style.width=pw;
				img.style.height=(img_h*pw)/img_w;
			}
			else
			{
				img.style.height=ph;
				img.style.width=(img_w*ph)/img_h; 
			}
		}
	}
} 
//调用：<img src="图片" onload="img_size(this)">
//自动缩放所有图片
function img_load()
{
	var img_item=document.body.getElementsByTagName("img");
	for (i=0;i<img_item.length; i++)
	{
		if (img_item[i]!=temp_img)
		{
			img_item[i].galleryImg="no";	//取消图片快捷工具
			img_size(img_item[i]);
//			img_item[i].onload=function(){ img_size(this);};
		}
	}
}
if (window.attachEvent)	//IE
{
//	window.attachEvent("onload",img_load);
}
else
{
//	window.addEventListener("load",img_load,false);
}
//页面图片多不建议使用img_load()而是对图片使用img_size(img)
//<img src="图片地址" onload="img_size(this)">