/*
 ImgRoll
*/

function ImgRoll(stub, onIns, offIns, clickIns)
{ 
  if(stub != null)
  {
    this.links = new Array();
    this.images = new Array();
    this.imgIdx = new Array();
    this.stub = stub;
    
    this.isSet = false;

    this.onIns = onIns;
    this.offIns = offIns;
    this.clickIns = clickIns;

    this.onrollon = null;
    this.onrolloff = null;
    this.onclick = null;
  }
}
new ImgRoll(null, null, null, null);

ImgRoll.prototype.add = function(baseName, ext, jsImgName)
/*
 ext: no . needed
*/
{
  this.images[jsImgName] = new Object();
  this.imgIdx[this.imgIdx.length] = this.images[jsImgName];
  
  this.images[jsImgName].jsImgName = jsImgName;
  this.images[jsImgName].status = 'off';
  
  this.images[jsImgName].off = new Image();
  this.images[jsImgName].off.src = 
   (this.stub + baseName + this.offIns + "." + ext);

  this.images[jsImgName].on = new Image();
  this.images[jsImgName].on.src = 
   (this.stub + baseName + this.onIns + "." + ext);  
  
  if (this.clickIns != null)
  {
    this.images[jsImgName].click = new Image();
    this.images[jsImgName].click.src = 
     (this.stub + baseName + this.clickIns + "." + ext);  
  }
}


ImgRoll.prototype.over = function(image)
{
  var osImage;
  if (osImage = this.images[image.name])
  {
    image.src = osImage.on.src;
    osImage.status = 'on';
    
    if (this.onrollon != null)
    {
      this.onrollon();
    }
  }
}
ImgRoll.prototype.out = function(image)
{
  var osImage;
  if (osImage = this.images[image.name])
  {
    image.src = osImage.off.src;
    osImage.status = 'off';
    
    if (this.onrolloff != null)
    {
      this.onrolloff();
    }
  }
}

ImgRoll.prototype.click = function(image)
{
  var osImage;
  if (osImage = this.images[image.name])
  {
    image.src = osImage.click.src;
    osImage.status = 'clicked';
    
    if (this.onclick != null)
    {
      this.onclick();
    }
  }
}

/* Use element ID instead */
ImgRoll.prototype.overId = function(id)
{
  var osImage, image;
  
  if (!document.getElementById)
  {
    return;
  }
  image = document.getElementById(id);
  
  if (osImage = this.images[id])
  {
    image.src = osImage.on.src;
    osImage.status = 'on';
    
    if (this.onrollon != null)
    {
      this.onrollon();
    }
  }
}
ImgRoll.prototype.outId = function(id)
{
  var osImage, image;
  
  if (!document.getElementById)
  {
    return;
  }
  image = document.getElementById(id);
  
  if (osImage = this.images[id])
  {
    image.src = osImage.off.src;
    osImage.status = 'off';
    
    if (this.onrolloff != null)
    {
      this.onrolloff();
    }
  }
}

ImgRoll.prototype.clickId = function(id)
{
  var osImage, image;
  
  if (!document.getElementById)
  {
    return;
  }
  image = document.getElementById(id);
  
  if (osImage = this.images[id])
  {
    image.src = osImage.click.src;
    osImage.status = 'clicked';
    
    if (this.onclick != null)
    {
      this.onclick();
    }
  }
}

