/*按比例生成缩略图*/
function DrawImage(MyPic,W,H){
  var flag=false;
  var image=new Image();
  image.src=MyPic.src;
  if(image.width>0 && image.height>0){
    flag=true;
    if(image.width/image.height>= W/H){
      if(image.width>W){  
        MyPic.width=W;
        MyPic.height=(image.height*W)/image.width;
      }
	  else{
        MyPic.width=image.width;  
        MyPic.height=image.height;
      }
    }
    else{
      if(image.height>H){  
        MyPic.height=H;
        MyPic.width=(image.width*H)/image.height;     
      }
	  else{
        MyPic.width=image.width;  
        MyPic.height=image.height;
      }
    }
  }
} 
/** 让图片垂直居中。使用前提：当前图片必须被包含在div中
      * ImgD：原图
      * maxWidth：允许的最大宽度(即包含本图片的div的父节点对象的宽度，一般是li)
      * maxHeight：允许的最大高度
      */
function centerImage(imgD, maxWidth, maxHeight){
		var div = imgD.parentNode;//获取包含本图片的div
		if(imgD.height < maxHeight){
				var top = (maxHeight - imgD.height) / 2;
				div.style.marginTop = top + "px";
		}
		if (document.all){
		}
		else{
			if(imgD.width < maxWidth){
					var left = (maxWidth - imgD.width) / 2;
					div.style.marginLeft = left + "px";
			}	
		}
}
