/*
	Tonic Digital Ltd
*/
//Setup global variables to track rotation element.
var imageRotateListIndex = 1
var imageRotateList      = null
var imageRotateTimerId   = null
var imageRotateInterval  = 5000
var imageRotateElementBase  = 'image-strapline-'
var runLoops             = true
var imageRotateListParentId = 'div#header-images'
var externalWindow;


//bootstrap is the common 
function BootstrapPage()
{
	SetupHeaderImageRotation();
}

function SetupHeaderImageRotation()
{
		imageRotateList = $(imageRotateListParentId + ' img');

		//we only rotate the images if there is one element in the parent dom object. 
		if(imageRotateList.length > 1)
		{
			//only start the timer if it has not already been started.
			if(imageRotateTimerId == null)
			{
				setInterval(RotateHeaderImageBoxChildren, imageRotateInterval)
			}
		}
}

// RotateHeaderImageBoxChildren, This function performs the rotation logic for any images. It works on the principle of 
// the first item in the list will be visible on page load, subsequent to that all images rotate in order.
function RotateHeaderImageBoxChildren()
{
	//get list length
	var listLength = imageRotateList.length

	//attain previous element id
	previousId = (imageRotateListIndex > 0)?imageRotateListIndex - 1:(listLength - 1);

	//reset imageRotateListIndex if it hits below condition.
	if(imageRotateListIndex >= listLength)
	{
		imageRotateListIndex = 0
	}

	//run special effects.
	
	$(imageRotateList[imageRotateListIndex]).fadeIn();
	$(imageRotateList[previousId]).fadeOut();

	imageRotateListIndex++
}

//bind to the onload event in the browser

var $ = jQuery.noConflict();

$(function() { BootstrapPage() ; });

