
// BEGIN IMAGE PRELOADER
function ImagePreloader(images, callback)
{ //parameters: images is an array of URLs, callback is a function
  //store callback function
  this.callback = callback;
  
  //initialize internal state
  this.nLoaded=0;
  this.nProcessed=0;
  this.aImages= new Array;
  
  //record the number of images
  this.nImages=images.length;
  
  //for each image, call preload()
  for (var i=0;i<images.length;i++)
    this.preload(images[i]);
}

ImagePreloader.prototype.preload = function(image)
{
  //create new image object and add to array
  var oImage = new Image;
  this.aImages.push(oImage);
  
  //set up event handlers for the image object
  oImage.onload = ImagePreloader.prototype.onload;
  oImage.onerror = ImagePreloader.prototype.onerror;
  oImage.onabort = ImagePreloader.prototype.onabort;
  
  //assign pointer back to this
  oImage.oImagePreloader = this;
  oImage.bLoaded=false;
  
  //assign the src property to load the img
  oImage.src=image;
}
ImagePreloader.prototype.onComplete = function()
{
  this.nProcessed++;
  if (this.nProcessed == this.nImages)
    {
	this.callback(this.aImages, this.nLoaded);
	}
}
ImagePreloader.prototype.onload = function()
{
  this.bloaded=true;
  this.oImagePreloader.nLoaded++;
  this.oImagePreloader.onComplete()
}
ImagePreloader.prototype.onerror = function()
{
  this.bError=true;
  this.oImagePreloader.onComplete()
}
ImagePreloader.prototype.onabort = function()
{
  this.bAbort=true;
  this.oImagePreloader.onComplete()
}
// END IMAGE PRELOADER
function loadDone(imgArr, numLoaded)
{
//show table
wishlist_div = document.getElementById('wishlist');
entireTbl = wishlist_div.getElementsByTagName('table')[0];
entireTbl.style.display = 'block';
}
function hidePic()
  {
  imgDiv = document.getElementById('wish_image');
  imgDiv.style.display = 'none';
  }
function showPic(imgNum,name)
  {
  //grab references
  imgDiv = document.getElementById('wish_image');
  imgTbl = document.getElementById('w_img_tbl');
  mn = window.document.getElementById('wishlist');
  //show frame
  imgDiv.style.display = 'block';

  //destroy old image
  imgDiv.removeChild(imgDiv.getElementsByTagName('img')[0]);
  //create new image
  newimg = document.createElement('img');
  newimg.style.display = 'block';
  //find url
  newimg.src = imgArr[imgNum];
  imgDiv.appendChild(newimg);
  //Change Title
  para = imgTbl.getElementsByTagName('p')[0];
  para.lastChild.nodeValue = name;

  //move mini-window
  var ParentObject = mn.getElementsByTagName('tr')[imgNum];
  //initialize totalTop to fix final position
  var totalTop;
  totalTop=-25;
  //subtract half of image's height
  totalTop -= (newimg.height/2);
  
  while (ParentObject)
    {
	totalTop += ParentObject.offsetTop;
	ParentObject = ParentObject.offsetParent;
	}

  //If this is the open water layout in IE, we must do things differently
  isOpenWater = (document.getElementById('this_is_water'));
  usingIE = (navigator.appName == "Microsoft Internet Explorer");
  if (isOpenWater && usingIE)
	{
	imgDiv.style.top = "50px"; //for IE
	}
  else
	{
	imgDiv.style.top = totalTop + "px"; //for all other browsers
	}
  
  //set table width to image width
 imgDiv.width = newimg.width;
 imgTbl.width = imgDiv.width;
  }

