// remap jQuery to $
(function($){})(window.jQuery);

/* trigger when page is ready */
$(document).ready(function (){

	// Fancybox
	$("a.fancybox,.gallery-item a").fancybox({
		'titlePosition':'inside'
	});

	// Stylistic Updates for non-modern browsers (these changes are done
	// with CSS, but older browsers won't see it)
	// -------------------------------------------------------------------
	$('.blog-post:last-child').addClass('last');
	
	// Medium & Small Galleries
	// -------------------------------------------------------------------
	
	var mediumBlocks = $('.medium-gallery a');
	
	// Medium & Small Gallery Hovers
	$(mediumBlocks).hover(function(){
		$(this).addClass('rotated');
		$(this).find('.img-title').stop().animate({'left':57},350,'easeOutExpo');
		$(this).find('.img-cap').stop().animate({'bottom':-40},350,'easeOutExpo');
	},function(){
		$(this).removeClass('rotated');
		$(this).find('.img-title').stop().animate({'left':0},350,'easeOutExpo');
		$(this).find('.img-cap').stop().animate({'bottom':0},350,'easeOutExpo');
	});
	
	var smallBlocks = $('.small-gallery a');
	
	// Medium & Small Gallery Hovers
	$(smallBlocks).hover(function(){
		$(this).stop().animate({'opacity':0.5},650,'easeOutQuad');
		$(this).find('.img-corner').stop().animate({'bottom':-18},350,'easeOutExpo');
	},function(){
		$(this).stop().animate({'opacity':1},350,'easeOutExpo');
		$(this).find('.img-corner').stop().animate({'bottom':0},350,'easeOutExpo');
	});
	
	// Text Fields & Search
	// -------------------------------------------------------------------
	
	// Text field clearing on focus
	$('.blink').focus(function(){
		if( $(this).val() == $(this).attr('title') ) {
			$(this).val('');
		}
	}).blur(function(){
		if( $(this).val() == '' ) {
			$(this).val( $(this).attr('title') );
		}
	});
	
	// Search field expanding on focus
	$('.search').focus(function(){
		$(this).animate({'width':180},300,'easeInOutQuad');
	}).blur(function(){
		$(this).animate({'width':120},300,'easeInOutQuad');
	});
	
	// Blockquote Styling
	$('blockquote').wrapInner('<div class="inner" />');
	
	// Table Styling
	$('article table tr:last').addClass('last');
	$('article table tr').each(function(){
		$('td:last', this).addClass('last');
	});
	$('article table tr:even').addClass('even');
	
	// Dropdowns
	// -------------------------------------------------------------------
	
	$('nav ul li').hover(function(){
		$(this).find('a:first-child').addClass('hover');
		$(this).find('ul.sub-menu').fadeIn('fast');
	},function(){
		$(this).find('a:first-child').removeClass('hover');
		$(this).find('ul.sub-menu').hide();
	});
	
	
});
