/*
@desc:图片等比缩放
i:要缩放的图片
fw:要缩放到的宽度
fh:要缩放到的高度
f:追加父容器
s:样式
*/
function autoScaleImg(i,fw,fh,f,s){
	if(i){
		var o=new Image(),w=fw||i.width,h=fh||i.height;
		o.src=i.src;
		if(o.width>0 && o.height>0){
			if(o.width/o.height>= w/h){
				if(o.width>w){
					i.width=w;
					i.height=(o.height*w)/o.width
				}else{
					i.width=o.width; 
					i.height=o.height
				}
			} else{
				if(o.height>h){
					i.height=h;
					i.width=(o.width*h)/o.height
				}else{
					i.width=o.width; 
					i.height=o.height
				} 
			}
	     }
	     drawImage(i,w,h,f,s);
     }
 }
 
 function drawImage(s,w,h,f,c){
 	if(f)
	{ 		
		var e=document.createElement('div');
	 	e.style.cssText="display:block;padding:0;margin:0 auto auto 0;width:"+w+'px;height:'+h+'px;text-align:center;'+c;
	 	s.parentNode.replaceChild(e, s);
	 	e.appendChild(s);
 	}
	else
	{
 	  s.style.marginTop=(h-s.height>0?h-s.height:0)+'px';
 		s.parentNode.style.visibility='visible';
 	}
 	s.style.visibility='visible';
 }



 function DisImg(ImgD, iwidth, iheight) {
    //参数(图片,允许的宽度,允许的高度) 
    var image = new Image();
    image.src = ImgD.src;
    if (image.width > 0 && image.height > 0) {
        if (image.width / image.height >= iwidth / iheight) {
            if (image.width > iwidth) {
                ImgD.width = iwidth;
                ImgD.height = (image.height * iwidth) / image.width;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
            ImgD.alt = image.width + "×" + image.height;
        }
        else {
            if (image.height > iheight) {
                ImgD.height = iheight;
                ImgD.width = (image.width * iheight) / image.height;
            } else {
                ImgD.width = image.width;
                ImgD.height = image.height;
            }
            ImgD.alt = image.width + "×" + image.height;
        }
    }
} 
