var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline=0;
var speed = 1500;
var pause = 4000;
var headlines = new Array(); // an array of jQuery objects

$(document).ready(function(){
						   
  // add after-scrollup items below the scroller
/*
  tmp_table = $('#page .content .after-scrollup').html();
  $('#page .content .after-scrollup').remove();
  if (tmp_table != null)
  {
  	$('#page .content #scrollup').after('<table>' + tmp_table + '</table>');
  }*/
						   
  headline_count = $("div.headline").size();

  for (var i = 0; i < headline_count; i++) {
    headlines[i] = $("div.headline:eq("+i+")");
  }

  headlines[current_headline].css('top','5px');

  headline_interval = setTimeout(headline_rotate,pause);
  $('#scrollup').hover(function() {
    clearInterval(headline_interval);
  }, function() {
    headline_interval = setTimeout(headline_rotate,pause);
  });

});

function headline_rotate() {
  
  up();
  down();
  
  
}

function up()
{
	current_headline = (old_headline + 1) % headline_count;
  	headlines[old_headline].animate({top: -17},(speed - 500), function() {
     $(this).css('top','30px');      	
    }); 
}

function down()
{
	headlines[current_headline].show().animate({top: 5},speed, function(){
		old_headline = current_headline;
		headline_interval = setTimeout(headline_rotate,pause);
	});
    
}