/* 	mini-gallery.js - Dynamically displays images on introduction pages 5 at a time.
-------------------------------------------------------------------------------------- */
// global variable defining which image we are on.
var currId = 1;
var asImagePath = new Array();


function hideAll(){
	//hide all the large images
	for (i = 1; i < 6; i++){
		var divId = 'big' + i;
		if(document.getElementById(divId) != null){
			document.getElementById(divId).style.display = 'none';
		}
	} // end loop
}

function switchImage(thisId) {
	hideAll();
	imgId = 'big' + thisId;
	//show the clicked on image
	document.getElementById(imgId).style.display = 'block';
	//set current id
	currId = thisId;
	
	// Set the selected image path in the set form
	setTopImage(currId);
}

function nextImage(sNextUrl){
	if ( currId < 5 ) 
	{
		nextId = 'big' + (currId + 1);
		
		// check the next image exists (could be at end)
		// if so hide all then show it
		var eltNext = document.getElementById(nextId)
		if (eltNext != null)
		{
			currId = currId + 1;
			hideAll();
			eltNext.style.display = 'block';
		}
	}
	else 
	{
		currId = 1;
		if (sNextUrl.length > 0)
		{
			window.location = sNextUrl;
		}
	}
	
	// Set the selected image path in the set form
	setTopImage(currId);	
}


function prevImage(sPrevUrl){
	
	if ( currId > 1 ) {
		currId = currId - 1;
		prevId = 'big' + currId;
		//hide all large images
		hideAll();
		//show the prev image
		document.getElementById(prevId).style.display = 'block';
	}
	else 
	{
		if (sPrevUrl.length > 0)
		{
			window.location = sPrevUrl;
		}
	}

	// Set the selected image path in the set form
	setTopImage(currId);
}


function setTopImage(i)
{
	currId = i;
	
	// In online, the set top image link isn't there
	var eltImage = document.getElementById('image');
	if (eltImage != null)
	{
		eltImage.value = asImagePath[i];
	}
}


function submitTopImage() 
{
	var form = document.getElementById("form_imageselect");
	if (form != null) {
		form.submit();
		return;
	}
}
