$(document).ready(function() {
	if ( $("div#front-page").length > 0 ) { 
		$('#front-page').append('<span id="recentposts-hover">&nbsp;</span>');
	}
	$('#mainNav ul li a').navbuttons();
	
	$('header h1').toggle(function() {
		$('body').addClass('grid');
	}, function() {
		$('body').removeClass('grid');
	});

	// Lightbox
	$('a[rel*=lightbox]').addTitle();
	$('a[rel*=lightbox]').lightBox();

	
});


(function($) {
// Hover in and out the nav	
$.fn.navbuttons = function() {
	
	
  return this.each(function() {
    $(this).hover(function() {
    	$(this).animate({'opacity': '1'}, '400');
		if ( $("div#front-page").length > 0 ) { 
				$.fn.navbuttons.classandshow($(this).parent('li').attr('class'));
		}
		
    }, function() {
    	$(this).animate({'opacity': '0'}, 'normal');
		if ( $("div#front-page").length > 0 ) {
			$.fn.navbuttons.removeclassandhide();
		}
    });
	});


};
// define our format function
$.fn.navbuttons.classandshow = function(giveclass) {
  $('#recentposts-hover').addClass(giveclass).animate({'opacity': '1'}, 'normal');
};
$.fn.navbuttons.removeclassandhide = function(takeclass) {
  $('#recentposts-hover').animate({'opacity': '0'}, 'fast', function() {
    $(this).removeClass(takeclass);
  })
};
})(jQuery);


;(function($) {
// Add title to the lightbox link
$.fn.addTitle = function() {


  return this.each(function() {
    var $this = $(this);
	title = $this.children('img').attr('alt');
	// console.log(title);
	$this.attr('title', title);

  

  });
};



})(jQuery);



