//----------------------------------------------------------
// Copyright - Gallaware, Inc. 2000
// All rights reserved
// These JavaScript functions are copyrighted by Gallaware, Inc.
// They can not be used, copied, altered, edited, or included 
// with or within any software, or published or distributed without
// the expressed written consent of Gallaware, Inc.
//----------------------------------------------------------

// Image processing utilities
//
// Functions included:
//  imageStartSwap()
//  swapImage()
//  changeImage()
//  imageAdd()
//  imageInfo()
//  addToPreload()
//  preloadAllImages()
//  preloadImage()
//  imageLinkEx()

// global variables
var preImageArray = new Array()
var imageArray = new Array()
var imageIdx

var imagecont = true

function imageStartSwap(dtime,cont)
{
  imageIdx = 0
  if (cont != null)
    imagecont = cont

  if (imageArray.length > 0)
    setTimeout(imageSwap, dtime)
}

function swapImage(name, src)
{
  eval("document." + name + ".src='" + src + "'")
}

function imageSwap()
{
 if (imageIdx < imageArray.length)
  {
    swapImage(imageArray[imageIdx].iname, imageArray[imageIdx].src)
    imageIdx++
  }

  if (imageIdx < imageArray.length)
    setTimeout(imageSwap, imageArray[imageIdx].dtime)
  else if (imagecont)
  {
    imageIdx = 0
    setTimeout(imageSwap, imageArray[imageIdx].dtime)
  }
}

function changeImage(imgobject, src)
{
  imgobject.src = src
}

function imageAdd(name, src, dtime)
{
  if (imageArray == null)
    imageArray = new Array()

  imageArray[imageArray.length] = new imageInfo(name, src, dtime)
}

// This function is the imageInfo object.  It is used to hold information about an image
// without having that image load into memory.  Using the JavaScript Image object would
// load the image into memory as soon as the 'src' attribute is set.  This object allows
// the loading to be put off until later in the loading of the page.
// param - name The name of the image
// param - src The URL of the source of the image
// param - ht The height of the image
// param - wd The width of the image
// param - alt The alternate text of the image

function imageInfo(name, src, dtime, ht, wd, alt)
{
  this.iname = name
  this.src = src
  this.dtime = dtime
  this.height = ht
  this.width = wd
  this.alt = alt
}

// This function adds image information to an array.  This array is then used
// with the 'preloadAllImages()' function.  This function should be used in the 'onLoad' 
// for the body.
// param - imgname The image name
// param - src The URL to the image
// param - ht The height of the image
// param - wd The width of the image
// param - alt The alternate text for the image

function addToPreload(imgname, src, ht, wd, alt)
{
  preImageArray[preImageArray.length] = new imageInfo(imgname, src, 0, ht, wd, alt)
}

// preloads an images that reside in the 'preImageArray' into memory.  
// This function should be used in the 'onLoad' event of the body tag.

function preloadAllImages()
{
  var idx
  var image

  for (idx = 0; idx < preImageArray.length; idx++)
    preloadImage(preImageArray[idx].src, preImageArray[idx].height, preImageArray[idx].width)
}

// preloads an image into memory.  Allows 'rollover' images to perform the rollover faster
// param - src The URL of the image
var imageArray_x = new Array()
function preloadImage(src, ht, wd)
{
  var image

  if (ht != null && wd != null)
  {
    if (ht > 0 && wd > 0)
      image = new Image(wd, ht)
    else
      image = new Image()
  }
  else
    image = new Image()

  image.src = src
  imageArray_x[imageArray_x.length] = image
}

//
// This function creates an HREF with an image.  It optionally allows the image
// to be rolled over using the mouseOver and mouseOut HREF attributes.  When a 
// rollover image is used, the second image is placed into an array.  This array
// does not 'pre-load' the images right away.  So, you will need to call preloadAllImages()
// after the page has loaded to make the second images load faster.
// param - name The name of the IMAGE which is referenced in the href
// param - link The URL of the HREF
// param - img1 The initial image to show in the link
// param - img2 If present, the image to show for the mouseOver
// param - ht The height of the image
// param - wd The width of the image
// param - alt The ALTernate text to display

function imageLinkEx(name, link,img1,img2,ht,wd,alt, target)
{
  document.write("<a href=\"", link, "\"")
  if (img2.length > 1)
  {
    document.write(" onMouseover='changeImage(",name, ",\"", img2, "\")' onMouseout='changeImage(", name, ",\"", img1 ,"\"")
    addToPreload(name, img2, ht, wd, alt)    

    document.write(")' ")
  }

  if (target != null && target.length > 0)
    document.write(" target=\"", target, "\"")

  document.write("><img border='0' name='", name, "' src='", img1, "' ")

  if (wd > 0)
    document.write(" width='", wd, "' ")

  if (ht > 0)
    document.write(" height='", ht, "' ")

  document.write(" alt='", alt, "'></A>")
}

