
/*  file name: tour_code.js   */

/*  This is the exciting part. It is not brain surgery, just careful 
planning. There are three basic concepts at work here: display the image, display 
the text, and move left or right.  */
		
var imageIndex = 0;   /* Initialize the index to the beginning image  */

/*  Compute the number of images so you can calculate when 
you reach the end of the array and can start over.  */

var imageLength = eval(tourScript + "_imageFile").length-1;
var imageFile;

/*  Because the onLoad event in the image tag  (containing the blank image) 
is triggered when the page loads,  the code attempts to find an associated 
image comment. To prevent the script from trying to display something that 
doesn't exist, we set an initial flag, which  will be cleared after the very 
first image is called via the displayImages() function. 


*/

var flagOne = 0;

/*  Check first to see if the browser is capable of displaying 
images and then calculate a value for the image file using the 
"tourscript" variable and the index number of the image array. 
The javaScript eval() function is great for these tasks. */

function displayImages() {
	if (document.images) {
		imageFile = eval(tourScript + "_imageFile[imageIndex]");
		flagOne = 1;     /*  we clear the flag on the first good image  */

		/* Here we replace the source of the "nowshowing" image, 
on the HTML page, with the file name of the image in the 
image array (sample tour script). This causes the image to change. */

		document.nowshowing.src = imageFile;
		/*  For Netscape browsers that are finicky about
		the onLoad() event placed in the image tag,
		uncomment the following line of code and remove the
		onLoad() event handler from the image tag in the HTML document.  */
		//Call displayTitle();
	}
}

	/*  Now that the image has finished loading, you can 
display the contents of the form's "textarea." Here you check to see 
that the flag has been reset and then bring in new data 
from the sample tour script.   */

function displayTitle()  {
	if (document.images) {
		if (flagOne == 1) {
		
	/*  There are two parts here. On the left side, you specify 
that the form "displaycomments" has a field "comments" with a 
value attribute we want to change. On the right you use the eval() 
function to create the text by specifying the position in the 
imageComments array (sample tour script) and grabbing the text. 
		
		document.displaycomments.comments.value = eval(tourScript + "_imageComments")
		[imageIndex];*/
		

caption.innerHTML = eval(tourScript + "_imageComments")
		[imageIndex];

}
	}
}

	/* The following two functions either add one or subtract one from the 
image index and then call the displayImages() function. The functions also 
check to see if the image index is at the end or the beginning 
and resets the index accordingly.  */

function turnLeft()  {
	imageIndex--;
	if (imageIndex < 0)  { imageIndex = imageLength };
	displayImages();
}

function turnRight()  {
	//alert(imageIndex);
	imageIndex++;
	if (imageIndex > imageLength)  { imageIndex = 0 };
	displayImages();
}
