//--------------------------------------------------
//  IMAGE ROLLOVERS
//--------------------------------------------------

if(typeof(tamar_rollover_warnings) == 'undefined') {
  tamar_rollover_warnings = false;
}

tamar_rollovers = new Array();

function tamar_rollover(obj, onSrc, offSrc) {

  //if the objects already in the array, leave it
  for (var i=0; i<tamar_rollovers.length; i++) {
    if (obj == tamar_rollovers[i].obj) return
  }

  //assign image object to this object and create image objects
  this.obj     = obj;
  this.off     = new Image();
  this.off.src = offSrc || obj.src;
  this.on      = new Image();
 
  //see if an onSrc image was supplied
  if (onSrc) {
    //it was so set the mouseover image source the supplied one
    this.on.src = onSrc;
    
    //see if the on and off images supplied are the same. If they are fail. We only need to check here
    //as if an onSrc wasn't supplied we know they should take the form _on/_off
    if (this.off.src == this.on.src) {
      this.error_msg('image with tamar_rollover has the same mouseover/mouseout image');
      return;
    }
  } else {
    //a mouseover image was not supplied, so we're going to work it out
    //the original image should have the format imagename_off.ext
    //the new image will have the format imagename_on.ext
    
    //onSrc = /(\w*)_off\.(\w\w\w\w?)$/.exec(this.off.src)
    
    if (this.off.src.indexOf('_off') > -1) {
      //transforms the _off filename to be an _on filename
      newString = this.off.src.replace(/_off/i,"_on");
      this.on.src = newString;
    } else {
      //the image didn't follow the pattern imagename_off.ext
      this.error_msg('image with tamar_rollover failed to load a correct filename.\n(file should be called [name]_off.gif)');
      return;
    }
  }
  
  //check the mouseover images filesize to see if it has been loaded properly
  /*
  if (this.on.fileSize <= 0) {
    this.error_msg('image with tamar_rollover failed to load mouseover (on) image. '+this.on.src+' could not be found');
    return;
  }
  */
  if ((this.on.width != this.off.width || this.on.height != this.off.height) && tamar_rollover_warnings) {
    this.error_msg('warning: image with tamar_rollover, dimensions of rollover images don\'t match');
  }

  //assign this object (tamar_rollover) to variable so we can assign it in functions below
  var thisObject  = this;
  
  //create handlers for image that change the image
  obj.onmouseover = function() { obj.src = thisObject.on.src  }
  obj.onmouseout  = function() { obj.src = thisObject.off.src }
  
  //push this object into the rollovers array
  tamar_rollovers[tamar_rollovers.length] = this;
}

tamar_rollover.prototype.error_msg = function(message) {
  alert(message);
  this.obj.style.border = '3px solid #ff3333';
}


