// JavaScript Document
var headline_count = 0;
var headline_interval = 0;
var old_headline = 0;
var current_headline = 0;

$(document).ready(function(){
  $.ajax({
        type: "POST",
        url: "./news.xml",
        dataType: "xml",
        success: function(xml) {
            $(xml).find('news').each(function(){
                var id = $(this).attr('id');
                var contenu = '<div class="news">'+$(this).find('contenu').text()+'</div>';
                var date = $(this).find('date').text();
                $(contenu).appendTo("#scrollup");
				headline_count++;
			});
        }
    });
  
  $("div.news:eq("+current_headline+")").css('top','5px');
  
  headline_interval = setInterval(headline_rotate,7000); //time in milliseconds
});

function headline_rotate() {
  current_headline = (old_headline + 1) % headline_count; 
  $("div.news:eq(" + old_headline + ")").animate({top: -305},1500, function() {
    $(this).css('top','310px');
    });
  $("div.news:eq(" + current_headline + ")").show().animate({top: 5},1500);  
  old_headline = current_headline;
}