var newsArray = new Array();
var currentNews = 0;
var myNewsInterval = setInterval ( 'moveNewsAuto()' , 10000 ); 

function newsData(_nimg , _ntitle , _ndate , _nabstract , _nLink)	{
	this.nImg = _nimg;
	this.nTitle = _ntitle;
	this.nDate = _ndate;
	this.nAbstract = _nabstract;
	this.nLink = _nLink;
}

function initNewsScroller()	{
	updateCurrentNews(0, false);

	// Build the little radio list
	var radBut = '';
	radBut += '<a href="javascript:void(0)" onclick="moveNews(\'last\', true)" id="last">&lt;</a>';
	for (i=0 ; i < newsArray.length ; i++ )	{
		radBut += '<a href="javascript:void(0)" onclick="updateCurrentNews(' +i+ ', true)" class="newsNav' +i+ ' newNavRad">' +(i + 1) + '</a>';
	}
	radBut += '<a href="javascript:void(0)" onclick="moveNews(\'next\', true)" id="first">&gt;</a>';
	$('#cyclenav').html(radBut)
}

function moveNewsAuto()	{
	moveNews('next', false);
}

function moveNews(dir, cancelAutoScroll)	{

	if (cancelAutoScroll)	{	clearInterval(myNewsInterval);	}

	tempNewsIndex = currentNews;
	if (dir == 'next')	{
		tempNewsIndex++;
		if ( tempNewsIndex >= newsArray.length )		{
			tempNewsIndex = 0;
		}
		updateCurrentNews(tempNewsIndex)
	}else{
		
		tempNewsIndex--;
		if ( tempNewsIndex < 0 )		{
			tempNewsIndex = (newsArray.length - 1);
		}
		updateCurrentNews(tempNewsIndex)
	}
}

function updateCurrentNews(newsArrayIndex, cancelAutoScroll)	{

	if (cancelAutoScroll)	{	clearInterval(myNewsInterval);	}

	currentNews = newsArrayIndex;
	na = newsArray[currentNews];

	// Add content
	$('#newsItemImg').attr('src', na.nImg);
	$('#newsItemTitle').html(na.nTitle);
	$('#newsItemDate').html(na.nDate);
	$('#newsItemAbstract').html(na.nAbstract);
	$('a.newsItemLink').attr('href' , na.nLink);

	// Change menu bullet thing
	$('#cyclenav a.on').removeClass('on');
	$('.newsNav' + newsArrayIndex ).addClass('on');
	//$('.newNav' + newsArrayIndex).css('background' , "url('../images/cyclenav-on.gif') no-repeat scroll 0 0 transparent");
}

