/* 画像サイズ調整クラス */
var AdjustImage = Class.create();
AdjustImage.prototype = {
  max : 0,
  realWidth : null,//元の幅を保持
  realHeight : null,//元の高さを保持

  initialize : function(max){
    this.max = max;
  },

  //maxより横幅が大きければ幅に合わせて縮小する。小さければそのまま
  adjustImageWidth : function(imgObj){
    var width = imgObj.width;
    var height = imgObj.height;

    if(this.realWidth == null){
      this.realWidth = width;
    }

    if(this.realHeight == null){
      this.realHeight = height;
    }

    if(width > this.max){
      imgObj.removeAttribute("width");
      imgObj.removeAttribute("height");
      imgObj.style.width = this.max + "px";
    }
  },

  //maxより縦横どちらかが大きければ幅に合わせて縮小する。小さければそのまま
  adjustImage : function(imgObj){
    var width = imgObj.width;
    var height = imgObj.height;

    if(this.realWidth == null){
      this.realWidth = width;
    }

    if(this.realHeight == null){
      this.realHeight = height;
    }

    if(height >= width && height > this.max){
      //縦長で縦がはみでる
      imgObj.removeAttribute("width");
      imgObj.removeAttribute("height");
      imgObj.style.height = this.max + "px";
    } else if(width >= height && width > this.max){
      //横長で横がはみでる
      imgObj.removeAttribute("width");
      imgObj.removeAttribute("height");
      imgObj.style.width = this.max + "px";
    }
  }
}


///////////////////////////////////////////////////////////////////

function showImg(imgElement, maxVal){
  new AdjustImage(maxVal).adjustImage(imgElement);
  imgElement.style.visibility = "visible";
}