var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline=0;
var list_count;
var list_interval;
var old_list = 0;
var current_list=0;

$(document).ready(function(){
  headline_count = $("div.hmpg_tab_image").size();
  $("div.hmpg_tab_image:eq("+current_headline+")").css('top','0px');
  
  headline_interval = setInterval(headline_rotate,5000); //time in milliseconds

});

function headline_rotate() {
  current_headline = (old_headline + 1) % headline_count; //remainder will always equal old_headline until it reaches headline_count - at which point it becomes zero. clock arithmetic
  $("div.hmpg_tab_image:eq(" + old_headline + ")").animate({top: -316},"fast", function() {$(this).css('top','321px');});
  $("div.hmpg_tab_image:eq(" + current_headline + ")").show().animate({top: 0},"fast");  
  old_headline = current_headline;
}


$(document).ready(function(){
  list_count = $("div.hmpg_tabs").size();
  $("div.hmpg_tabs:eq("+current_list+")").addClass("selected");
  
  list_interval = setInterval(list_rotate,5000); //time in milliseconds

});

function list_rotate() {
  current_list = (old_list + 1) % list_count; //remainder will always equal old_headline until it reaches headline_count - at which point it becomes zero. clock arithmetic
  $("div.hmpg_tabs:eq(" + old_list + ")").removeClass("selected");
  $("div.hmpg_tabs:eq("+current_list+")").addClass("selected");
  old_list = current_list;
}
