
	var arrImages = new Array;
	var objPhoto = document.getElementById("imgPhotoLarge");
	var objPhotoDescription = document.getElementById("lblPhotoDescription");
	var objImageContainer = document.getElementById("imgcontainer");

	// Load image from thumbnail
	function showThumb(objImage) {
		showImage(objImage.arrindexid);
	}

	// Load image
	function showImage(intIndex) {
		objPhoto.src = arrImages[intIndex].src;
		objPhoto.arrindexid = intIndex;
		objPhotoDescription.innerHTML = arrImages[intIndex].photodescription;
	}

	// Add a new image to the list
	function addImage(id, description) {
		var strImage = "";

		strImage = "<img src=\"getimage.aspx?id=" + id + "&type=thumb\" rftype=\"thumb\" photoid=\"" + id + "\" photodescription=\"" + description + "\" onmouseover=\"showThumb(this);\" class=\"portfoliothumb\" >";

		objImageContainer.innerHTML += strImage;

	}

	// Navigate to the next image, start again when last image shown
	function nextImage() {
		var intCurrentImage = 0;
		if (arrImages.length > 0) {

			intCurrentImage = objPhoto.arrindexid;

			intCurrentImage++;

			if (intCurrentImage == arrImages.length) {
				intCurrentImage = 0;
			}

			showImage(intCurrentImage);
		}
	}

	// Navigate to the previous image, go to end when first image shown
	function previousImage() {
		var intCurrentImage = 0;
		if (arrImages.length > 0) {

			intCurrentImage = objPhoto.arrindexid;

			intCurrentImage--;

			if (intCurrentImage == -1) {
				intCurrentImage = arrImages.length - 1;
			}

			showImage(intCurrentImage);
		}
	}

	// Preload all images
	function preloader() {

		var objImages = document.getElementsByTagName("IMG");
		var intNewIndex = 0;

		for (var i=0;i<objImages.length;i++) {

			if (objImages[i].getAttribute("rftype") == "thumb") {
				intNewIndex = arrImages.length;
				arrImages[intNewIndex] = new Image();
				arrImages[intNewIndex].src = "getimage.aspx?id=" + objImages[i].getAttribute("photoid") + "&type=normal";
				arrImages[intNewIndex].photodescription = objImages[i].getAttribute("photodescription");

				objImages[i].arrindexid = intNewIndex;
			}

		}

		if (arrImages.length > 0) {
			showImage(0);
		}

	}	
