/* ------------------------------------------------------

    Author:   Pat Heard
    Purpose:  Adds the hover overlay for lightbox thumbs
    URL:      http://fullahead.org

   ------------------------------------------------------ */

jQuery(document).ready(function($){

  // Create the mouseover magnifying glass
  var overlay = $('<div id="lightbox-overlay"/>');  
  
  if($.support.opacity){
    overlay.css({'opacity': 0});
  } else {
    overlay.hide();
  }
  
  
  $('#content').append(overlay);

  // Loop through all images with a rel=lightbox
  $("a[rel*=lightbox] img").each(
    function(){
      $(this).hover(      
        function(){
          overlay.stop(); 
          
          // Adjust for the image being inside a <td>
          var tdAdjust = $(this).parents('td').length > 0 ? 10 : 0;
          
          var pos = $(this).position()
          overlay.css({
            'left': pos.left + $(this).width() - 40 + tdAdjust,
            'top': pos.top + $(this).height() - 40
          }); 
          
          // Check if the browser supports opacity fade on a .png
          if($.support.opacity){
            overlay.css({'opacity': 0}); 
            overlay.fadeTo(200, 1);
          } else {
            overlay.show();
          }
        },
        function(){
          overlay.stop();
          if($.support.opacity){
            overlay.fadeTo(200, 0);
          } else {
            overlay.hide();
          }          
    
        }   
      );  
    }
  );
});

