

function setThumbDiv(idt) {
  g_thmbid = idt;
}

//--------------------------------------------------
// constructor
//   create a new img if new image nameis given
//
function ScaledImage(idt) {
  this.divThumb = document.getElementById(idt);

  this.imgThumb = null;
  this.prevImg = "";
}

new ScaledImage("");
function doScaleD() {
  alert("*DDDDD");
}
//--------------------------------------------------
// setImage
//   create a new img if new image nameis given
//
ScaledImage.prototype.setImage=function(sNewImage) {

 if (sNewImage != this.prevImg) {
   //    var td = document.getElementById(g_thmbid);
    var tp = this.divThumb.firstChild;
    if (tp) {
	this.divThumb.removeChild(tp);
    }
    //    alert("Setting "+sNewImage);
    this.imgThumb = document.createElement("img");
    /////  this.imgThumb.style.visibility="hidden";
    this.imgThumb.style.position="absolute";
    this.imgThumb.src=sNewImage;
    this.divThumb.appendChild(this.imgThumb);
    this.prevImg = sNewImage;


    // IE doesn't do img.onload ...
    var browserName=navigator.appName;
    if (browserName=="Microsoft Internet Explorer") {
      doScale(this.imgThumb);
    } else {
     this.imgThumb.onload=doScale;
    }

  }
}

//--------------------------------------------------
// doScale - callback for img.onLoad
//   "this" refers to imgThumb
//
//ScaledImage.prototype.doScale = function() {
function doScale(ii) {

  var browserName=navigator.appName;
  if (browserName=="Microsoft Internet Explorer") {
  } else {
    ii=this;
  }

  wC = ii.parentNode.offsetWidth;
  hC = ii.parentNode.offsetHeight;
  //  this.width=0;
  //  this.height=0;

  // image size & aspect
  wI = ii.offsetWidth;
  hI = ii.offsetHeight;
  fI = (1.0*wI)/hI;
  //  alert("image: "+wI+"x"+hI+" -> "+fI);

  // container size & aspect
  wC = ii.parentNode.offsetWidth;
  hC = ii.parentNode.offsetHeight;
  fC = (1.0*wC)/hC;
  //  alert("container("+this.parentNode.id+"): "+wI+"x"+hI+" -> "+fI);

  // determine scale
  if (fC > fI) {
    wS = hC*fI;
    hS = hC;
  } else {
    wS = wC;
    hS = wC/fI;
  }

  //  alert("scaled: "+wS+"x"+hS);
  ii.width = wS;
  ii.height = hS;
 
  
  sStyle = "position:absolute; " +
             "width:"+wS+"px; " + 
             "height:"+hS+"px; " +
             "left:"+((wC-ii.width)/2)+"px; " +
             "top:"+((hC-ii.height)/2)+"px; " +
             "visibility:visible;";
  ii.style.cssText=sStyle;
}

ScaledImage.prototype.hide=function() {
  if (this.imgThumb) {
    this.imgThumb.style.visibility="hidden";
  }
}
ScaledImage.prototype.show=function() {
  if (this.imgThumb) {
    this.imgThumb.style.visibility="visible";
  }
}

ScaledImage.prototype.displayData=function() {
  if (this.imgThumb) {
    alert("si size:"+this.imgThumb.width+"x"+this.imgThumb.height);
  }
}

