// -----------------------------------------------------------------
//						Redland Shire Council 
// -----------------------------------------------------------------
// Class    : Loading 
// Purpose  : Handles the loading animation by swapping images.
// -----------------------------------------------------------------
// Calls    :
// Called by: Anything that requires the loading splash animation
// -----------------------------------------------------------------
// Arguments:
// Globals  :
// Returns  :
// -----------------------------------------------------------------
// Notes    : 
// -----------------------------------------------------------------
// History  :
// =================================================================

// a variable used to remember the ID of the timeout object
var timeoutID=0;

//Function to swap images to give the illusion of animation
function LoadNextImage()
{
	//Show the loading spash image element
	document.getElementById('loadingSplash').style.visibility = 'visible';
	
	//Check the alt tag to determine which image from the animation is currently displayed
	switch(document.getElementById('loadingSplash').alt)
	{
		//Check the current image and change it, along with the alt tag
		case '0':
			document.getElementById('loadingSplash').src = 'images/loading_1.gif';
			document.getElementById('loadingSplash').alt = '1';
			break;
		case '1':
			document.getElementById('loadingSplash').src = 'images/loading_2.gif';
			document.getElementById('loadingSplash').alt = '2';
			break;
		case '2':
			document.getElementById('loadingSplash').src = 'images/loading_3.gif';
			document.getElementById('loadingSplash').alt = '3';
			break;
		case '3':
			document.getElementById('loadingSplash').src = 'images/loading_0.gif';
			document.getElementById('loadingSplash').alt = '0';
			break;
	}
	
	//Wait a random amount of time before going to the next image (between 300-700ms)
	var randomWait = Math.round(Math.random() * (700 - 300)) + 300;
	
	//Call this function again after the random delay
	timeoutID=window.setTimeout("LoadNextImage();", randomWait);
}

function HideLoadingImage()
{
	//Show the loading spash image element
	document.getElementById('loadingSplash').style.visibility = 'hidden';
	
	//cancel the recursive function
	window.clearTimeout(timeoutID);
}

//Move the loading image splash to the centre of the new screen dimensions
//This method is called on the img's 'onload' event.
function updateLoadingSplashPos()
{
		document.getElementById('loadingSplash').style.left = document.body.clientWidth/2 - document.getElementById('loadingSplash').width/2;
		document.getElementById('loadingSplash').style.top = document.body.clientHeight/2 - document.getElementById('loadingSplash').height/2;
}