
function Rollover(varName, name, linkAct, helpText, width, height, xtraStates, imgsPath, fileExt) {
  this.varName  = varName;
  this.name     = name;
  this.linkAct  = linkAct;
  this.helpText = helpText;
  this.width    = width;
  this.height   = height;

  this.loadStates = ( 'out|over' + ( (typeof xtraStates == 'undefined') ? '' : '|' + xtraStates ) ).split('|');

  this.imgsPath = (typeof imgsPath == 'undefined') ? 'images/' : imgsPath;
  this.fileExt  = (typeof fileExt  == 'undefined') ? '.jpg'    : fileExt;

  this.imgLoaded  = new Array();
  for (var i = 0; i < this.loadStates.length; i++) this.imgLoaded[this.loadStates[i]] = false;

  this.doneLoading = roDoneLoading;
  this.nextPreload = roNextPreload;

  this.imageURL   = roImageURL;
  this.onMouse    = roMouseEvent;
  this.setEnabled = roSetEnabled;
  this.showImage  = roShowImage;
  this.srcHTML    = roSourceHTML;
  }

function roDoneLoading() {
  if (this.loadState != '') this.imgLoaded[this.loadState] = true;

  return (roGetNextPreloadState(this) == '');
  }

function roNextPreload() {
  this.loadState = roGetNextPreloadState(this);

  return (this.loadState == '') ? '' : this.imageURL(this.loadState);
  }

function roGetNextPreloadState(roObj) {
  var state = '';
  for (var i = 0; (i < roObj.loadStates.length) && (state == ''); i++) {
    if (!roObj.imgLoaded[roObj.loadStates[i]]) state = roObj.loadStates[i];
    }

  return state;
  }

function roImageURL(state) {
  return this.imgsPath + this.name + ((state == 'out') ? '' : '_' + state) + this.fileExt;
  }

function roMouseEvent(evt) {
  if (this.isEnabled) {
    var state = evt.type.substr(5);
    if (this.imgLoaded[state]) this.showImage(state);

    if (state == 'out') window.status = '';
                   else if (this.helpText) window.status = this.helpText;
    }
  else window.status = '';

  return true;
  }

function roSetEnabled(enable, state) {
  this.isEnabled = enable;
  document[this.name].alt = (enable) ? this.helpText : '';
  document[this.name].style.cursor = (enable) ? 'hand' : 'default';
  this.showImage(state);
  }

function roShowImage(state) {
  document[this.name].src = this.imageURL(state);
  }

function roSourceHTML(ability, state) {
  var onState = (typeof state == 'undefined') ? 'out' : state;
  var strHTML = '<img src="' + this.imageURL(onState) + '" width=' + this.width + ' height=' + this.height + ' name="' + this.name + '"';

  if (ability != 'fixed') {
    this.isEnabled = (ability != 'disabled');
    var func = '="return ' + this.varName + '.onMouse(event);"';
    var str  = '<a href="' + this.linkAct + '" onMouseOver' + func + ' onMouseOut' + func;

    if (typeof this.imgLoaded['down'] != 'undefined') str += ' onMouseDown' + func;
    if (typeof this.imgLoaded['up']   != 'undefined') str += ' onMouseUp'   + func;

    strHTML = str + ' onClick="return ' + this.varName + '.isEnabled;">' + strHTML + ' border=0';
    if (this.isEnabled && this.helpText) strHTML += ' alt="' + this.helpText + '"'
    strHTML += '></a';
    }

  this.imgLoaded[onState] = true;

  return strHTML + '>';
  }
