/**
 * Image preload and rollover functionality.
 *
 * @important! function must be called by onLoad event.
 *
 * @author Nicholas Pappas (nick@rightstep.org)
 * @version 1.1
 */
function rollSetup() {
  /** string added to "on" state images */
  var post = "_roll";

  /** fetch the image tag array from the DOM */
  var imgTags = document.getElementsByTagName("img");

  /** loop through the images for find appropriate preloads */
  for (i=0; i < imgTags.length; i++) {
    /** make sure there is a source defined */
    if (imgTags[i].src != '') {
      /** make sure the image tag has a class */
      tmpClass = imgTags[i].className;
      if (tmpClass) {
        /** match the image rollover class */    
        if (tmpClass.match("rollover")) {
          /** store the image source to the 'imgOut' attribute */        
          imgTags[i].imgOut = new Image();
          imgTags[i].imgOut.src = imgTags[i].src;
	
          /** pull apart the source string */
          srcLength = imgTags[i].src.length;

          srcName = imgTags[i].src.substr(0, srcLength-4);
          srcExt = imgTags[i].src.substr(srcLength-4, srcLength);

          /** store the image source to the 'imgOver' attribute */
          imgTags[i].imgOver = new Image();
          imgTags[i].imgOver.src = srcName + post + srcExt;

          /** set up the 'onmouseover' and 'onmouseout' event handlers */          
          imgTags[i].onmouseover = function() {
            this.src = this.imgOver.src;
          }
          imgTags[i].onmouseout = function() {
            this.src = this.imgOut.src;
          }
        }
      }
    }
  }
}

