$(function()
{
	/*
	   ---------------------------------------------------------------------------- 
	   ** equalize the heights of the footer blocks and the aside blocks
	   ---------------------------------------------------------------------------- 
	*/

	equalize("aside.site .equalize");
	equalize("footer.site .equalize");
	equalize("section.projects .category h3");
	/*
	   ---------------------------------------------------------------------------- 
	   ** resize the footer height too so that the middle vertical dashed border 
	   ** extends to the height of the window
	   ---------------------------------------------------------------------------- 
	*/
	var viewportHeight = $(window).height();
	var headerHeight = $('header.site').height();
	var sectionHeight = $('section.page').height();
	var footerHeight = $('footer.site .equalize').height();
	var totalHeight = headerHeight + sectionHeight + footerHeight;
	if (viewportHeight > totalHeight)
	{
		var diff = viewportHeight - totalHeight;
		var newFooterHeight = footerHeight + diff;
		$('footer.site .equalize').height(newFooterHeight);
	}
	/*
	   ---------------------------------------------------------------------------- 
	   ** when you resize the window, resize the footer height too so that the 
	   ** middle vertical dashed border extends to the height of the window
	   ---------------------------------------------------------------------------- 
	*/
	$(window).resize(function() { 
		var viewportHeight = $(window).height();
		var headerHeight = $('header.site').height();
		var sectionHeight = $('section.page').height();
		var footerHeight = $('footer.site .equalize').height();
		var totalHeight = headerHeight + sectionHeight + footerHeight;
		if (viewportHeight > totalHeight)
		{
			var diff = viewportHeight - totalHeight;
			var newFooterHeight = footerHeight + diff;
			$('footer.site .equalize').height(newFooterHeight);
		}
	});	
	/*
	   ---------------------------------------------------------------------------- 
	   ** wraps nav links with a span to style a bottom border on hover
	   ---------------------------------------------------------------------------- 
	*/
	$('header.site nav .top a, footer.site nav a').wrapInner('<span>');
	/*
	   ---------------------------------------------------------------------------- 
	   ** adds a span to a button if it needs an arrow
	   ---------------------------------------------------------------------------- 
	*/
	$('a.button.arrow.right').append('<span></span>');
	$('a.button.arrow.left').prepend('<span></span>');
	$("a.button, button.button").hover(
		function()
		{
			$(this).stop().animate({
				'background-color':'#5f5f5f'
			}, 250);
		},
		function()
		{
			if ($(this).hasClass('blue'))
			{
				$(this).stop().animate({
					'background-color':'#4482d0'
				}, 250);
			}
			else if ($(this).hasClass('grey'))
			{
				$(this).stop().animate({
					'background-color':'#808080'
				}, 250);
			}
			else
			{
				$(this).stop().animate({
					'background-color':'#434343'
				}, 250);
			}
		}
	);
	/*
	   ---------------------------------------------------------------------------- 
	   ** main nav mega drop down
	   ---------------------------------------------------------------------------- 
	*/
	$("header.site nav li").hoverIntent(
		function()
		{
			$(this).addClass('hover').find('.dropdown').removeClass('acc');
		},
		function()
		{
			$(this).stop().removeClass('hover').find('.dropdown').addClass('acc');
		}
	);
	$(".dropdown li a").hover(
		function()
		{
			$(this).stop().find('.rollover').fadeTo(100, 0.999999);
			$(this).stop().find('.more').fadeTo(100, 0.999999);
		},
		function()
		{
			$(this).stop().find('.more').fadeTo(100, 0);
			$(this).stop().find('.rollover').fadeTo(100, 0);
		}
	);
	$("nav.panel-nav li:first-child").addClass('active');
	var firstBg = '#'+$(".panels .panel:first-child").attr('data-item-color');
	$('article.entry').css({'background-color':firstBg});
	/*
	   ---------------------------------------------------------------------------- 
	   ** sets a default input value based on the title attribute from the field
	   ---------------------------------------------------------------------------- 
	*/
	defaultInputValue = '';
	var $inputs = $('input[type="email"], input[type="text"]');
	$inputs.each(function(i)
	{
		var thisValue = $(this).getValue();
		if (thisValue == "")
		{
			var thisTitle = $(this).attr('title');
			$(this).attr('value', thisTitle);
		}
	});
	/*
	   ---------------------------------------------------------------------------- 
		** on focusing an input text field, set the default variable to the initial 
		** value and clear the field
	   ---------------------------------------------------------------------------- 
	*/
	$('input[type="email"], input[type="text"]').focus(function()
	{
		currentInputValue = $(this).attr('value');
		defaultInputValue = $(this).attr('title');
		if (currentInputValue == defaultInputValue)
		{
			$(this).attr('value', '');
		}
	});
	/*
	   ---------------------------------------------------------------------------- 
		** on blurring the field, check to see if the user has entered legit value
		** if not, return the value of the field to the initial default value; if 
		** so, do nothing
	   ---------------------------------------------------------------------------- 
	*/
	$('input[type="email"], input[type="text"]').blur(function()
	{
		currentInputValue = $(this).attr('value');
		if (currentInputValue == '')
		{
			$(this).attr('value', defaultInputValue);
		}
		defaultInputValue = '';
	});
	/*
	   ---------------------------------------------------------------------------- 
		** animate the social icon backgrounds in footer
	   ---------------------------------------------------------------------------- 
	*/
	 $(".social a").hoverIntent(
		function()
		{
			$(this).stop().animate({
				'background-color':'#b4b4b4'
			}, 100);
		},
		function()
		{
			$(this).stop().animate({
				'background-color':'#7c7c7c'
			}, 100);
		}
	);
	/*
	   ---------------------------------------------------------------------------- 
		** animate the blue rollover states on the related blog post thumbnails
	   ---------------------------------------------------------------------------- 
	*/
	$("aside.related li a").hover(
		function()
		{
			$(this).find('.link').stop().animate({
				'background-color':'#5f5f5f'
			}, 100);
			$(this).stop().find('.rollover').fadeTo(100, 0.999999);
		},
		function()
		{
			$(this).find('.link').stop().animate({
				'background-color':'#434343'
			}, 100);
			$(this).stop().find('.rollover').fadeTo(100, 0);
		}
	);	
	
	$("section.search form").submit(function()
	{
		var keywords = $(this).find('input[type="text"]').getValue();
		if ((keywords == 'search') || (keywords == ''))
		{
			return false;
		}
	});
	
});
