function preloadHoverImages() {
  $("img").each(function() {
  
    var src = $(this).attr("src");
    if(src && src.indexOf("base") != -1) {
    
      var img = new Image();
      img.src = src.replace(/base/, "hover");
    }
  });
} 

$(document).ready(function(){

  cycleTopImages();

  $('.archives ul img').click(function(){
    if($('.archives ul li:not(.top)').css('display') == 'none')
    {
      $('.archives ul').removeClass('height39');
      $('.archives ul li:not(.top)').css('display', 'block');
      $('.archives ul').css('border-bottom', '1px solid #54732c');
    }
    else
    {
      $('.archives ul').addClass('height39');
      $('.archives ul li:not(.top)').css('display', 'none');
      $('.archives ul').css('border-bottom', 'none');      
    }
    return false;
  });
  
  $('body:not(li.top)').click(function(){
    $('.archives ul').addClass('height39');
    $('.archives ul li:not(.top)').css('display', 'none');
    $('.archives ul').css('border-bottom', 'none');
  });
  
  
     // load the hover images
   preloadHoverImages();
   
   // assign the rollover code
   $(".ro").hover(
     function() {
     
       var src = $(this).attr("src");
       if (src) {
         $(this).attr("src", src.replace(/base/, "hover"));
       }
     },
     function() {
     
       var src = $(this).attr("src");
       if (src) {
         $(this).attr("src", src.replace(/hover/, "base"));
       }
     }
   );
  
});

function cycleTopImages() {
  $('.logo .right-img:last').fadeOut(5000, function(){
    $(this).clone().prependTo('.logo').show();
    $(this).remove();
    cycleTopImages();
  });
}
