var headlines;
var k;

function newsrotate() {

	// Madness, json indexes from -1 !!!
	if (parseInt(k) == parseInt(headlines.length)-1) { k = -1; }
	
	$('#news_headline').fadeOut("slow", function() {
		var subject = '<b>' + headlines[k].subject + '</b>';
		
		$('#news_headline').html(subject);
		$('#news_headline').attr('href', headlines[k].uri);
		$('#news_headline').fadeIn("slow");
	});
	
	k++;
}

$(document).ready(function () {
	$.get("/news/get_latest_headlines", function(data) {
		
		headlines = eval(data);
		k = 0;
		newsrotate();
		setInterval("newsrotate()", 5000);
		
	}, "json");
});
