function pageLoad()
{
  // add behaviors
  addThumbClickBehaviors();
  
  // select first image and 'click' it
  var firstImg = document.getElementById('thumblist').getElementsByTagName("IMG")[0];
  xDOM.dispatchClickEvent(firstImg);
}

function thumbClick(evt)
{
  // get event
  var target = xDOM.getEventTarget(evt);

  // remove 'highlighted' classname from all thumbs
  var thumbs = target.parentNode.getElementsByTagName("IMG");
  for(var i = 0; i < thumbs.length; i++)
    thumbs[i].className = "";

  // add 'highlighted' classname to target
  target.className = "highlighted";
  
	// get image name
	var imgName = getImageNameFromThumbName(target.src);

	// find img tag set src
	var img = document.getElementById('galleryImage');
	img.src = imgName;
	img.alt = imgName;
}

/* add click behaviors */
function addThumbClickBehaviors()
{
 	var x = document.getElementById('thumblist');
	if (!x) return;
	for (var i = 0; i < x.childNodes.length; i++)
	{
	    var node = x.childNodes[i];
	    if (node.tagName == 'IMG')
	    {
        xDOM.addEventHandler(node, "click", thumbClick, false);
        xDOM.addEventHandler(node, "keypress", thumbClick, false);
      }	    
	}
}

/* strips thbumnail suffix from image name */
function getImageNameFromThumbName(name)
{
	var dotPos = name.lastIndexOf('.');
	var ext = name.substring(dotPos, name.length);
	var imageName = name.substr(0, dotPos-2) + ext;
	//alert(imageName);
	return imageName;
}
