// JavaScript Document

//This script counts the thumbnail images, blocks displays of contents of div's label p1, p2, ...
//It enables the display of the div with the page number p'n' corresponding to Show(n)
//The thumbnail corresponding to 'n' also is highlighted in a darker border.

var running;      //is slideshow running?
var count=0;      //slideshow image counter    

function Display( n) {          //display big image
	if(!document.getElementById || !document.getElementsByTagName) return false;    //quit if javascript not DOM capable
	var x=document.getElementById('tnails').getElementsByTagName("img");
	for(i=1; i<x.length+1; i++)
	  if (i==n) document.getElementById('p'+n).style.display = "block"  //display selected photograph
	  else document.getElementById('p'+i).style.display = "none";       //hide all others 
	for (var i=0;i<x.length;i++)  
	  if(i!=(n-1)) x[i].style.borderColor="#EEEEEE";  //make colored border same color as background
	x[n-1].style.borderColor="#6666FF";               //put blue border around selected thumbnail
}

function Show(j) {  //a thumbnail was clicked, stop slideshow if running, and display image
    if(!document.getElementById || !document.getElementsByTagName) return false;    //quit if javascript not DOM capable
	pauseShow();    //stop slideshow
	count=parseInt(j);        //restart slideshow at clicked image
	Display(j);	
}

function runShow() { 
    if(!document.getElementById || !document.getElementsByTagName) return false;    //quit if javascript not DOM capable
	var thumbcount=	x=document.getElementById('tnails').getElementsByTagName("img").length; //count thumbnail images	
	document.getElementById('run_btn').style.display="none";
	document.getElementById('pause_btn').style.display="block";
	if (count<thumbcount)
	  {Display(count+1); count++;
	   running=setTimeout("runShow()",5000);   //iterate every five seconds  
	  }  //note that images run from 1 to thumbcount plus 1
	else
	  {count=0; pauseShow();}         //halt show	
}

function pauseShow() {
	if(!document.getElementById || !document.getElementsByTagName) return false;    //quit if javascript not DOM capable
	if (running) clearTimeout(running);
	document.getElementById('run_btn').style.display="block";
	document.getElementById('pause_btn').style.display="none";
}

//window.onload=function()       //call the show function to set the first display
//{Show('1');}