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");
    }
  });
} 

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

function cycleTopImages() {
  $('#home-headerimg .head-img:last').fadeOut(5000, function(){
    $(this).clone().prependTo('#home-headerimg').show();
    $(this).remove();
    cycleTopImages();
  });
}
//
// On Document Ready...
//
// ...roll over code for images
// 
$(document).ready(function() {
 
   // load the hover images
   preloadHoverImages();
   
   // load the images for the detail page
   preloadDetailImages();
   
   // load rotating images effect
  cycleTopImages();
   
   // 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"));
       }
     }
   );
   
   
   $('.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 #074045');
      $('.archives ul li:not(.top)').addClass('minus3top');
    }
    else
    {
      $('.archives ul').addClass('height39');
      $('.archives ul li:not(.top)').css('display', 'none');
      $('.archives ul').css('border-bottom', 'none');
      $('.archives ul li:not(.top)').removeClass('minus3top');
    }
    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');
      $('.archives ul li:not(.top)').removeClass('minus3top');
  });
});