var fullyFeatured =
	(navigator.appName != "xNetscape" && parseInt(navigator.appVersion) >= 4);

var maxPictureIndex = Math.floor(pictureData.length / 4);
var callCount = 0;
var lastIndex = 0;

function byId(id)
{
	// Should use document.all[id] for ie4, document.layers[id] for ns4,
	// and document.getElementById(id) for ie5 and ns6
    return document.getElementById(id);
}

function layoutIndexEntry(i, j, curr)
{
	var html = "";

	html += "&nbsp; ";
	if (i == curr)
		html += "<!b>";
	else
		html += "<a href='javascript:showPicture(" + i + ")'>";
	html += i + 1;
	if (j > i + 1)
		html += "-" + j ;
	if (i == curr)
		html += "<!/b>";
	else
		html += "</a>";

	return html;
}

function showPicture(index)
{
	var html;

	if (index < 0)
		index = 0;
	else if (index >= maxPictureIndex)
		index = maxPictureIndex - 1;

	document.myPicture.src = picturePath + pictureData[(index * 4) + 0];
	document.myPicture.width = pictureData[(index * 4) + 1];
	document.myPicture.height = pictureData[(index * 4) + 2];
	if (index + 1 < maxPictureIndex)
		document.myCache.src = picturePath + pictureData[((index + 1) * 4) + 0];

	callCount++;
	lastIndex = index;

	if (callCount > 1) {
		byId('myHelp').innerHTML = "";
	}

	// The following may fail (silently break) under NS 7 or earlier
	if (1 || fullyFeatured) {
		var i = 0;
		var imin = Math.floor(index / 20) * 20;
		var imax = imin + 20;

		if (imax > maxPictureIndex)
			imax = maxPictureIndex;

		byId('myCaption').innerHTML = pictureData[(index * 4) + 3];

		html = "<b>";
		if (index > 0)
			html += "<a href='javascript:showPicture(" + (index - 1) + ")'>";
		html += "&larr;";
		if (index > 0)
			html += "</a>";

		while (i < maxPictureIndex) {
			var j = i;

			j = i + ((i >= imin && i < imax) ? 1 : 20);
			if (j > maxPictureIndex)
				j = maxPictureIndex;

			html += layoutIndexEntry(i, j, index);

			i = j;
		}

		html += "&nbsp; ";
		if (index + 1 < maxPictureIndex)
			html += "<a href='javascript:showPicture(" + (index + 1) + ")'>";
		html += "&rarr;";
		if (index + 1 < maxPictureIndex)
			html += "</a>";
		html += "</b>";

		byId('myControl').innerHTML = html;
	}

}

function showNextPicture(offset)
{
	showPicture(lastIndex + offset);
}

function layoutPictureIndex()
{
	if (1 || !fullyFeatured) {
		var tmp =
			"<b><a href='javascript:showNextPicture(-1);'>&larr;</a>&nbsp;";

		for (var i = 0; i < maxPictureIndex; i++) {
			if (i > 0)
				tmp += "&nbsp; ";
			tmp += "<a href='javascript:showPicture(" + i + ")'>" + (i + 1) +
				"</a>";
		}

		tmp +=
			"&nbsp;<a href='javascript:showNextPicture(1);'>&rarr;</a></b>";
		document.write(tmp);
	}
}

