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 equalHeight(group) {
  tallest = 0;
  group.each(function() {
    thisHeight = $(this).height();
    if(thisHeight > tallest) {
      tallest = thisHeight;
    }
  });
  group.height(tallest);
}

//
// On Document Ready...
//
// ...roll over code for images
//
$(document).ready(function() {
 
   // load the hover images
   preloadHoverImages();

   // load the images for the detail page
   preloadDetailImages();

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

   // NAVIGATION

   // generating sprites for navigation
   generateSprites(".nav", "current-", true, 300, "fade");

   // "cleanup" of email addresses
   $("a").each(function() {
     var href = $(this).attr("href");
     if (href && href.indexOf(" [at] ") > 0) {
       href = href.replace(/ \[at\] /, "@");
       $(this).attr("href", href);
     }
   });


   //Clear default text from text box when clicked
   $('#header .member-login input').focus(function(){
    var defaultText = $(this).val();
    $(this).val('');
   });


   // Clear default text from text box when clicked 
   $('#leftnav-col input').focus(function(){
     var defaultText = $(this).val();
     if(defaultText == 'Search Articles'){
       $(this).val('');
     }
   });

});

$(window).load(function() {
  equalHeight($(".eq-height"));
});
