$(document).ready(function() {
  var body = $("body");
  body.addClass("javascript");
  
  var rows = $("tbody tr");
  
  // Add hover class to table rows
  rows.hover(
    function() {$(this).addClass("hover");},
    function() {$(this).removeClass("hover");}
  );
  
  // Turn the entire tr into a link based on the A embedded
  rows.click(function() {
    var link = $(this).find("a");
    window.location = link.attr("href");
  });
  
  // Insert extra divs to be animated
  var overlay = $('<div id="overlay">&nbsp;</div>');
  body.append(overlay);
  
  var headerIDs = ["001", "002", "003", "004", "005", "006"];
  var headers   = [];
  for (var i=0; i < headerIDs.length; i++) {
    var header = $('<div class="header" id="header-' + headerIDs[i] + '">&nbsp;</div>');
    if (i != 0) header.css({width: 0});
    headers.push(header);
    body.append(header);
  };
    
  // Cycle through the header images
  var current = 0;
  var length = headers.length - 1;
  var cycle = function() {
    var next = (current < length ? current + 1 : 0);
    headers[current].animate({width: 0}, 200);
    headers[next].animate({width: "100%"}, 200);
    current = next;
    window.setTimeout(cycle, 8000);
  };
  
  $(window).load(function() {
    window.setTimeout(cycle, 3000);
  });
});
