var n = 0;
var newsList = new Array();

var randomQuery = "?" + Math.floor( Math.random()*100 );

$.getJSON("cms/news.json", function(json)
{
	newsList = json.data;
});
		
jQuery(document).ready(function(){
	if( newsList[0] == undefined )
	{
		getNewsList();
	}
	else
	{
		startUp();
	}
});

function startUp()
{
	jQuery('#newsTopics')
		.html( newsList[0] )
		.hide()
		.fadeIn("slow",
			playNews	
		);
	
	setTopHtml();
}

function playNews()
{
	var tid=setInterval("upDate()",5000);
	//getNewsList();
}

function getNewsList()
{
	$.getJSON("cms/news.json", function(json){
		newsList = json.data;
		startUp();
	});
	
	/*var j = 0;
	jQuery('#newsList li').each(function(){
		newsList[j] = $(this).html();
		j++;
	})*/
}

function upDate()
{
	n++;
	
	if( newsList[n] == undefined)
	{
		n=0
	};
	var newsTx = newsList[n];

	jQuery('#newsTopics')
		.fadeOut("slow",
			function(){
				jQuery('#newsTopics')
					.html(newsTx)
					.fadeIn("slow")
			}
		);
}

function setTopHtml()
{
	var __reg0 = newsList.length;
	
	for( i=0; i<__reg0; i++ )
	{
		jQuery('#newsList').prepend( "<li>" + newsList[i] + "</li>" );
	}
}
