var objNewImage;

function nextImage() {
	
	//start moving the main image to the next one
	var intWhichImage = (intCurrentImage+1);
	if (intWhichImage > intTotalImages) {
		intWhichImage = 1;
	}
	
	//call the main function to start the swap
	changeImage(intWhichImage);
	
}

function prevImage() {
	
	//start moving the main image to the previous one
	var intWhichImage = (intCurrentImage-1);
	if (intWhichImage < 1) {
		intWhichImage = intTotalImages;
	}
	
	//call the main function to start the swap
	changeImage(intWhichImage);
	
}

function changeImage(intImageNum) {
	
	//get the required objects
	var objLoadingImage = document.getElementById('loadingimage');
	var objMainImage = document.getElementById('mainimage');
	
	//set the main image to the loading image
	objMainImage.src = objLoadingImage.src;
	
	//create a new image to load the new one
	objNewImage = new Image;
	objNewImage.onload = loadImageComplete;
	objNewImage.onerror = loadImageError;
	objNewImage.onabort = loadImageAbort;
	
	//load it
	objNewImage.src = strGallery + '/images/' + intImageNum + '.jpg';
	
	intCurrentImage = intImageNum;

}

loadImageComplete = function() {
	//set the image to the new one
	var objMainImage = document.getElementById('mainimage');
	objMainImage.src = objNewImage.src;
}

loadImageError = function() {
	//show error message to the user
	alert('Sorry, there has been an error loading the image you selected.');
}

loadImageAbort = function() {
	//do nothing
}
