<!-- Start hide script from older browsers.

// File BtnStuff.js
// Functions and processing of image swap buttons.

/* Inserted into the web page with something like:
<script language=JavaScript src="BtnStuff.js"> </script>
*/

/* 
This function loads images that are not loaded when the page loads.
This is done so that images are immediately available when they are
called upon; so the user doesn't need to wait for it to download.
Call with: onLoad="ImgPreload('Images/image1.jpg', 'Images/image2.jpg', ...);"
*/
function ImgPreload()
{
  // Get the number of arguments passed to this function. 
  iNumArgs=ImgPreload.arguments.length;
  // Create a global array for images within the document object.
  document.aImages = new Array();

  // Loop through the arguments passed to this function.
  for(var loop = 0; loop < iNumArgs; loop++)
  {
    // For each arg, create a new image in the global array.
    document.aImages[loop] = new Image();
    // Set the source of the image to the current argument.
    document.aImages[loop].src = ImgPreload.arguments[loop];
  }
}

/*
Creates a button object (a constructor) and writes the button to the screen.
ButtonName - Name of the object / button.
default_image - File name and location of default image (start and onMouseOut).
hilight_image - File name and location of image when mouse moves over the button.
help_msg - Alt help message for the button.
click_action - JavaScript that runs when button is clicked.
Must be called with something like:
 BtnCovLtr_obj = new MakeButtonObj("BtnCovLtr",'Images/BtnCovLtr1.jpg', 
 'Images/BtnCovLtr2.jpg','Cover Letter','goNewPage("CovLtr.htm");');
*/
function MakeButtonObj(ButtonName, default_image, hilight_image, help_msg, click_action)
{
  var image_name = ButtonName + "_image";
  var obj_name = ButtonName + "_obj";

  /*
  Write out the HTML. Because of this, this function cannot be called after
  the document is loaded. This puts the image on the screen with the
  events assigned to the image. Just as if it was done in HTML in the 
  body of the HTML.
  */
  document.write("<a href='#' ");
  document.write("onMouseOver='" + obj_name + ".makeHighlight();' ");
  document.write("onMouseOut ='" + obj_name + ".makeDefault();' ");
  document.write("onClick='" + obj_name + ".doClick(); return false;' >");
  document.write("<img src='" + default_image + "' ");
  document.write(" name='" + image_name + "' border='0'");
  document.write(" alt='" + help_msg + "'></a><p>");
//  document.write(" name='" + image_name + "' border='0' width='122' height='35'");

  // Assign properties to the object.
  this.default_image = default_image;
  this.hilight_image = hilight_image;
  this.click_action = click_action;
  this.image_name = image_name;

  // Assign methods (or pointers to the functions).
  this.makeHighlight = makeHighlight;
  this.makeDefault = makeDefault;
  this.doClick = doClick;
} // End function MakeButtonObj

/*
Called when onMouseOver of the button.
This function is a method of the objects created in this document so 
"this" applies to the object used in the call.
Must be called with somethig like:
 onMouseOut = obj_name.makeDefault();
The calls to this function are written out in function MakeButtonObj.
*/
function makeDefault()
{
  var the_image = eval("window.document." + this.image_name);
  the_image.src = this.default_image;
}
// End function makeDefault

/*
Called when onMouseOut the button.
This function is a method of the objects created in this document so 
"this" applies to the object used in the call.
Must be called with somethig like:
 onMouseOver = obj_name.makeHighlight();
The calls to this function are written out in function MakeButtonObj.
*/
function makeHighlight()
{
  var the_image = eval("window.document." + this.image_name);
  the_image.src = this.hilight_image;
}
// End function makeHighlight

/*
Called when the button is clicked.
This function is a method of the objects created in this document so 
"this" applies to the object used in the call.
*/
function doClick()
{
  eval(this.click_action);
}
// End function doClick

function goNewPage(sNewUrl)
{
  if (sNewUrl != "")
  {
    window.location.href=sNewUrl
  }
  else
  {
    return false;
  }
}
// End function goNewPage

// End hide script from older browsers. -->
