// initialise global variables
var element = 0;
var count = 0;
			
// function to show the next image in the set
function nextImage(elementNum)
{
	if(element==imagesArray.length-1)
	{
		element = 0;
	}else{
		element = elementNum += 1;
	}// end if else
					
	// set the main image element with the new image	
	document.getElementById("mainImage").src = imagesArray[element];
}// end function nextImage()
					
// function to show the previous image in the set
function prevImage(elementNum)
{
	if(element==0)
	{
		element = imagesArray.length-1;
	}else{	
		element = elementNum -= 1;
	}// end if else
						
	// set the main image element with the new image
	document.getElementById("mainImage").src = imagesArray[element];
}// end function prevImage()
			
// function to show lightbox at the last viewed image
function showLightbox() {
	var lightbox = document.getElementById("lightbox");
	var lightboxBackground = document.getElementById("lightboxBackground");
				
	// initialise the display property of the lightbox as none
	if (count==0)
	{
		lightbox.style.display = 'none';
		lightboxBackground.style.display = 'none';
		count += 1;
	}// end if count==0
				
	if ( lightbox.style.display == 'none' ) 
	{
		// show the lightbox
		lightbox.style.display = 'block';
		lightboxBackground.style.display = 'block';
	}else {
		// hide the lightbox
		lightbox.style.display = 'none';
		lightboxBackground.style.display = 'none';
	}// end if else !=
}// end function showLightbox()
			
// function to show lightbox at a specified image
function showLightboxSelected(elementNum) {
	var lightbox = document.getElementById("lightbox");
	var lightboxBackground = document.getElementById("lightboxBackground");
				
	document.getElementById("mainImage").src = imagesArray[elementNum];
	element = elementNum;
				
	// initialise the display property of the lightbox as none
	if (count==0)
	{
		lightbox.style.display = 'none';
		lightboxBackground.style.display = 'none';
		count += 1;
	}// end if count==0
				
	if ( lightbox.style.display == 'none' ) 
	{
		// show the lightbox
		lightbox.style.display = 'block';
		lightboxBackground.style.display = 'block';
	}else {
		// hide the lightbox
		lightbox.style.display = 'none';
		lightboxBackground.style.display = 'none';
	}// end if else !=
}// end function showLightbox()
