// This file contains Javascript code to support cross-browser slide shows.  Both
// continuous loop and manual slide shows are supported.  The slide shows require 
// a target image with id=imageID, surrounded by a div tag with id=divID and 
// style="background-image".  The list of files in the show are passed in a single
// string, separated by semicolons.  The primary functions are as follows:
//
//   continuousSlideShow() -- Call function as the body tag's onLoad event hander 
//                            to initiate a continuous loop slide show.
//   startSlideShow() -- Call function as the body tag's onLoad event hander 
//                            to initiate a manual slide show. 
//   firstSlide() -- In a manual slide show, link to this method to display the first
//                   slide in the slide show.
//   previousSlide() -- In a manual slide show, link to this method to display the
//                      previous slide in the slide show.
//   nextSlide() -- In a manual slide show, link to this method to display the next
//                  slide in the slide show.
//   lastSlide() -- In a manual slide show, link to this method to display the last
//                  slide in the slide show.
// Note that these methods do NOT pre-load the images into a cache.  Only the filenames
// are pre-loaded.  31 Mar 2005  rk


var slideCache = new Array();    // cache of image filenames
var slideNum = 0;                // number of current slide in show
var blendTime = 500;             // milliseconds for blend transition 
// var timeoutID;


function continuousSlideShow(divID, imageID, imageFiles, seconds) {
// Function starts a continuous loop slide show.  Seconds specifies the interval between slides.
  startSlideShow(divID,imageID,imageFiles);
  setTimeout("slideLoop('" + divID + "','" + imageID + "'," + (seconds * 1000) + ");", seconds * 1000); 
} // continuous slide show


function pauseSlideShow() {
// Function pauses a continuous slide slide by cancelling the time out.
//  clearTimeout(timeoutID);
} // pause slide show


function slideLoop(divID, imageID, milliseconds) {
// Function implements the continuous loop portition of a looping slide show.
  nextSlide(divID, imageID, blendTime);
  setTimeout("slideLoop('" + divID + "','" + imageID + "'," + milliseconds + ");", milliseconds); 
} // slide loop


function startSlideShow(divID, imageID, imageFiles) {
// Function starts a slide show.
  slideCache = imageFiles.split(";");
  window.document.getElementById(imageID).src = slideCache[0];
} // start slide show


function nextSlide(divID, imageID, milliseconds) {
// Function replaces the current image with the next one in the slide show.
  slideNum++;
  if (slideNum > slideCache.length-1) { slideNum = 0; }
  blendImage(divID, imageID, slideCache[slideNum], milliseconds);
} // next slide


function previousSlide(divID, imageID, milliseconds) {
// Function replaces the current image with the previous one in the slide show.
  slideNum--;
  if (slideNum < 0) { slideNum = slideCache.length-1; }
  blendImage(divID, imageID, slideCache[slideNum], milliseconds);
} // previous slide


function firstSlide(divID, imageID, milliseconds) {
// Function replaces the current image with the first one in the slide show.
  slideNum = 0;
  blendImage(divID, imageID, slideCache[slideNum], milliseconds);
} // first slide


function lastSlide(divID, imageID, milliseconds) {
// Function replaces the current image with the last one in the slide show.
  slideNum = slideCache.length-1;
  blendImage(divID, imageID, slideCache[slideNum], milliseconds);
} // last slide


function changeOpacity(opacity, imageID) {
// Function changes the opacity of the image with id=imageID to opacity 
// where an opacity of 0 is transparent and 100 is opaque.
var object = document.getElementById(imageID).style;
  object.opacity = opacity / 100;
  object.MozOpacity = opacity / 100;
  object.KhtmlOpacity = opacity / 100;
  object.filter = "alpha(opacity=" + opacity + ")";
} // change opacity


function blendImage(divID, imageID, imageFilename, milliseconds) {
// Functions fades out the current image with id=imageID and fades in a new image
// from the file named imageFilename in its place.  To accomplish this the function
// (1) copies the current image in imageID to a background image in divID; (2)
// sets the opacity of imageID to transparent; (3) copies imageFilename to
// imageID; and (4) fades imageID from transparent to opaque.
var speed = Math.round(milliseconds/100);
  document.getElementById(divID).style.backgroundImage = "url(" + document.getElementById(imageID).src + ")";
  changeOpacity(0, imageID);
  document.getElementById(imageID).src = imageFilename;
  for (i = 0; i <= 100; i++) {
    setTimeout("changeOpacity(" + i + ",'" + imageID + "')",i*speed);
  } 
} // blend image


function launchSlideShow(url, width, height) {
// Function opens a custom window and launches a new window for the slide show.  14 Apr 2006  rk
  var newWindow = window.open( url, '', 'height='+height+', resizable=no, status=no, titlebar=no, width='+width);
  newWindow.focus();
} // launch next rad





