var headline2_count;
var headline2_interval;
var old_headline2 = 0;
var current_headline2=0;

$(document).ready(function(){
  headline2_count = $("div.headline2").size();
  $("div.headline2:eq("+current_headline2+")").css('top','5px');
  
  headline2_interval = setInterval(headline2_rotate,5000); //time in milliseconds
  $('#scrollup_features').hover(function() {
    clearInterval(headline2_interval);
  }, function() {
    headline2_interval = setInterval(headline2_rotate,5000); //time in milliseconds
    headline2_rotate();
  });
});

function headline2_rotate() {
  current_headline2 = (old_headline2 + 1) % headline2_count; //remainder will always equal old_headline2 until it reaches headline2_count - at which point it becomes zero. clock arithmetic
  $("div.headline2:eq(" + old_headline2 + ")").animate({top: -245},"slow", function() {
    $(this).css('top','250px');
    });
  $("div.headline2:eq(" + current_headline2 + ")").show().animate({top: 5},"slow");  
  old_headline2 = current_headline2;
}