/*
	How to use this script:
	
	1. Add script tag to bottom of web page:
		<script language="javascript" type="text/javascript" src="slideshow.js"></script>
	
	2. Put "onload" event into "body" tag:
		<body onload="runSlideShow()">
	
	3. Setup "Pic[]" array either in this file or dynamically generate and add to web page.
	
	4. Put controls on the web page:
		<img name="SlideShow">
		<INPUT id="FirstButton" type="button" value="<<" onclick="gotoPic('F')" style="WIDTH: 30px">
		<INPUT id="PreviousButton" type="button" value="<" onclick="gotoPic('P')" style="WIDTH: 30px">
		<INPUT id="PausePlayButton" type="button" value="Pause" onclick="pausePlay()" style="WIDTH: 100px">
		<INPUT id="NextButton" type="button" value=">" onclick="gotoPic('N')" style="WIDTH: 30px">
		<INPUT id="LastButton" type="button" value=">>" onclick="gotoPic('L')" style="WIDTH: 30px">
*/

// Set slide show speed (milliseconds).
var slideShowSpeed = 5000;

// Duration of crossfade (seconds).
var crossFadeDuration = 3;

// Specify the image files. Can be done here or in the web page.
/*
var Pic = new Array();
Pic[0] = '1.jpg';
Pic[1] = '2.jpg';
Pic[2] = '3.jpg';
Pic[3] = '4.jpg';
Pic[4] = '5.jpg';
*/

var t;
var j = -1;
var p = Pic.length;
var play = true;

// =======================================

function runSlideShow()
{
	if (play)
	{
		j++;
		doImage();
		doTimer();
	}
}

function doImage()
{
	if (j > (p - 1))
	{
		j = 0;
	}
	if (j < 0)
	{
		j = p - 1;
	}
	
	if (document.all)
	{
		document.images.SlideShow.style.filter="blendTrans(duration=2)";
		document.images.SlideShow.style.filter="blendTrans(duration=crossFadeDuration)";
		document.images.SlideShow.filters.blendTrans.Apply();
	}
	
	document.images.SlideShow.src = Pic[j];
	
	if (document.all)
	{
		document.images.SlideShow.filters.blendTrans.Play();
	}
}

function doTimer()
{
	t = setTimeout('runSlideShow()', slideShowSpeed);
}

function stopTimer()
{
	window.clearTimeout(t);
}

function gotoPic(action)
{
	stopTimer();
	
	if (action == "F") // First
	{
		j = 0;
	}
	else if (action == "P") // Previous
	{
		j--;
	}
	else if (action == "N") // Next
	{
		j++;
	}
	else if (action == "L") // Last
	{
		j = p - 1;
	}
	
	doImage();
	
	if (play)
	{
		doTimer();
	}
}

function pausePlay()
{
	play = !play;
	
	var e = document.getElementById("PausePlayButton");
	var buttonValue;

	if (play)
	{
		buttonValue = "Pause";
		doTimer();
	}
	else
	{
		buttonValue = "Play";
		stopTimer();
	}
	
	if (e != null)
	{
		e.value = buttonValue;
	}
}
