// Slideshow script
//
//=====================
// author: S. Pelchat
//=====================
//
// remote global vars: 
//---------------------------------------
// playing:		boolean true when in automated slideshow mode
// loaded:		boolean used to indicate the whole page is loaded 
// collection_max:	number of collections in the page [1..n]
// collection_num:	default start collection [1..collection_max]
//
// remote functions:
//---------------------------------------
// updateDisplay( collection_num_to_display, image_num_to_display );
//
// example of collection definition, older images first:
//
// var collection1="slideshow";
// var collection1_num=0;
// var collection1_max=3;
// 
// slideshow_img1 = new Image ()
// slideshow_img1.src = "pntnef8.jpg"
// slideshow_img1.width=188
// slideshow_img1.height=250
// slideshow_caption1 =  "starship_icon.gif"
// slideshow_text1 =  "Starship #8"
//


// handle for slideshow timer
var timerid;

// callback method used by the timeout function to change the displayed image
function slideCollection()
{
if(playing == "true") {
	if(loaded == 1) {
		var current_collection_idx = "collection"+collection_num;
		var current_collection_name = eval(current_collection_idx)
		var num=eval(current_collection_idx+"_num="+current_collection_idx+"_num - 1")
		var max=eval(current_collection_idx+"_max")
		if (num < 1)
		{num=eval(current_collection_idx+"_num = " + max)}
		updateDisplay(current_collection_name,num)
		}
	timerid=setTimeout('slideCollection()',12000);
  }
}

// utility method to retrieve the play/pause button image
function getPlayPauseImg(ext) {
if( playing=="false" ) {
return "slideshow_nav_pl_"+ext+".gif";
} else {
return "slideshow_nav_pa_"+ext+".gif";
}
}

// function to start the slideshow
function playCollection()
{
if(playing == "false") {
  playing = "true";
  slideCollection();
  }
else {
  playing = "false";
}
}

// show next(older) image in collection, roll to 'max'
function nextImage()
{
playing = "false";
clearTimeout(timerid);
var current_collection_idx = "collection"+collection_num;
var current_collection_name = eval(current_collection_idx)
var num=eval(current_collection_idx+"_num="+current_collection_idx+"_num - 1")
var max=eval(current_collection_idx+"_max")
if (num<=0)
{num=eval(current_collection_idx+"_num = " + max) }
updateDisplay(current_collection_name,num)
}

// show previous(recent) image in collection, roll to '1'
function prevImage()
{
playing = "false";
clearTimeout(timerid);
var current_collection_idx = "collection"+collection_num;
var current_collection_name = eval(current_collection_idx)
var num=eval(current_collection_idx+"_num="+current_collection_idx+"_num + 1")
var max=eval(current_collection_idx+"_max")
if (num > max)
{num=eval(current_collection_idx+"_num = 1")}
updateDisplay(current_collection_name,num)
}

// show next collection in page, showing most recent image by calling nextImage
function nextCollection()
{
playing = "false";
clearTimeout(timerid);
if(loaded == 1) {
	collection_num = collection_num + 1
	if (collection_num>collection_max)
	{collection_num=1}
	eval("collection"+collection_num+"_num = 0")
	}
nextImage();
}

// show previous collection in page, showing most recent image by calling nextImage
function prevCollection()
{
playing = "false";
clearTimeout(timerid);
collection_num = collection_num - 1
if (collection_num==0)
{collection_num=collection_max}
var current_collection = eval("collection"+collection_num)
eval("collection"+collection_num+"_num = 0")
nextImage();
}

// show next collection in page, showing most recent image by calling nextImage
function gotoCollection(coll_num)
{
playing = "false";
clearTimeout(timerid);
collection_num = coll_num
if (collection_num>collection_max)
{collection_num=1}
eval("collection"+collection_num+"_num = 0")
nextImage();
}

// called by the onload event handler
function initSlideshow()
{
if(playing=="true") 
{slideCollection();}
else 
// assumes all collections image num=0
{nextImage();}
}

// helper
function linkGetter() 
{   
var msgWindow=window.open("","msg","width=400,height=400")   
msgWindow.document.write("anchors.length is " +      document.anchors.length + "<BR>")   
for (var i = 0; i < document.anchors.length; i++) {      
msgWindow.document.write("**"+document.anchors[i].name + "***" +document.anchors[i].text + "**<BR>")   
}
}

loaded = 1;

