function fetchEntries() {
    $.ajax({
        type: 'GET',
        url: '/ajax/newsticker.php',
        async: true,
		dataType: 'json', 
        success: function(entries) {
			if(entries.length > 0) {
				startNewsticker(entries,0);
			}
        }   
    }); 
}

function startNewsticker(ticker, i) {
    $('#ticker').html(ticker[i]);
    $('#ticker').fadeIn('slow');

	if(ticker.length > 1) {
		setTimeout(function() {
			$('#ticker').fadeOut('slow');
			setTimeout(function() {
				startNewsticker(ticker, ((i+1) % ticker.length));
			}, 500);
		}, 4500);
	}
}

$(document).ready(function() {
	var i = 0;
    $('#ticker').hide();
	fetchEntries();
});

