// Expects to see an array called "data" with:
// <img1 filename/path>,
// <caption1 text>
// <img2 filename/path>,
// <caption2 text>,
// ...
// if an image name is empty, just the text will be displayed
// along with a "hand" image.

// see http://developer.irt.org/script/244.htm
function go(url) {
    if (document.images)
        location.replace(url);
    else
        location.href = url;
}

function keyHandler(e)
{
    var pressedKey;
    if (document.all)    { e = window.event; }
    if (document.layers) { pressedKey = e.which; }
    if (document.all)    { pressedKey = e.keyCode; }
	if (pressedKey == 32 || pressedKey == 110 || pressedKey == 78)
	{
		// space, n or N = Next
		if (next <= total)
		{
			go(filename + '?' + next);
		}
	}
	else if (pressedKey == 112 || pressedKey == 80)
	{
		// p or P = Prev
		if (prev >= 1)
		{
			go(filename + '?' + prev);
		} 
	}
	else if (pressedKey == 63 && data[index].length != 0)
	{
		// ? show file name
		alert('File="' + data[index] + '"');
	}
}

document.onkeypress = keyHandler;

// based on Nicko's code!

//Get slide number from URL
var url = "" + window.location;
var num = 1;
var argstart = url.indexOf("?");
var fileend = argstart;
var filestart = url.lastIndexOf("/") + 1;	// url has forward slashes
if (argstart >= 2)
	num = url.substring(argstart + 1);
else
	fileend = url.length + 1;

// work out the name of the html file from the url
var filename = "slidesho.html";	// default
if (filestart != -1)
	filename = url.substring(filestart, fileend);

//Calc other nums
var next = num;
next++;
var prev = num;
prev--;
var total = data.length/2 ;
var index = (num - 1)*2;

//Build the dynamic HTML page
var html = '';
html += '<a href = "../index.html">Up</a> | ';
html += '<a href = "javascript:history.back()">Back</a> | ';
// prev/next links:
if (prev >= 1)
	html += '<a href="javascript:go(\'' + filename + '?' + prev + '\')">Previous</a> | ';
else
	html += 'Previous | ';
if (next <= total)
	html += '<a href="javascript:go(\'' + filename + '?' + next + '\')">Next</a>';
else
	html += 'Next';

// individual page links, 1 | 2 | 3 ...
html += '&nbsp;&nbsp; <FONT SIZE="-1">';
for (var pic = 1; pic <= total; pic++)
{
	if (pic != 1)
		html += ' | ';
	if (pic == num)
		html += '<b>' + pic + '</b>';
	else
		html += '<a href="javascript:go(\'' + filename + '?' + pic + '\')">' + pic + '</a>';
}

// the caption/text:
html += '</FONT><br><br>';
html += data[index + 1] + '<p>';
html += '<CENTER>';
if (data[index].length == 0)
{
	// no image, just text, if reqd put up a "next" img (the hand).
	if (next <= total)
		html += '<a href="javascript:go(\'' + filename + '?' + next + '\')"><IMG src="' + '../slidesho.gif' + '" BORDER=0 ALT="Next"></A><br>';
}
else
{

	// the picture, make it act like Next:
	if (next <= total)
		html += '<a href="javascript:go(\'' + filename + '?' + next + '\')"><IMG src="' + data[index] + '" BORDER=0 ALT="Next"></A><br>';
	else
		html += '<IMG src="' + data[index] + '" BORDER=0><br>';
}
html += '</CENTER>';
document.write(html);

