/*
	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;


function FixIE6flicker() {
	try {
		document.execCommand("BackgroundImageCache", false, true);
	} catch(err) { }
}

//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++
}

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

if(typeof sIFR == "function"){
	sIFR.replaceElement(named({sSelector:"div.left-column h2, h3", sFlashSrc:"/assets/helvetica_45light.swf", sColor:"#000000", sBgColor:"#ffffff", sWmode:"transparent", selectable:true}));

	sIFR.replaceElement(named({sSelector:"div.contact-details h2", sFlashSrc:"/assets/helvetica_45light.swf", sColor:"#000000", sBgColor:"#cccccc", sWmode:"transparent", selectable:true}));


	sIFR.replaceElement(named({sSelector:"div.quote", sFlashSrc:"/assets/helvetica_45light.swf", sColor:"#ffffff", sBgColor:"#ae4c7b", sWmode:"transparent", selectable:true}));	
	
	
	sIFR.replaceElement(named({sSelector:"div.opening h2", sFlashSrc:"/assets/helvetica_45light.swf", sColor:"#ffffff", sBgColor:"#666666", sWmode:"transparent"}));

};

