$(document).ready(function() {

//	The time in millesconds to delay the displaying
var newsRSSTimeDelay = 9000;

//	Read the items array generated by the above PHP code
var newsRSSitems = "";

var timeout = 0;

var i = 0;
function showNextNewsRSSItem() {
	$(".opinion").fadeOut("fast", function() {
	
		//	Display the new item in the desired HTML element
		$(".opinionText").text(newsRSSitems[i]['title']);
		
		//	Give the link tag the right destination
		$("#opinionItem").attr("href", newsRSSitems[i]['link']);
		
		//	Fade in the HTML which contains the text
		$(".opinion").fadeIn("fast", function() {
			i++;
			if (i >= newsRSSitems.length) {
				i = 0;
			}
		});
	});
		
	//	show the next item after a short wait
	timeout = setTimeout(showNextNewsRSSItem, newsRSSTimeDelay);

	
}







$("button.RSSPrev").click(function() {
	clearTimeout(timeout);
	i = i-2;
	if (i < 0) {
		i = newsRSSitems.length+1;
	}
	showNextNewsRSSItem();
	
	return false;
});

$("button.RSSNext").click(function() {
	clearTimeout(timeout);
	showNextNewsRSSItem();
	
	return false;
});

//	Start showing ze itemz!
$.get("includes/opinion.php", null, function(items) {
	newsRSSitems = $.parseJSON(items);
	showNextNewsRSSItem();
});

});

