/*
	Tonic Digital Ltd
*/
//Setup global variables to track rotation element.
var newsItemRotateListIndex = 1;
var newsItemRotateList      = null;
var newsItemRotateTimerId   = null;
var newsItemRotateInterval  = 1750;
var newsItemRotateElementSelector  = 'div.blog-news-item';
var runLoops             = true;
var newsItemParentSelector = 'div#latest_news';


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


function SetupNewsItemRotation()
{
	newsItemRotateList = $(newsItemRotateElementSelector, newsItemParentSelector)
	
	if(newsItemRotateList.length > 1 && newsItemRotateTimerId == null)
	{
			setInterval(RotateNewsItemBoxChildren, newsItemRotateInterval)
	}	
}

// RotateNewsItemBoxChildren, 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 RotateNewsItemBoxChildren()
{
	//get list length
	var listLength = newsItemRotateList.length

	previousId = (newsItemRotateListIndex > 0)?newsItemRotateListIndex - 1:(listLength - 1);



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

	$(newsItemRotateList[newsItemRotateListIndex]).fadeIn();
	$(newsItemRotateList[previousId]).fadeOut();
	
	//run special effects.
	/*new Effect.Appear( $(newsItemRotateElementBase + newsItemRotateListIndex) )
	new Effect.Fade( $(newsItemRotateElementBase + previousId) )
*/
	newsItemRotateListIndex++
}

//bind to the onload event in the browser
$(function() {
	BootstrapPage();
});
