/**
* Javascript file used to display the images in the gallery
* Required the gallery markup defined in the gallery.html page and galleryImages.js which defines
* the images to display.
*
* Author: Andrew Powell, Copyright &copy; 2008
* Version: 1.0
* Date: 01/08/2008
**/


var position = 0;

var picturesPerPage = 6;

var imagesLocation = "./images/";

/*
* Go to the next gallery page
*/
function next2() {
	for(var i = 0; i < picturesPerPage; i++) {
		cleanup(i);
	}
	
	for(var i = 0; i < picturesPerPage; i++) {
		var imagePlacehold = document.getElementById("img" + i);
		cleanup(i);
		if(galleryImages[position] != undefined) {
			document.getElementById("href" + i).style.display = "block";
			imagePlacehold.src = smallLocation + galleryImages[position].src;
			imagePlacehold.alt = galleryImages[position].title;
			imagePlacehold.title = galleryImages[position].title;
			imagePlacehold.className = "imageBorder";
			document.getElementById("title" + i).innerHTML = galleryImages[position].title;
			document.getElementById("href" + i).href = mediumLocation + galleryImages[position].src;
			document.getElementById("href" + i).style.textDecoration = "none";
		} else {
			document.getElementById("href" + i).style.display = "none";
			imagePlacehold.src = imagesLocation + "none.gif";
			imagePlacehold.className = "imageBorderNone";
			imagePlacehold.alt = "";
		}
		position++;
	}
	checkPosition();
	// refresh the lightbox code so that it picks up the new links
	//new Lightbox();
	//initLightbox();
	
	for(var i = 0; i < picturesPerPage; i++) {
		try {
			document.getElementById("floater" + i).onmouseover = function() {
				this.style.cursor = "pointer";
			};
			document.getElementById("floater" + i).onmouseout = function() {
				this.style.cursor = "default";
			};
			document.getElementById("floater" + i).onclick = document.getElementById("href" + i).onclick;
		} catch(e) {
		}
	}
}

/*
* Clean up previous gallery configurations
*/
function cleanup(index) {
	document.getElementById("title" + index).innerHTML = "";
	document.getElementById("img" + index).src = imagesLocation + "none.gif";
}

/*
* Go back to the previous gallery page
*/
function previous2() {
	position = position - (picturesPerPage * 2);
	next2();
}

/*
* Move to the start
*/
function gotoStart() {
	position = 0;
	next2();
}

/*
* Move to the end
*/
function gotoEnd() {
	position = Math.floor(galleryImages.length / picturesPerPage) * picturesPerPage;
	if(galleryImages[position] == undefined) {
		position = position - picturesPerPage;
	}
	next2();
}

/*
* Check the position of the gallery index enabling or disabling button
*/
function checkPosition() {
	document.getElementById("next_1").disabled = false;
	document.getElementById("next_2").disabled = false;
	document.getElementById("previous_1").disabled = false;
	document.getElementById("previous_2").disabled = false;
	document.getElementById("start_1").disabled = false;
	document.getElementById("start_2").disabled = false;
	document.getElementById("end_1").disabled = false;
	document.getElementById("end_2").disabled = false;
		
	if(position >= galleryImages.length) {
		// disable next
		document.getElementById("next_1").disabled = true;
		document.getElementById("next_2").disabled = true;
	}
	if(position <= picturesPerPage) {
		document.getElementById("previous_1").disabled = true;
		document.getElementById("previous_2").disabled = true;
	}
	if(position <= picturesPerPage) {
		document.getElementById("start_1").disabled = true;
		document.getElementById("start_2").disabled = true;

	}
	if(position >= galleryImages.length) {
		document.getElementById("end_1").disabled = true;
		document.getElementById("end_2").disabled = true;
	}
}