/*
 * base.js
 * k. walters
 * kennethwalters@lostghost.com
 */


// added by Greg Bray to allow for slideshow to be paused
var pauseSlideShow = 0;
function setPause() {
	pauseSlideShow=1;
}

function clearPause() {
	pauseSlideShow=0;
}
// end added part

// Browser Slide-Show script.
// With image cross fade effect for those browsers that support it.
// Script copyright (C) 2004 www.cryer.co.uk.
// Script is free to use provided this copyright header is included.
var slideCache = new Array();
function RunSlideShow(pictureName,imageFiles,displaySecs,listLength,pictureCaption,imageCaptionList)
{

//alert(" ------ "+imageCaptionList);

  if (pauseSlideShow == 0){
	  //$("#debug").html( $("#debug").html() + 'in RunSlideshow:' + imageFiles + '<br>');
      if (manualPictures[pictureName] == null) {
//    	  imageFiles = imageFiles;
      } else {
    	  imageFiles = manualPictures[pictureName];
 	  }
      if (manualPictures[pictureCaption] == null) {
//    	  imageFiles = imageFiles;
      } else {
    	  imageCaptionList = manualPictures[pictureCaption];
 	  }

//--- add separators
	  var imageSeparator = imageFiles.indexOf(";");
	  var captionSeparator = imageCaptionList.indexOf(";");

	  
//--- determine next	  
	  var nextImage = imageFiles.substring(0,imageSeparator);
	  var nextCaption = imageCaptionList.substring(0,captionSeparator);
		
	  if (document.all)
	  {
	    document.getElementById(pictureName).style.filter="blendTrans(duration=2)";
	    document.getElementById(pictureName).filters.blendTrans.Apply();
	  }
	  document.getElementById(pictureName).src = nextImage;
	  document.imageForm.imageCaption.value = nextCaption;
	 // alert(nextImage);

	  if (document.all)
	  {
	    document.getElementById(pictureName).filters.blendTrans.Play();
	  }

	  var futureImages = imageFiles.substring(imageSeparator+1,imageFiles.length)
	    + ';' + nextImage;
	  var futureCaption = imageCaptionList.substring(captionSeparator+1,imageCaptionList.length)
	    + ';' + nextCaption;
	
//		alert (futureImages);
// sets array for manual forward button to start in same order
	  manualPictures[pictureName] = futureImages;
	  manualPictures[pictureCaption] = futureCaption;

	  // create a list of images in reverse order for use by previous button	
	  reversePictureList = "";
	  reverseCaptionList = "";
	  tempList = imageFiles + ';flag';
	  tempCaption = imageCaptionList + ';flag';
	  x = 1;
	  while (tempList.indexOf(";") != -1){
	  	imageSeparator = tempList.indexOf(";");
		captionSeparator = tempCaption.indexOf(";");
		if (x == 1) {
			reversePictureList = tempList.substring(0,imageSeparator);
			reverseCaptionList = tempCaption.substring(0,captionSeparator);
		}else{
			reversePictureList = tempList.substring(0,imageSeparator) + ';' + reversePictureList;
			reverseCaptionList = tempCaption.substring(0,captionSeparator) + ';' + reverseCaptionList;
		}
		tempList = tempList.substring(imageSeparator+1,tempList.length);
		tempCaption = tempCaption.substring(captionSeparator+1,tempCaption.length);
		x++;
	  }
	  reversePictures[pictureName] = reversePictureList;
	  reversePictures[pictureCaption] = reverseCaptionList;

// show next picture
slideshowTimerID = setTimeout("RunSlideShow('"+pictureName+"','"+futureImages+"','"+displaySecs+"','"+listLength+"','"+pictureCaption+"','"+futureCaption+"')",	displaySecs*1000);
	 
	  // Cache the next image to improve performance.
	  imageSeparator = futureImages.indexOf(";");
	  nextImage = futureImages.substring(0,imageSeparator);
	  if (slideCache[nextImage] == null) {
	    slideCache[nextImage] = new Image;
	    slideCache[nextImage].src = nextImage;
	  }
 } // end if pauseslideshow  
	
}


// Manual Slide-Show script. With image cross fade effect for those browsers
// that support it.
// Script copyright (C) 2004 www.cryer.co.uk.
// Script is free to use provided this copyright header is included.  pictureName,imageFiles,pictureCaption,imageCaptionList
var manualPictures = new Array();
function NextImageSlide(pictureName,imageFiles,listLength,pictureCaption,imageCaptionList)				
{
  // Ensure picture list primed.
  if (manualPictures[pictureName] == null) {
    manualPictures[pictureName] = imageFiles;
	manualPictures[pictureCaption] = imageCaptionList;
  } else {
    imageFiles = manualPictures[pictureName];
	imageCaptionList = manualPictures[pictureCaption];
  }
  var imageSeparator = imageFiles.indexOf(";");
  var captionSeparator = imageCaptionList.indexOf(";");
  
  var nextImage = imageFiles.substring(0,imageSeparator);
  var nextCaption = imageCaptionList.substring(0,captionSeparator);
  
  if (document.all)
  {
    // removed to remove fade on manual pic changes - document.getElementById(pictureName).style.filter="blendTrans(duration=2)";
    // removed to remove fade on manual pic changes - document.getElementById(pictureName).filters.blendTrans.Apply();
  }
  document.getElementById(pictureName).src = nextImage;
  document.imageForm.imageCaption.value = nextCaption;
  
  if (document.all)
  {
   // removed to remove fade on manual pic changes -  document.getElementById(pictureName).filters.blendTrans.Play();
  }
  manualPictures[pictureName] = imageFiles.substring(imageSeparator+1,imageFiles.length)
    + ';' + nextImage;
  manualPictures[pictureCaption] = imageCaptionList.substring(captionSeparator+1,imageCaptionList.length)
    + ';' + nextCaption;
   
  // create a list of images in reverse order for use by previous button	
	  reversePictureList = "";
	  reverseCaptionList = "";
	  tempList = imageFiles + ';flag';
	  tempCaption = imageCaptionList + ';flag';
	  x = 1;
	  while (tempList.indexOf(";") != -1){
	  	imageSeparator = tempList.indexOf(";");
		captionSeparator = tempCaption.indexOf(";");
		if (x == 1) {
			reversePictureList = tempList.substring(0,imageSeparator);
			reverseCaptionList = tempCaption.substring(0,captionSeparator);
		}else{
			reversePictureList = tempList.substring(0,imageSeparator) + ';' + reversePictureList;
			reverseCaptionList = tempCaption.substring(0,captionSeparator) + ';' + reverseCaptionList;
		}
		tempList = tempList.substring(imageSeparator+1,tempList.length);
		tempCaption = tempCaption.substring(captionSeparator+1,tempCaption.length);
		x++;
	  }
	  reversePictures[pictureName] = reversePictureList;
	  reversePictures[pictureCaption] = reverseCaptionList;

}

// Manual Slide-Show script. With image cross fade effect for those browsers
// that support it.
// Script copyright (C) 2004 www.cryer.co.uk.
// Script is free to use provided this copyright header is included.

// Adapted by Greg Bray to allow for back button instead of forward button
var reversePictures = new Array();
function PreviousImageSlide(pictureName,imageFiles,listLength,pictureCaption,imageCaptionList)
{ 
  // Ensure picture list primed.
  if (reversePictures[pictureName] == null) {
    reversePictures[pictureName] = imageFiles;
	reversePictures[pictureCaption] = imageCaptionList;
  } else {
    imageFiles = reversePictures[pictureName];
	imageCaptionList = reversePictures[pictureCaption];
	listLength = listLength - 1;
  }
  var imageSeparator = imageFiles.indexOf(";");
  var captionSeparator = imageCaptionList.indexOf(";");
  
  var nextImage = imageFiles.substring(0,imageSeparator);
  var nextCaption = imageCaptionList.substring(0,captionSeparator);
  
  if (document.all)
  {
    // removed to remove fade on manual pic changes - document.getElementById(pictureName).style.filter="blendTrans(duration=2)";
    // removed to remove fade on manual pic changes - document.getElementById(pictureName).filters.blendTrans.Apply();
  }
  document.getElementById(pictureName).src = nextImage;
  document.imageForm.imageCaption.value = nextCaption;  
  
  if (document.all)
  {
    // removed to remove fade on manual pic changes - document.getElementById(pictureName).filters.blendTrans.Play();
  }
  reversePictures[pictureName] =
    imageFiles.substring(imageSeparator+1,imageFiles.length)
    + ';' + nextImage;
  reversePictures[pictureCaption] = imageCaptionList.substring(captionSeparator+1,imageCaptionList.length)
    + ';' + nextCaption;
  
  /// create a list of images in reverse order for use by previous button	
	  reversePictureList = "";
	  reverseCaptionList = "";
	  tempList = imageFiles + ';flag';
	  tempCaption = imageCaptionList + ';flag';
	  x = 1;
	  while (tempList.indexOf(";") != -1){
	  	imageSeparator = tempList.indexOf(";");
		captionSeparator = tempCaption.indexOf(";");
		if (x == 1) {
			reversePictureList = tempList.substring(0,imageSeparator);
			reverseCaptionList = tempCaption.substring(0,captionSeparator);
		}else{
			reversePictureList = tempList.substring(0,imageSeparator) + ';' + reversePictureList;
			reverseCaptionList = tempCaption.substring(0,captionSeparator) + ';' + reverseCaptionList;
		}
		tempList = tempList.substring(imageSeparator+1,tempList.length);
		tempCaption = tempCaption.substring(captionSeparator+1,tempCaption.length);
		x++;
	  }
	  manualPictures[pictureName] = reversePictureList;
	  manualPictures[pictureCaption] = reverseCaptionList;
}

