// JavaScript Document for Image Rollover functions:
// by Nicholas Lee (modified from the original by Macromedia Corp.)

// SHARED GLOBAL VARIABLES (These are used in this script but declared in main HTML document)
// variable "preloadFlag"

// GLOBAL VARIABLES
var currentRollover = null; // the name of the image currently rolled over

// ROLLING THE IMAGE (MOUSEOVER)
function rollImage(name, rolloverImage) {
  if(preloadFlag == true) { // PRELOADFLAG VARIABLE IS DECLARED IN MAIN HTML DOCUMENT
	var doc = document;
	if(doc[name]) var imgObj = doc[name]; // find the object and state it as the image to be changed if found

	if(doc.images && imgObj) {
	  if(!imgObj.orgsrc) imgObj.orgsrc = imgObj.src; // if original image has not been recorded as a property of the image object, do so
	  imgObj.src = rolloverImage; // replace the image
	  currentRollover = imgObj; // record the name of the current rollover so it can be restored after mouseOut
	}
  }
}

// RESTORING THE IMAGE (MOUSEOUT)
function restoreImage() {
  var doc = document;

  if(doc.images) {
    if(currentRollover && currentRollover.orgsrc) { // if there is a current rollover and original image of it is recorded:
	  currentRollover.src = currentRollover.orgsrc; // set the image back to original image
	  currentRollover = null; // reset the current rollover variable
	}
  }
}

// SWAPPING AN IMAGE WITH AN EVENT INITIATED OUTSIDE THAT IMAGE
function remoteImageSwap(name, rolloverImage) {
  var doc = document;

  if(doc.images) {
	if(doc[name]) doc[name].src = rolloverImage;
  }
}