
/**
 *  basic functions for image management which can be used for a simple 'hover' effect
 *
 *  @author   Tobias Hettinger
 *  @version  $Id: image.js,v 1.6 2009/01/16 14:24:32 tobias Exp $
 */


/**
 *  array that contains the images
 */
WATImages = new Array();


/**
 *  function to load a set of images
 *
 *  @param string imageId  id of the image
 *  @param string url1     first image url
 *  @param string url2     second image url
 *  @param string url3     third image url
 */
function watLoadImage(imageId, url1, url2, url3)
{
  //  get the array index for the new image and and initialize the new image array
  var index = WATImages.length;
  WATImages[index] = new Array(4);
  WATImages[index][0] = imageId;
  
  //  load the first image
  if (url1)
  {
    WATImages[index][1] = new Image();
    WATImages[index][1].src = url1;
  }
  else WATImages[index][1] = null;
  
  //  load the second image
  if (url2)
  {
    WATImages[index][2] = new Image();
    WATImages[index][2].src = url2;
  }
  else WATImages[index][2] = null;
  
  //  load the third image
  if (url3)
  {
    WATImages[index][3] = new Image();
    WATImages[index][3].src = url3;
  }
  else WATImages[index][3] = null;
}

/**
 *  function to check if the image with the passed id exists
 *
 *  @param string imageId  id of the image to check
 *
 *  @return bool  the function returns true if the image exists or false if the image does not exist
 */
function watImageExists(imageId)
{
  //  initialize the result
  var result = false;

  //  search the image to replace
  var imgCount = WATImages.length;
  for (var a=0; a<imgCount; a++)
    if (WATImages[a][0] == imageId)
      result = true;
  
  //  return true if the image exists or false if the image does not exist
  return result;
}

/**
 *  function to replace an image
 *
 *  @param string imageId  id of the image to replace
 *  @param int    index    index of the new image (1, 2 or 3)
 */
function watReplaceImage(imageId, index)
{
  //  search the image to replace
  var imgCount = WATImages.length;
  for (var a=0; a<imgCount; a++)
  {
    if (WATImages[a][0] == imageId)
    {
      //  search the image in the document
      var image = document.getElementById(imageId); 
      if (image)
      {
        //  replace the image if an image with the passed index is available
        if (WATImages[a][index])
        {
          image.src = WATImages[a][index].src;
        }
      }	
    }
  }	
}
