var thisPhoto;
var nextPhoto;
var divElement;
var imgElement1;
var imgElement2;
var imgStyle1;
var imgStyle2;
var rotateInterval;  /* in seconds */
var transInterval;   /* in seconds */
var mouseIsOver = false;
var masterList = new Array();

function initRotator (imageList, divElemID, imgElem1ID, imgElem2ID, rot, trans) {
  /* imageList is an array of objects:
     
	 imageList[i].image		(holds an image object - added here)
	             .filename
	             .hyperlink	(where to jump to when clicked)
				 .tip			(what to show on hover)	 
  */
  
  /* create image structure for each member in database */
  var i;
  
  for (i=0; i<imageList.length; i++) {
    masterList[i] = imageList[i];
    masterList[i].image = new Image ();
  }
  
  /* itialize globals */

  thisPhoto = 0;
  imgElement1 = document.getElementById(imgElem1ID);
  imgStyle1 = imgElement1.style;
  imgElement2 = document.getElementById(imgElem2ID);
  imgStyle2 = imgElement2.style;
  divElement = document.getElementById(divElemID);

  rotateInterval = rot;
  transInterval = trans;

  /* randomly select next photo and preload it */

  nextPhoto = 1;
  preLoad (nextPhoto);

  /* schedule rotation */

  setInterval ("displayPhoto ()", rotateInterval * 1000);
}

function displayPhoto () {

  /* if next-up image is not yet loaded or if mouse is over, wait a cycle */
  if (masterList[nextPhoto].image.complete && !mouseIsOver) {
    setOpac (100); 					//  see only image 1 
 
    setImage (2, masterList[nextPhoto].image.src);	//  set image 2 to new photo (invisible)

    /* advance photo */
 
    thisPhoto = nextPhoto;

    /*  set "mouse hover" tip text */

    setTip ();

    /* schedule blend by decreasing opacity of image1 and increasing opacity of image 2  */

    for (i=0; i<=100; i+=3) {
       setTimeout ("setOpac ("+ (100-i) +")", i*10*transInterval);
    }
    /* once fadeout is complete, set images to be the same */

    funcCall = "setImage(1,\"" + masterList[nextPhoto].image.src + "\")";
    setTimeout (funcCall, transInterval * 1000 + 25); 
    setTimeout ("setOpac(100)", transInterval * 1000 + 125); 
  }

  /* preload the next image to display */
	
  nextPhoto = (nextPhoto + 1) % masterList.length;
  preLoad (nextPhoto);
}

function preLoad (index) {
   masterList[index].image.src = masterList[index].filename;
}

function jumpto() {
  if (thisPhoto < 0) return;
  parent.location = masterList[thisPhoto].hyperlink;
}

function mouseOver () {
  mouseIsOver = true;
}

function mouseOut () {
  mouseIsOver = false;
}

function setOpac (opacity) {

    imgStyle1.opacity = (opacity / 100);
    imgStyle1.MozOpacity = (opacity / 100);
    imgStyle1.KhtmlOpacity = (opacity / 100);
    imgStyle1.filter = "alpha(opacity=" + opacity + ")"; 
 
    imgStyle2.opacity = ((100 - opacity) / 100);
    imgStyle2.MozOpacity = ((100 - opacity) / 100);
    imgStyle2.KhtmlOpacity = ((100 / opacity) / 100);
    imgStyle2.filter = "alpha(opacity=" + (100 - opacity) + ")"; 
}

function setImage (image, file) {

  /*  set image */
  if (image == 1) 
     imgElement1.src = file;
  else 
     imgElement2.src = file;

  return;
}

function setTip () {

  /*  set title */
  divElement.title = masterList[thisPhoto].tip;
}


