﻿// image: img 元素
// zoom: (true|false) 是否对图片进行缩放，缺省为true
// width/height:
//   如果只指定width，则把图片的显示宽度缩到width 范围之内；
//   如果同时指定两个参数:
//      如果zoom 为false，则强制图片的显示大小为 width(px) x height(px)；
//      如果zoom 为true，则把图片缩小到指定的 width * height 范围之内
function _missthumbnail(image, width, height, zoom) {
  // 计算原图的url 地址
  var url=image.src;
  var p1=url.lastIndexOf('.');
  if(url == '' || p1 == -1) {
    return;
  }
  if(!url.substring(p1-2, p1).match(/[_-][smol]/)) {
    return;
  }
  url=url.substring(0, p1-2) + url.substring(p1);
  image.src=url;
  image.removeAttribute('width');
  image.removeAttribute('height');
  // 显示图片的原始大小，不进行缩放
  if(zoom != null && zoom == false) {
    if(width != null) image.width=width;
    if(height != null) image.height=height;
    return;
  }
  // 把图片的宽度缩到 width 范围之内
  if(width != null && height == null) {
    if(image.width > width) {
      image.height=width*image.height/image.width;
      image.width = width;
    }
  } else if(width != null && height != null && (image.width > width || image.height > height)) {
    // 把图片缩小到指定的 width * height 范围之内
    var rWmH=image.width * height; // rWmH=>real-width * max-height
    var rHmW=image.height * width; // rHmW=>read-height * max-width
    var calWidth=width, calHeight=height;
    if(rWmH < rHmW) {
      calHeight = height;
      calWidth = height * image.width / image.height;
    } else if(rWmH > rHmW) {
      calWidth = width;
      calHeight = width * image.height / image.width;
    } else if(rWmH == rHmW) {
      calWidth = width;
      calHeight = height;
    }
    image.width=calWidth;
    image.height=calHeight;
  }
}

var flag=false;
function DrawImage(ImgD,w,h){ 
   var image=new Image();
   image.src=ImgD.src;
   if(image.width>0 && image.height>0){
    flag=true;
    if(image.width/image.height>1){
     if(image.width>w){
     ImgD.width=w;
     ImgD.height=(image.height*w)/image.width;
     }else{
     //alert(image.width);
     ImgD.width=image.width;
     ImgD.height=image.height;
     }
     //ImgD.alt=image.width+"×"+image.height;
     }
    else{
     if(image.height>h){
	  ImgD.height=h;
     ImgD.width=(image.width*h)/image.height;
     }else{
     ImgD.width=image.width;
     ImgD.height=image.height;
     }
     //ImgD.alt=image.width+"×"+image.height;
     }
    }
}

        function OnMouseOverStyle(obj)
        {
             HouseRowStyle = obj.className;
            obj.className = 'bkyellow1';
        }
        function OnMouseOutStyle(obj)
        {
            obj.className = HouseRowStyle;
            HouseRowStyle = 'bkyellow';
        }  
