


var intArrayIndex = 1;				// start the index of the photo array at 1 instead of 0

var a_PhotoArray = new Array();	// create a new photo array



var currentGallery = 1;				// set the current thumbnail gallery at the first one

var imgChg = new Array();			// create an array for preloading images

var whichImageLoaded = intArrayIndex;	// set the default medium image to the first image in the photo array



var noOfImages						// variable to store the number of images



// FUNCTION

// Function to initialize the Gallery page

function initGallery(){

	if(is.ns && is.mac) relSize.moveBy(0,-4);	// fix for netscape on macs by moving the relSize Div up 4 pixels

	loadPhoto(whichImageLoaded);	// load the first image from the image path array to be displayed

	checkForMoreImages();

	relative.show();				// display the relative Div, which was hidden to prevent the user from seeing a blue box move around the screen

	gallery1.show();				// display the first gallery thumbnails

	preloadCars();					// preload the medium size photo images to improve user performance

}



// FUNCTION

// Function used by the photo gallery popup page to get the current index of the array to display the correct big image

// INPUTS:	none

// OUTPUTS:	array index of the current image displayed

function getCurrentImageValue(){

	return whichImageLoaded;

}



// FUNCTION

// Function to preload/precache the medium images of the photo array

function preloadCars(){

	// Preload medium images here.  Write out for each appropriate image.

	imgChg = new Image();

	for (var i = 1; i <= a_PhotoArray.length; i++){

		imgChg[i] = new Image();

		imgChg[i].src = a_PhotoArray[1].med

	}

	return true;

}



// OBJECT

// Photo Object

// INPUTS:	sml = path of small image

//			med = path of medium image

//			big = path of big image

//			size = size of the big image in kilobytes

//			text = text associated with the big image

// OUTPUTS:	NONE

function imgObject(sml, med, big, size, text) {

	this.sml = sml;

	this.med = med;

	this.big = big;

	this.size = size;

	this.text = text;

}


// FUNCTION

// Function to store the image properties into the photo object which is stored in the photo array

// INPUTS:	sml = path of small image

//			med = path of medium image

//			big = path of big image

//			size = size of the big image in kilobytes

//			text = text associated with the big image

// OUTPUTS:	NONE

function fillImgArray(sml, med, big, size, text) {

	a_PhotoArray[intArrayIndex++] = new imgObject(sml, med, big, size, text);	//increment the photo index and store the new photo object in the array

}




// Modify this function to output the correct image name. 

// Replaces the current medium photo with the new photoID

// INPUTS:	photoID  = array index of the photo to load

// OUTPUTS:	swaps the current medium image with the new photoID

function loadPhoto(photoID) {

	// setup the beginning html string with the urlPathValue to the photo gallery popup page

	var strSizeBegin = '<a href="javascript:popWindow(\'' + urlPathValue + '\', \'pictureWindow\',700,450,1,0,1);" class="GalleryLink"><span class="whitetext"><img name="largePhoto" src="images/g_arrowWhite.gif" width="9" height="10" border="0" />Large (';

	var strSizeEnd = 'k)</span></a>';	// close up the html string

	

	whichImageLoaded = photoID;		// set whichImageLoaded variable to photoID to track the current image being displayed



	document.images.photoDisplay.src = a_PhotoArray[photoID].med;	// set the new image src to the medium photo path from the photo array

	

	size.write(strSizeBegin + a_PhotoArray[photoID].size + strSizeEnd);		// write to the size div the updated href link and size information

}



// FUNCTION

// Function to check if there is more then 12 images in the photo array, and display a link for more images to swap the thumnail gallery images

// OUTPUTS: returns the appropiate html string to the page

function checkForMoreImages(){

	var text;

	noOfImages = a_PhotoArray.length - 1;	// set the noOfImages in this page



	if (noOfImages <= 12) {

		text = '<spacer type="block" width="1" height="1">';

	} else {

		text = '<a href="javascript:toggleGallery();" class="GalleryLink"><span class="whitetext"><img name="moreImages" src="images/g_arrowWhite.gif" width="9" height="10" border="0" />More Images</span></a>';

	}

	

	more.write(text);

}



// FUNCTION

// Function to navigate the gallery with previous and next links

// INPUTS:	direction = 1 (go forward) / -1 (go back/previous)

// OUTPUTS:	change the current image to the appropiate image

function changeImage(direction) {

	whichImageLoaded += direction;		// set the whichImageLoaded variable to the current image



	var blnToggle = false;				// set the blnToggle boolean to false



	if (whichImageLoaded < 1) whichImageLoaded = noOfImages;	// if the new image index is 0 then set the photo index to the last image

	if (whichImageLoaded > noOfImages) whichImageLoaded = 1;	// if the new image index is greater than the number of images in the array, set the photo index to 1



	if ((whichImageLoaded >=1) && (whichImageLoaded <=12) && (currentGallery != 1)) blnToggle = true;	// check to see if the thumbnail gallery has to be swapped

	if ((whichImageLoaded >=13) && (whichImageLoaded <=24) && (currentGallery != 2)) blnToggle = true;



	if (blnToggle) toggleGallery();		// if the blnToggle boolean is true, then swap the thumbnail gallery

	

	loadPhoto(whichImageLoaded);		// load the new current image

}



// FUNCTION

// Function to swap the thumbnail gallery

function toggleGallery() {

	if (currentGallery == 1) {

		gallery1.hide();

		gallery2.show();

		currentGallery = 2;

	} else {
		gallery2.hide();
		gallery1.show();
		currentGallery = 1;
	}
}

