// Copyright 2001-2002 GuideTools.com Ltd 


//Finds any object in either browser using recursion.
//Only pass the first argument, the name of the object to find.
//Returns a pointer the object if found, else an empty string.
//  MM_intFindObject('bar') returns the object
//  document.layers['foo'].document.layers['bar']

function GT_FindObject(objName,  parentObj) {
  var i,tempObj="",found=false,curObj = "";
  var NS = (navigator.appName.indexOf("Netscape") != -1);
  if (!NS && document.all) curObj = document.all[objName]; //IE4
  if (!curObj) {
    parentObj = (parentObj != null)? parentObj.document : document;
    if (parentObj[objName] != null) curObj = parentObj[objName]; //at top level
    else { //if in form
      if (parentObj.forms) for (i=0; i<parentObj.forms.length; i++) {  //search level for form object
        if (parentObj.forms[i][objName]) {
          curObj = parentObj.forms[i][objName];
          found = true; break;
      } }
      if (!found && NS && parentObj.layers && parentObj.layers.length > 0) {
        parentObj = parentObj.layers;
        for (i=0; i<parentObj.length; i++) { //else search for child layers
          tempObj = MM_intFindObject(objName,parentObj[i]); //recurse
          if (tempObj) { curObj = tempObj; break;} //if found, done
  } } } }
  return curObj;
}

// Constructs a slideshow
function GT_slideshow(theSelf, theImage) {
  // properties
  this.totalImages = 0;
  this.currentImage = 1;
  this.images = new Array();
  
  this._self = theSelf;
  this._Image = GT_FindObject(theImage);

  // methods 
  this.addImage = GT_addImage;
  this.firstImage = GT_firstImage;
  this.prevImage = GT_prevImage;
  this.nextImage = GT_nextImage;
  this.lastImage = GT_lastImage;
  this.showCurrentImage = GT_showCurrentImage;
}

function GT_showCurrentImage() {
  with (this ){
    _Image.src = images[currentImage].src;
    var e = window.event;
    if ((e)&&(e.type=='click'))
      e.cancelBubble = true;
  }    
}
    

function GT_addImage(imageSrc) {
  with (this) {
    totalImages++;
    images[totalImages] = new Image();
    images[totalImages].src = imageSrc;
  }
}

function GT_firstImage() {
  with (this) {
    currentImage = 1;
    showCurrentImage();
  }
}

function GT_prevImage() {
  with (this) {
    currentImage--;
    if (currentImage<1) currentImage=1;
    showCurrentImage();
  }
}
 
function GT_nextImage() {
  with (this) {
    currentImage++;
    if (currentImage > totalImages) currentImage = totalImages;
    showCurrentImage();
  }
}

function GT_lastImage() {
  with (this) {
    currentImage = totalImages;
    showCurrentImage();
  }
}
