var dynImages = new Object();

function dynImage(id, selImgSrc, unselImgSrc)
 {
  this.id         = id;
  this.selImg     = new Image();
  this.selImg.src = selImgSrc;
  this.unselImgSrc   = unselImgSrc;
  this.imgSrc     = '';
  dynImages[id]   = this;
}

dynImage.prototype.showSelImg = function()
{
  if (!this.imgSrc)
  {
    this.imgSrc = this.img.src;
  }
  this.img.src = this.selImg.src;
}

dynImage.prototype.select = function()
{
  if (!this.selected)
  {
    for (var id in dynImages)
    {
      dynImages[id].deSelect();
    }
    this.selected = true;
  }
  this.showSelImg();
  return false;
}

dynImage.prototype.deSelect = function()
{
  this.selected = false;
  if (this.imgSrc)
  {
    this.img.src = this.unselImgSrc;
  }
}

dynImage.prototype.mouseout = function()
{
  if (!this.selected) this.deSelect();
}

dynImage.prototype.init = function()
{
  var a    = this.link = document.getElementById(this.id);
  this.img = a.getElementsByTagName('img')[0];
  a.onmouseover = function() { return dynImages[this.id].showSelImg(); }
  a.onmouseout  = function() { return dynImages[this.id].mouseout();  }
  a.onclick     = function() { return dynImages[this.id].select(); }
  a.onfocus     = function() { return dynImages[this.id].select(); }
  a.onblur      = function() {
    dynImages[this.id].deSelect();
    dynImages["text-size-s"].select();
    return;
  }

  this.selected = false;

  // Setting the default image is handled by styleswitcher.js
  //	dynImages["text-size-s"].select();
}