//JavaScript Document
//Basic Image Gallery Functions
//Rhian Thomas - July 2004
//Copyright American Institute For Foreign Study
//Note: Quotations will not change on MACs. ImageDescriptions and large image will change on MACs.

//Function nextPicture
//Used to switch the large picture to the next picture in the image gallery
//Pre-conditions: Requires the variable integer 'numberOfPictures'
//'numberOfPictures' is the total number of images located in the gallery's 
//'large' folder and is calculated using server side VB in the asp page that calls this 
//javascript file.
//Also required is the variable integer 'currentPictureNumber'. This variable indicates which 
//large picture is currently displayed on the page and is set in the javascript located in the
//asp page that calls is javascript file.
//Post-conditions: Increments the 'currentPictureNumber' variable and passes on the 
//variables 'currentPictureNumber' and 'numberOfPictures' to the function changePicture. 'numberOfPictures' is unchanged.
function nextPicture(numberOfPictures)
{
	currentPictureNumber = currentPictureNumber + 1;
	
	//check if the next picture in the gallery does exists (if the currentPictureNumber is greater than the number of pictures
	//in the image gallery. If this is true, then display the first picture in the image gallery
	//if the currentPictureNumbe is > numberOfPictures, then currentPictureNumbe = 1
	if (currentPictureNumber > numberOfPictures)
		currentPictureNumber = 1;
		
	changePicture(currentPictureNumber, numberOfPictures);
}

//Function previousPicture
//Used to switch the large picture to the previous picture in the image gallery
//Pre-conditions: Requires the variable integer 'numberOfPictures'
//'numberOfPictures' is the total number of images located in the gallery's 
//'large' folder and is calculated using server side VB in the asp page that calls this 
//javascript file.
//Also required is the variable integer 'currentPictureNumber'. This variable indicates which 
//large picture is currently displayed on the page and is set in the javascript located in the
//asp page that calls is javascript file.
//Post-conditions: Decrements the 'currentPictureNumber' variable and passes on the 
//variables 'currentPictureNumber' and 'numberOfPictures' to the function changePicture. 'numberOfPictures' is unchanged.
function previousPicture(numberOfPictures)
{
	currentPictureNumber = currentPictureNumber - 1;
	
	//check if the previous picture in the gallery exists (if the currentPictureNumber is less than 1, then
	//display the last picture in the image gallery).
	//if the currentPictureNumber is < 1, then currentPictureNumber = numberOfPictures
	if (currentPictureNumber < 1)
		currentPictureNumber = numberOfPictures;
		
	changePicture(currentPictureNumber, numberOfPictures);
}

//Function changePicture
//Used to switch the large picture to the new image requested by the user
//Pre-conditions: Requires the variable integer 'numberOfPictures'
//'numberOfPictures' is the total number of images located in the gallery's 
//'large' folder and is calculated using server side VB in the asp page that calls this 
//javascript file.
//Also required is the variable integer 'pictureNumber'. This variable indicates which 
//picture has been requested by the user to be displayed.
//Optional are two arrays initalized in javascript files assigned in the asp page that called this file.
//The arrays are labeled 'imageDescriptions' and 'quotations' respectively.
//These optional arrays contain the image descriptions associated with the images (in ascending order) and 
//the quotations associated with the image gallery.
//If image descriptions are used, then the array must contain the same number of elements as the number of images
//located in 'large'.
//As of quotations, there may be as many or as few quotations as desired as the gallery will cycle through the 
//quotations.
//Post-conditions: The variable 'numberOfPictures' is unchanged. The function will determine which
//picture the user would like to be shown and displays the new picture, changes the imageDescription (if available) located 
//under the large picture and also changes the quotation (if available) located to the right of the large picture.
//if no imageDescription and/or quotation is available, no change is made. The variable integer 'currentPictureNumber' is set
//to the new picture number displayed. Updates the integer variable 'currentQuotationNumber' to the quotation now displayed if
//a change is made.

function changePicture(pictureNumber, numberOfPictures)
{
	//check if the array 'imageDescriptions' is a defined array (as it is optional)
	//if the array is defined, then change the field labeled 'pictureDescription' located under the large image
	//to the array element associated with the new image to be displayed. Note: works on MACs. 
	if (typeof imageDescriptions != "undefined")
	{
		document.getElementById("pictureDescription").innerHTML = imageDescriptions[pictureNumber - 1];
	}
	
	//display the large image requested by the user.
	//assumes that images are labeled in ascending order in the folder 'large' starting with 1.jpg
	largePicture.src = galleryName + "/large/" + pictureNumber + ".jpg";
	//set the currentPictureNumber to the pictureNumber now displayed
	currentPictureNumber = pictureNumber;
	
	//check if the array 'quotations' is a defined array (as it is an optional)
	//if the array is defined, display the next quotation in the file. 
	//if all quotations have been displayed, then restart the rotation at the first quotation in the file.
	//Note: does not work on MACs. On MACs, the quotation does not change.
	if (typeof quotations != "undefined")
	{
		//if the currentQuotationNumber > quotations.length(), then currentQuotationNumber = 0
		if (currentQuotationNumber >= quotations.length)
			currentQuotationNumber = 0;
		document.getElementById("quotation").innerHTML = quotations[currentQuotationNumber];
		currentQuotationNumber = currentQuotationNumber + 1;
	}
}
