//图片自适应大小
//id为img控件的id
//width与height为img父控件的宽高——即img的最大宽高
//示例：<img id="dd" src="ee.jpg" onload="imgFit('dd',100,200)" />"
function imgFit(imageArr,width,height)
{
	//var imageArr=document.getElementById(id);
	//if(imageArr.offsetWidth>width || imageArr.offsetHeight>height)
    //{
    //alert(imageArr.style.marginTop);
    if(!imageArr.offsetWidth){
		imageArr.style.width=width;
	}
	else
	{
	    sWidth=imageArr.offsetWidth;
	    sHeight=imageArr.offsetHeight;
	    imageRate1=parseInt(imageArr.offsetWidth)/width;
	    imageRate2=parseInt(imageArr.offsetHeight)/height;
	    if(imageRate2>imageRate1)
	    {
		    imageArr.style.height = sHeight/imageRate2+"px";
		    imageArr.style.marginLeft=(width-sWidth/imageRate2)/2+"px";
		}
	    else
	    {
	        if(imageRate1!=0)
	        {
		        imageArr.style.width = sWidth/imageRate1 +"px";
		        imageArr.style.marginTop=(height-sHeight/imageRate1)/2+"px";
		    }
		}
		} 
		//alert(imageArr.offsetWidth+":"+imageArr.offsetHeight);
    //}
}

