
/*******************************************************************************
* Image Viewer Scripts
*******************************************************************************/

// global variable to set the currently displayed photo div - default to 1
var photoIndex = 1;

// perform photo next
// javascript variable photoIndexMax must be set on the page
function doPhotoNext() {
	
	// ensure the next photo index exists
	if (photoIndex < photoIndexMax) {
		
		// increase the photo index
		photoIndex++;

		// show the new index, hide all others
		hide("div_photo_" + (photoIndex - 1));
		show("div_photo_" + photoIndex);

		// show previous link, hide next link if we have reached the max
		show("div_photo_previous");
		if (photoIndex == photoIndexMax) {
			hide("div_photo_next");
		} else {
			show("div_photo_next");
		}
	}
}

// perform photo previous
// javascript variable photoIndexMax must be set on the page
function doPhotoPrevious() {

	// ensure the previous photo index exists
	if (photoIndex > 1) {

		// decrease the photo index
		photoIndex--;

		// show the new index, hide all others
		hide("div_photo_" + (photoIndex + 1));
		show("div_photo_" + photoIndex);

		// show next link, hide previous link if we have reached the minimum
		show("div_photo_next");
		if (photoIndex == 1) {
			hide("div_photo_previous");
		} else {
			show("div_photo_previous");
		}
	}
}

// perform photo click
// pass in the URL to the new large image
function doPhotoClick(imageURL) {
	doPhotoClick(imageURL, null, null, null);
}

function doPhotoClick(imageURL, imageWidth, imageHeight) {
	doPhotoClick(imageURL, imageWidth, imageHeight, null);
}

function doPhotoClick(imageURL, imageWidth, imageHeight, imageAlt) {
	// change the image source to the imageURL parameter
	target = document.getElementById("img_photo_main");

	if (target != null) {
		target.src = imageURL;
		
		if (imageWidth != null) {
			target.width = imageWidth;
		}
		
		if (imageHeight != null) {
			target.height = imageHeight;
		}
		
		if (imageAlt != null) {
			target.alt = imageAlt;
		}
	}
}
