// Define the function for preloading images
jQuery.preloadImages = function()
{
  for(var i = 0; i<arguments.length; i++)
  {
    jQuery("<img>").attr("src", arguments[i]);
  }
}

// Define the actions to take on document.ready
$(document).ready(function(){
  
  // Make all links with '#' do nothing
  $("a[href=#]").click(function(event){ event.preventDefault(); });
  
  // Change any pretty photo links to lightboxes
  //$("a[rel^='prettyphoto']").prettyPhoto();
  
  // Update all relevant images with "hover" states
  $("img[data-hover]").each(function(){
    // Create a blur attribute using the current source
    $(this).attr('data-blur', $(this).attr('src'));
    // Preload the hover image
    $.preloadImages($(this).attr('data-hover'));
    // Add a hover-event to the image
    $(this).hover(
      function(){
        $(this).attr('src',$(this).attr('data-hover'));
        },
      function(){
        $(this).attr('src',$(this).attr('data-blur'));  
        }
      );
    });
  
  // Add hover effects to the right nav images
  $("img.right_nav_image").each(function(){
    $(this).animate({opacity:0.9},100);
    $(this).hover(function(){$(this).animate({opacity:1.0},200);},function(){$(this).animate({opacity:0.9},200);});
    });
  
  // Add the dropdown menu effects
  $("#navigation td[data-submenu]").each(function(){
      $(this).hover(
        function(){
          var button_offset = $(this).find('img').offset();
          var button_height = $(this).find('img').height();
          var button_width = $(this).find('img').width();
          $('#'+$(this).attr('data-submenu')).css({
              'z-index':'30001',
              'position':'absolute',
              'width':$(this).width(),
              'display':'block',
              'top':(button_offset.top + button_height),
              'left':button_offset.left
              });
          },
        function(){
          $('#'+$(this).attr('data-submenu')).css('display','none');
          }
        );
    });
  
});