// Image Rollovers
// An alternate to using the recommended CSS functionality
// when the latter is not a possibility for some reason.

// The JavaScript remembers the original image URL, and thus a file
// does not need to be passed unless you're rolling out to an image
// that is different from the one originally loaded.

var oldImages = new Array();
var imgPath   = 'http://www.stevewilkos.com/images/'; // a path to the images if all the same (else blank)

function imageSwap(imgName, newImage, setPath) {

  if( newImage != undefined && newImage != null ) {
  // Store the old image for when it needs to be reverted
  var oldImageParts  = new Array();

    oldImageURL        = document.getElementsByName(imgName)[0].src;
    oldImageParts      = oldImageURL.split('/');
    oldImages[imgName] = oldImageParts[oldImageParts.length - 1];

  } else {
  // Set the image to be loaded to the old (original) value
    if( oldImages[imgName] != undefined ) {
      newImage = oldImages[imgName];
    } else {
      // Not enough data to work with
      return false;
    }
  }

  // Swap the path if requested
  imgPath = (setPath != undefined) ? setPath : imgPath;

  // Swap the image with another
  document.getElementsByName(imgName)[0].src = imgPath + newImage;

} // ! imageSwap function
