<!-- Original:  Martin Webb (martin@irt.org) -->

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
function right(e) {
if (navigator.appName == 'Netscape' &&
(e.which == 3 || e.which == 2))
return false;
else if (navigator.appName == 'Microsoft Internet Explorer' &&
(event.button == 2 || event.button == 3)) {
alert("Sorry, you do not have permission to right click.");
return false;
}
return true;
}

document.onmousedown=right;
document.onmouseup=right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
if (document.layers) window.captureEvents(Event.MOUSEUP);
window.onmousedown=right;
window.onmouseup=right;
//  End -->

var index = document.location.search;
index = index.slice(1);

function next() {
	
	var newGroupIndex;
	var newPositionIndex;
	var newImageIndex;
	var groupAndPosition = getGroupAndPosition(index);
	var groupIndex = groupAndPosition[0];
	var positionIndex = groupAndPosition[1];
	if ( positionIndex == myImageGroups[groupIndex].contents.length - 1 ) {
		if ( groupIndex == 0 ) {
			newGroupIndex = myImageGroups.length - 1;
		}
		else {
			newGroupIndex = groupIndex - 1;
		}
		newPositionIndex = 0;
	}
	else {
		newPositionIndex = positionIndex + 1;
		newGroupIndex = groupIndex;
	}
	newImageIndex = myImageGroups[newGroupIndex].contents[newPositionIndex];
	//window.alert("newGroupIndex = " + newGroupIndex + "\nnewPositionIndex = " + newPositionIndex + "\nnewImageIndex = " + newImageIndex);
	document.location.search = "?" + newImageIndex;

}

function previous() {

	var newGroupIndex;
	var newPositionIndex;
	var newImageIndex;
	var groupAndPosition = getGroupAndPosition(index);
	var groupIndex = groupAndPosition[0];
	var positionIndex = groupAndPosition[1];
	if ( positionIndex == 0 ) {
		if ( groupIndex == myImageGroups.length - 1 ) {
			newGroupIndex = 0;
		}
		else {
			newGroupIndex = groupIndex + 1;
		}
		newPositionIndex = myImageGroups[newGroupIndex].contents.length - 1;
	}
	else {
		newPositionIndex = positionIndex - 1;
		newGroupIndex = groupIndex;
	}
	newImageIndex = myImageGroups[newGroupIndex].contents[newPositionIndex];
	//window.alert("newGroupIndex = " + newGroupIndex + "\nnewPositionIndex = " + newPositionIndex + "\nnewImageIndex = " + newImageIndex);
	document.location.search = "?" + newImageIndex;
}

function getGroupAndPosition(imageIndex) {

	var groupAndPosition = new Array();
	for ( var i=0; i < (myImageGroups.length ); i++ ) {
		for ( var j=0; j < (myImageGroups[i].contents.length ); j++ ) {
			if ( myImageGroups[i].contents[j] == imageIndex ) {
				groupAndPosition[0] = i;
				groupAndPosition[1] = j;
			}
		}
	}
	//window.alert(groupAndPosition[0] + " " + groupAndPosition[1] );
	return groupAndPosition;

}

function renderThumbnails() {

		for ( var i = (myImageGroups.length - 1); i > -1; i-- ) {
			document.write('<tr valign="middle">');
			document.write('<td align="center" class="cva">' + myImageGroups[i].text + '</td>');
			document.write('</tr>');
			document.write('<tr>');
			document.write('<td align="center">');
			document.write('<table width="500">');
			document.write('<tr valign="middle">');
			for ( var j = 0; j < myImageGroups[i].contents.length; j++ ) {
				document.write('<td align="center"><a href="image_viewer.htm?' + myImageGroups[i].contents[j] + '"><img nosave border=0 src="' + myImages[myImageGroups[i].contents[j]].thumbnail + '"></a></td>');
			}
			document.write('</tr>');
			document.write('</table>');
			document.write('</td>');
			document.write('</tr>');
			document.write('<tr valign="middle">');
			document.write('<td align="center" class="cva">' + myImageGroups[i].text2 + '</td>');
			document.write('</tr>');
			document.write('<tr valign="middle">');
			document.write('<td align="center" class="cva">&nbsp;</td>');
			document.write('</tr>');
		}
}
