/*
**
** The JavaScript code used here was derived from a tutorial on this site:
** http://www.quirksmode.org/js/newmouseover.html
**
*/
var photosPath = "Images/Photos/";
var thumbnailsPath = "Images/Thumbnails/";

function isIE5OrGreater()
{
if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion >= "4.0")
  return true;
if (navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion < "4.0")
  return false;
if (navigator.appName == "Netscape" && navigator.appVersion >= "4.0")
  return false
if (navigator.appName == "Netscape" && navigator.appVersion < "4.0")
  return false;
if (navigator.appName != "Microsoft Internet Explorer" && navigator.appName != "Netscape")
  return false
}

function initializeGallery()
{
  var preloads = new Object();
  for (i=0;i<aItemData.length;i++)
  {
    var img = document.getElementById("img"+i);
    if (img)
    {
      var aIndividualItem = aItemData[i];
      img.src = thumbnailsPath + aIndividualItem[4];
		  preloads['n'+img.id] = new Image;
		  preloads['n'+img.id].src = thumbnailsPath + aIndividualItem[4];
		  preloads['o'+img.id] = new Image;		  
		  preloads['o'+img.id].src = thumbnailsPath + aIndividualItem[5];
		  preloads['o'+img.id].onerror = function () {this.src='Images/Photos/default.gif'}
		  preloads['l'+img.id] = new String(aIndividualItem[0]);
		  img.onmouseover = function () {this.src=preloads['o'+this.id].src;}
		  img.onmouseout = function () {this.src=preloads['n'+this.id].src;}
		  img.onclick = function () {displayItem(preloads['l'+this.id]);}
    }
  }
}

function displayItem(item)
{
  if (item == "") return;
	  
	// reset rollover functions for thumbnails before turning the selected one 'on'
	initializeGallery();
  
  // get an array of the thumbnails
  if (document.getElementById) {
		var x = document.getElementById('main_l').getElementsByTagName('IMG');
	} else if (document.all) {
		var x = document.all['main_l'].all.tags('IMG');
  } else {
	  return;
	}
  
  // find the selected item and display it
  var aIndividualItem;
  for (i in aItemData)
  {  
    aIndividualItem = aItemData[i];
    if (aIndividualItem[0].toUpperCase() == item.toUpperCase())
    {    
      // set the selected item's thumbnail to "on"
      x[i].src = thumbnailsPath + aIndividualItem[5];
      x[i].onmouseover = function () {}
		  x[i].onmouseout = function () {}

      // display the selected item and its attributes
      var div = document.getElementById("main_r");
      var artImg = document.getElementById("artImg");
      var artDesc = document.getElementById("artDesc");
      
      // fade if Internet Explorer
      if (isIE5OrGreater())
        div.filters[0].Apply();

      artImg.src = photosPath + aIndividualItem[0];
      artImg.width = aIndividualItem[1];
      artImg.height = aIndividualItem[2];
      artDesc.innerHTML = aIndividualItem[3];
      
      // fade if Internet Explorer
      if (isIE5OrGreater())
        div.filters[0].Play();
      
      break;
    }
  }
}