    // Image Flipping script
    // Author:   June 13, 1997 - Casey Barton (casey@e-commerce.com)
    // Modified: Aug  22, 1997 - Velimir Otovic (votovic@e-commerce.com)
    //           Oct  15, 1997 - Mike Hesler (mchesler@uwaterloo.ca)
    // Copyright e-Commerce Inc, 1997
    // Based loosely on Jamie Zawinski (jwz@netscape.com)'s home page script.
    //
    // Usage:
    //   - Include both <!SCRIPT> blocks into the
    //     <HEAD> block of your page.
    //
    //   - Insert the attribute 
    //        onLoad="do_preload()"
    //     into the <BODY> tag
    //
    //   - Each relevant <A><IMG> block should resemble
    //        <!A HREF="nextpage.html" onMouseOver="turn_on('imgToHighlight','othrImgToReplace')" onMouseOut="turn_of ('highlightedImg','othrImg')">
    //        <!IMG SRC="next1.gif" NAME="imgToHighlight" BORDER=0>
    //        <!IMG SRC="next2.gif" NAME="othrImgToReplace" BORDER=0>
    //        
    //     where 'next1.gif' is the name of the default (unhighlighted) image to be replaced,
    //     'next2.gif' is the name of an image that is also replaced
    //
    //   - The highlighted image is then assumed to be named 'nextXa.gif'
    //     (the image name with an appended 'a'), to be found in the
    //     same directory as the default image.
    //   - An image named 'nextXb.gif' will be used to replace the other image
    //     (the image name with an appended 'b'), to be found in the 
    //     same directory as the default image.
    var prefetched = new Array;
    var imgSrcArray = new Array;
    var donePreload = false;
    // Figure out the src attribute of the
    // highlighted counterpart of an image
    function highlight_src(imgSrc) {
        if ( imgSrc != null && imgSrc != 'undefined') {
            // Just add an 'a' to the image name
            return imgSrc.substring(0, imgSrc.length - 4) +
                   'a' +
                   imgSrc.substring(imgSrc.length - 4);
        } else
            return null;
    }
    // Figure out the src attribute of the
    // reference counterpart of an image
    function reference_src(imgSrc) {
        if ( imgSrc != null && imgSrc != 'undefined') {
            // Just add an 'b' to the image name
            return imgSrc.substring(0, imgSrc.length - 4) +
                   'b' +
                   imgSrc.substring(imgSrc.length - 4);
        } else
            return null;
    }
    // Get an image into memory
    function preload_image(imgSrc, width, height) {
        if ( imgSrc != null && imgSrc != 'undefined') {
            var i = prefetched.length;
	    var name = highlight_src(imgSrc);
            prefetched[i] = new Image(width, height);
            prefetched[i].src = name;
            i = i + 1;
            name = reference_src(imgSrc);
	    prefetched[i] = new Image(width, height);
	    prefetched[i].src = name;
        }
    }
    // Find and preload all necessary highlighted images
    function do_preload() {
        for (var i in document.images) 
	  {
            if (i != 'length' && isNaN(parseInt('' + i))) 
		{
			var imgStr = document.images[i].src;
            	imgSrcArray[i] = document.images[i].src;
            	preload_image(imgSrcArray[i], document.images[i].width, document.images[i].height);
            }
        }
        donePreload = true;
    }
    // Flip to the highlighted image
    function turn_on(srcReplace) {
        if (donePreload && (document.images[srcReplace] != null) && imgSrcArray[srcReplace] != null)
		{
                document.images[srcReplace].src = highlight_src(imgSrcArray[srcReplace]);
		}
    }
    // Flip to the highlighted image
    function turn_ref(srcReplace, refReplace) {
        if (donePreload && (document.images[srcReplace] != null) && (document.images[refReplace] != null) && (imgSrcArray[srcReplace] != null) )
		{
		document.images[refReplace].src = reference_src(imgSrcArray[srcReplace]);
		}
    }
    // Flip (back) to the regular image
    function turn_off(imgName) {        
        if (donePreload && (document.images[imgName] != null) && (imgSrcArray[imgName] != null) )
	    {
		var imgStr = imgSrcArray[imgName];
		if (imgStr != null)
		    document.images[imgName].src = imgStr ;
	    }
    }
