﻿/* this script requires a global hash named 'imgHashPreloaded'
 * each selected image should be stored under same key defined in the targeted img name attribute
 * that hash can be obtained with the preload function.
 */

function preload(imgNames, gfxPath, gfxPostfix){

  var imgHashPreloaded = new Object();

  for (var i = 0; i < imgNames.length; ++i){
    var newImg = new Image();
    newImg.src = gfxPath + imgNames[i] + gfxPostfix;
    imgHashPreloaded[imgNames[i]] = newImg;
  }
      
  return imgHashPreloaded;
}


/*
 * @param imgName the name-attr value of the img-tag to change
 */
function over(imgName){
  if (document.images){
    var imgSrcOld = document.images[imgName].src;
    document.images[imgName].src = imgHashPreloaded[imgName].src
    imgHashPreloaded[imgName].src = imgSrcOld;
  }
}

function out(imgName){
  if (document.images)
    over(imgName);
}