/* ------------------------------------------------------

    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();
          }          
    
        }   
      );  
    }
  );
  
  // Home page description behaviour
  $('#content .featured').each(  
    
    function(){
    
        
        var overlay = $(this).find('.post-content');        
        if(overlay){
            var origHeight = overlay.height();
            overlay.css({'opacity': 0, 'visibility': 'visible', 'height': 0});

            $(this).hover(
                function(){
                    overlay.stop();                
                    overlay.animate({'opacity': 0.8, 'height': origHeight});
                    overlay.slideDown();
                },
                function(){
                    overlay.stop();
                    overlay.animate({'opacity': 0, 'height': 0});
                }        
            );    
        }
    }
  );
  

  
  // Comment link that shows the comment form
  $('#comment-link a').click(function(){
  
    var comments = $('#comments');
    if(comments){
        comments.show();
    }
    
  });
  
  
  // Archive/category pages
  $('#thumb-links li').each(function(){
  

    var title = $(this).find('span');    
    if(title && title.text().length > 0){
        var origHeight = title.height();
        title.css({'opacity': 0, 'height': 0, 'visibility': 'visible'});

        // Mouseover events
        $(this).hover(    
            function(){
                title.stop();
                title.animate({'opacity': 0.8, 'height': origHeight}, 250);
            },
            function(){
                title.stop();
                title.animate({'opacity': 0, 'height': 0}, 250);
            }    
        );
    }
    
  });
  
});

(function($) {

    $(window).load(function() {
	  // Home page collage
	  var $homeLink = $('#home-collage');
	  if($homeLink.length > 0){	  
		  
		  // Get the image, it's original dimensions and the amount to grow by
		  var $img = $homeLink.find('img');		  
		  var w = $img.width();
		  var h = $img.height();		  
		  var wGrow = w * 0.1;
		  var hGrow = h * 0.1;	  
		  
		  // Set the image to position absolute in its link container (so as not to affect other element positions)
		  $homeLink.css({display: 'block', position: 'relative', height: h});
		  $img.css({position: 'absolute', top: 0, left: 0});

		  // mouseover/out of the link
		  $homeLink.hover(
			function(){
				$img.stop().animate({
					width: w + wGrow, 
					height: h + hGrow, 
					top: wGrow/2 * -1, 
					left: hGrow/2 * -1
				}, {
					duration: 200
				});
			},
			function(){
				$img.stop().animate({
					width: w, 
					height: h, 
					top: 0, 
					left: 0
				}, {
					duration: 200
				});
			}
		  );	
	  }
    });

})(jQuery);  

