$(document).ready(function () {
    if ($('.newsPanel li')) {
        $('.newsPanel li').hide();
        $('.newsPanel li:first').show();
        setInterval('loop()', 6000);
    }
});

function loop() {
	var current = ($('.newsPanel li.on')? $('.newsPanel li.on') : $('newsPanel li:first')); //check if any 'li' has 'on' class, if not, grab the first 'li'
	var next = ((current.next().length) ? ((current.next().hasClass('caption'))? $('.newsPanel li:first') : current.next()) : $('.newsPanel li:first')); //get next 'li', if it reached the end of the list, rotate it back to the first news
	//the animation
	current.fadeOut('slow', function() {
		$(this).removeClass('on');
		next.fadeIn('slow', function() {$(this).addClass('on');});
	});
}
