﻿//图片按比例缩放
function img_size(img)
{
	var w=img.getAttribute("w");
	var h=img.getAttribute("h");
	if (img.getAttribute("w")==null||img.getAttribute("h")==null)
	{
		w=img.width;
		h=img.height;
		img.setAttribute("w",w);
		img.setAttribute("h",h);
	}
	var image=new Image();
	image.src=img.src;
	if (img_w==0 || img_h==0)
	{
		var img_w=image.width;
		var img_h=image.height;
		if(img_w>0 && img_h>0)
		{
			if (img_w>w||img_h>h)
			{
				if(img_w/img_h>= w/h)
				{
					img.width=w;
					img.height=(img_h*w)/img_w;
				}
				else
				{
					img.height=h;
					img.width=(img_w*h)/img_h; 
				}
			}
			else
			{
				img.height=img_h;
				img.width=img_w; 
			}
		}
		else
		{
			img.src="images/null.gif";
			img.alt="this images address error";
			return false;
		}
	}
} 
//调用：<img src="图片" onload="img_size(this)">
//全部图片缩放
function img_load()
{
	var img_item=document.getElementsByTagName("img");
	for (i=0;i<img_item.length; i++)
	{
		img_size(img_item[i]);
		img_item[i].onload=function(){img_size(this)};
	}
}
/*
var tempFunc = window.onload;
window.onload = function()
{
	if (typeof(tempFunc) == "function")
	{
		try
		{
			tempFunc();
		}
		catch (e){}
	}
	img_load();
}
*/