//
// VARIOUS JAVASCRIPT FUNCTIONS USED IN DISPLAYING PICTURES
//
// Set a variable that will evaluate to "true" if using MSIE 4.0 or greater.

var IE = (navigator.appVersion.indexOf("MSIE") > 0) && (parseInt(navigator.appVersion) >= 4);
var NS = (navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 4);

// Delcare a variable for a "child" window.
var PictureWindow = null;

// Declare a variable for the CURRENT image's index.
var intCurrentImageIndex;

// Declare a variable for the path to the "images" folder.
var strImagesFolder;

// Declare variables for the current arrow conditions.
var	strPrevImageOn = "prev-on.jpg";
var	strPrevImageOff = "prev-off.jpg";
var	strPrevImageOver = "prev-over.jpg";
var	strFirstImageOn = "first-on.jpg";
var	strFirstImageOff = "first-off.jpg";
var	strFirstImageOver = "first-over.jpg";
var	strNextImageOn = "next-on.jpg";
var	strNextImageOff = "next-off.jpg";
var	strNextImageOver = "next-over.jpg";
var	strLastImageOn = "last-on.jpg";
var	strLastImageOff = "last-off.jpg";
var	strLastImageOver = "last-over.jpg";

// Function to open a separate window for viewing pictures. Once open (or 
// if already open), the picture and its caption are displayed in it.
function PictureOpen(intImageIndex)
{
	var strCurrentLocation;

	intCurrentImageIndex = intImageIndex;

	if (intImageIndex < 10)
		strImage = "0";
	else
		strImage = "";
	strImage = strImage + intImageIndex;

	strPicture = "pic" + strImage + ".jpg";
	strTitle = document.title;
	strCaption = Captions[intImageIndex - 1];
	if (IE)
	{
		intDefLength = 0;
		strHide = "none";
		strShow = "inline";
	}
	else
	{
		intDefLength = 50;
		strHide = "hidden";
		strShow = "show";
	}
	if (! PictureWindow || PictureWindow.closed)
	{
		// Get current location and then determine the relative location of
		// the "images" folder.
		strCurrentLocation = location.pathname.substr(location.pathname.indexOf("pictures"));
		for (i = 0, strImagesFolder = ""; i < strCurrentLocation.length; i++)
			if (strCurrentLocation.charAt(i) == "/")
				strImagesFolder = strImagesFolder + "../";
		strImagesFolder = strImagesFolder + "images/";

		PictureWindow = window.open("", "Picture","location=no,scrollbars=yes");
		PictureWindow.document.write(
			"<HTML><HEAD><TITLE>Picture from \"" + strTitle + "\"</TITLE></HEAD>");
		PictureWindow.document.write(
			"<BODY><center><form name=Image>" +
				"<font face='Arial' color=blue><br>" +
				"<img name=FirstOff border=\"0\" " +
					"src=\"" + strImagesFolder + strFirstImageOff + "\" " +
					"alt=\"At beginning.\" " +
					"style='display:" + strHide + ";'>" +
				"<img name=FirstOn border=\"0\" " +
					"src=\"" + strImagesFolder + strFirstImageOn + "\" " +
					"alt=\"First picture.\" " +
					"onclick='opener.PictureSlide(\"FIRST\");' valign=absbottom " +
					"onMouseOver='document.Image.FirstOn.src=\"" + strImagesFolder + strFirstImageOver + "\"' " +
					"onMouseOut='document.Image.FirstOn.src=\"" + strImagesFolder + strFirstImageOn + "\"' " +
					"style='color:blue; cursor:hand; display:" + strShow + ";'>" +
				"&nbsp;&nbsp;" +
				"<img name=PrevOff border=\"0\" " +
					"src=\"" + strImagesFolder + strPrevImageOff + "\" " +
					"alt=\"At beginning.\"" +
					"style=display:" + strHide + ";'>" +
				"<img name=PrevOn border=\"0\" " +
					"src=\"" + strImagesFolder + strPrevImageOn + "\" " +
					"alt=\"Previous picture.\" " +
					"onclick='opener.PictureSlide(\"PREV\");' valign=absbottom " +
					"onMouseOver='document.Image.PrevOn.src=\"" + strImagesFolder + strPrevImageOver + "\"' " +
					"onMouseOut='document.Image.PrevOn.src=\"" + strImagesFolder + strPrevImageOn + "\"' " +
					"style='color:blue; cursor:hand; display:" + strShow + ";'>&nbsp;&nbsp;" +
				"<span valign='top' style='font-size:26; font-family:Arial; color:blue;'>" + strTitle + "</span>&nbsp;&nbsp;" +
				"<img name=NextOn border=\"0\" " +
					"src=\"" + strImagesFolder + strNextImageOn + "\" " +
					"alt=\"Next picture.\" " +
					"onclick='opener.PictureSlide(\"NEXT\");' " +
					"onMouseOver='document.Image.NextOn.src=\"" + strImagesFolder + strNextImageOver + "\"' " +
					"onMouseOut='document.Image.NextOn.src=\"" + strImagesFolder + strNextImageOn + "\"' " +
					"style='color:blue; cursor:hand; display:" + strShow + ";'>" +
				"<img name=NextOff border=\"0\" " +
					"src=\"" + strImagesFolder + strNextImageOff + "\" " +
					"alt=\"At end.\" " +
					"style='display:" + strHide + ";'>" +
				"&nbsp;&nbsp;" +
				"<img name=LastOn border=\"0\" " +
					"src=\"" + strImagesFolder + strLastImageOn + "\" " +
					"alt=\"Last picture.\" " +
					"onclick='opener.PictureSlide(\"LAST\");' valign=absbottom " +
					"onMouseOver='document.Image.LastOn.src=\"" + strImagesFolder + strLastImageOver + "\"' " +
					"onMouseOut='document.Image.LastOn.src=\"" + strImagesFolder + strLastImageOn + "\"' " +
					"style='color:blue; cursor:hand; display:" + strShow + ";'>" +
				"<img name=LastOff border=\"0\" " +
					"src=\"" + strImagesFolder + strLastImageOff + "\" " +
					"alt=\"At end.\"" +
					"style=display:" + strHide + ";'>" +

				"<br><img name=Source src='" + strPicture + "' align=center border=8 alt='' " +
					"style='border-style:ridge;" +
					"border-top-color:#E7E7E7;border-left-color:#E7E7E7;border-bottom-color:#A7A7A7;border-right-color:#A7A7A7;'>" +
				"<br>");
		if (strCaption.length > 1)
		{
			PictureWindow.document.write(
			"<input name=Text type=text " +
				"style='font-size: 11; font-family: MS Sans Serif, Arial; font-weight: bold; text-align: center; " +
				"border-width: 1; border-style: solid; color: blue; display: " + strHide + ";' value='' " +
				">" +
			"<textarea name=TextArea rows=2 cols=80 " +
				"style='font-size: 11; font-family: MS Sans Serif, Arial; font-weight: bold; text-align: center; " +
				"border-width: 1; border-style: solid; scrollbar: no; color: blue; display: " + strHide + ";' value='' " +
				">" +
			"</textarea></input>");
		}
		PictureWindow.document.write("</form></center></BODY></HTML>");
	}
	PictureWindow.document.Image.Source.src = strPicture;
	PictureWindow.document.Image.Source.alt = strCaption;
	if (intImageIndex == 1)
	{
		PictureWindow.document.Image.FirstOff.style.display = strShow;
		PictureWindow.document.Image.FirstOn.style.display = strHide;
		PictureWindow.document.Image.PrevOff.style.display = strShow;
		PictureWindow.document.Image.PrevOn.style.display = strHide;
		PictureWindow.document.Image.NextOff.style.display = strHide;
		PictureWindow.document.Image.NextOn.style.display = strShow;
		PictureWindow.document.Image.LastOff.style.display = strHide;
		PictureWindow.document.Image.LastOn.style.display = strShow;
	}
	else if (intImageIndex == Captions.length)
	{
		PictureWindow.document.Image.FirstOff.style.display = strHide;
		PictureWindow.document.Image.FirstOn.style.display = strShow;
		PictureWindow.document.Image.PrevOff.style.display = strHide;
		PictureWindow.document.Image.PrevOn.style.display = strShow;
		PictureWindow.document.Image.NextOff.style.display = strShow;
		PictureWindow.document.Image.NextOn.style.display = strHide;
		PictureWindow.document.Image.LastOff.style.display = strShow;
		PictureWindow.document.Image.LastOn.style.display = strHide;
	}
	else
	{
		PictureWindow.document.Image.FirstOff.style.display = strHide;
		PictureWindow.document.Image.FirstOn.style.display = strShow;
		PictureWindow.document.Image.PrevOff.style.display = strHide;
		PictureWindow.document.Image.PrevOn.style.display = strShow;
		PictureWindow.document.Image.NextOff.style.display = strHide;
		PictureWindow.document.Image.NextOn.style.display = strShow;
		PictureWindow.document.Image.LastOff.style.display = strHide;
		PictureWindow.document.Image.LastOn.style.display = strShow;
	}
	if (strCaption.length > 1)
	{
		if (strCaption.length < 80)
		{
			PictureWindow.document.Image.TextArea.style.display = strHide;
			PictureWindow.document.Image.Text.style.display = strShow;
			PictureWindow.document.Image.Text.size = strCaption.length + 6;
			PictureWindow.document.Image.Text.style.fontFamily = "Arial";
			PictureWindow.document.Image.Text.style.fontSize = "16";
			PictureWindow.document.Image.Text.style.borderWidth = "2";
		}
		else if (strCaption.length < 120)
		{
			PictureWindow.document.Image.TextArea.style.display = strHide;
			PictureWindow.document.Image.Text.style.display = strShow;
			PictureWindow.document.Image.Text.size = strCaption.length + 4;
			PictureWindow.document.Image.Text.style.fontFamily = "Arial";
			PictureWindow.document.Image.Text.style.fontSize = "12";
			PictureWindow.document.Image.Text.style.borderWidth = "1";
		}
		else
		{
			PictureWindow.document.Image.Text.style.display = strHide;
			PictureWindow.document.Image.TextArea.style.display = strShow;
			PictureWindow.document.Image.TextArea.cols = 120;
			PictureWindow.document.Image.TextArea.style.fontFamily = "MS Sans Serif";
			PictureWindow.document.Image.TextArea.style.fontSize = "9";
			PictureWindow.document.Image.TextArea.style.borderWidth = "1";
		}
		PictureWindow.document.Image.Text.innerText = strCaption;
		PictureWindow.document.Image.TextArea.innerText = strCaption;

	}
	else
	{
		PictureWindow.document.Image.Text.innerText = "";
		PictureWindow.document.Image.TextArea.innerText = "";
		PictureWindow.document.Image.Text.style.display = strHide;
	}
	PictureWindow.focus();
}

// Function to close any windows that were opened.
function PictureClose()
{
	if (PictureWindow != null)
		PictureWindow.close();
}

// Function to display the thumbnail pictures.
function PictureThumbnails()
{
	// Loop through printing the thumbnails. 
	for (j = 1; j <= Captions.length; j++)
	{
		strThumbnail = "t-pic" + (j < 10 ? "0" : "") + j + ".jpg";
		
		document.write(
			"<img src='" + strThumbnail + "' border=3 " +
				"onclick=\"javascript:PictureOpen('" + j + "');\" " +
				"onMouseOver='window.status=\"Click on an image for full size viewing ...\";' " +
				"alt='" + Captions[j - 1] + "' " +
				"style='border-top-color:#D6D6D6;border-left-color:#D6D6D6;border-bottom-color:#A7A7A7;border-right-color:#A7A7A7;cursor:hand'>" +
			"&nbsp;\n");
	}
}	

function PictureSlide(strDirection)
{
	var intNewImageIndex = intCurrentImageIndex;

	// See which direction the slide needs to move and set the image index appropriately.
	if (strDirection == "NEXT")
		intNewImageIndex++;
	else if (strDirection == "PREV")
		intNewImageIndex--;
	else if (strDirection == "FIRST")
		intNewImageIndex = 1;
	else if (strDirection == "LAST")
		intNewImageIndex = Captions.length;

	if (intNewImageIndex < 1)
		intNewImageIndex = Captions.length;
	else if (intNewImageIndex > Captions.length)
		intNewImageIndex = 1;

	// Open the appropriate image.	
	PictureOpen(intNewImageIndex);
}

