/*
Class: 		ImageGallery
Author: 	matt@gruden.com
Date:		4/10/2004
Version: 	1.0.0

Description: ImageGallery Class.
- Offers Next/Previous functionality for an image gallery
- Specify the id of the thumb-nail Element to be updated.
- Specify the id of the large-image link Element to be updated (i.e. the href property is updated).
- Assumes that small and large images are named the same.
*/


/*
* Constructor
* @param String thumbNailElementId (name of target element). Required
* @param String thumbNailPath (path to the thumbnails). Required
* @param String[] imagesArray (array of image paths). Required
* @param String largeLinkElementId (name of large-image <a> element). Required
* @param String largeImagePath (path to the large-images) Required
* @param Boolean popUpLargeImage (should large-image open in a popUp (true) or current window (false)). Required
* @param String popUp_template. Optional
* @param int imageId  (image index). Optional
*/
function ImageGallery(thumbNailElementId, thumbNailPath, imagesArray, largeLinkElementId, largeImagePath, popUpLargeImage, popUp_template, startIndex){
	this.thumbNailElement = document.getElementById(thumbNailElementId);
	this.thumbNailPath = thumbNailPath;
	this.imagesArray = imagesArray;
	this.largeLinkElement = document.getElementById(largeLinkElementId);
	this.largeImagePath = largeImagePath;
	this.popUpLargeImage = popUpLargeImage;
	
	// optional parameters
	if(arguments[6] != "undefined"){
		this.popUp_template = arguments[6]
	}
	if(arguments[7] != "undefined"){
		this.activeImageNum = arguments[7];
	}else{
		// default is first image in array
		this.activeImageNum = 0;
	}
};

var o = ImageGallery.prototype;

// Public Methods
// -----------------------------------------------------------
o.nextImage = function(){
	this.activeImageNum ++;
	if (this.activeImageNum >= this.imagesArray.length){
		this.activeImageNum = 0;
	}
	this.setThumbNailSrc();
}

o.previousImage = function(){
	this.activeImageNum --;
	if (this.activeImageNum < 0){
		this.activeImageNum = (this.imagesArray.length - 1);
	}
	this.setThumbNailSrc();
}	
// -----------------------------------------------------------


// Private Methods
// -----------------------------------------------------------
o.setThumbNailSrc = function(){
	this.thumbNailElement.src = this.thumbNailPath + this.imagesArray[this.activeImageNum];
	this.setLargeImageLink();
}

o.setLargeImageLink = function(){
	var target_url = this.largeImagePath + this.imagesArray[this.activeImageNum];
	var height = 50;
	var width = 50;

	if(! this.popUpLargeImage){
		this.largeLinkElement.href = target_url
	}else{
		// open a cfm template (which calculates the height/width of window according to image dimentions). Pass the image_scr as a url parameter
		this.largeLinkElement.href = 'javascript:window.open("' + this.popUp_template + '?image_scr=' + target_url + '","largeImage", "width=' + width + ', height=' + height + ', resizable=yes,scrollbars=yes,top=15,left=15"); void 0;'
	}
}

// -----------------------------------------------------------