 
jQuery(document).ready(function()
{
	var internetExplorer = jQuery.browser.msie;
	var opera = jQuery.browser.opera;
	

	
	// Takes off fixed positioning if the window is too small to stop the nav covering the text
	var navTopPosition = parseFloat(jQuery('.content:first').height()) + 21; 
	
	function checkNavigationPosition()
	{
		var windowWidth = jQuery(window).width();
		if (windowWidth < 1004)
		{
			jQuery('#navigation').addClass('absolute').css('bottom', navTopPosition);	
			jQuery('#previous-design').addClass('hidden');
		}
		else
		{
			jQuery('#navigation').removeClass('absolute');
			jQuery('#previous-design').removeClass('hidden');
		}
	}
	checkNavigationPosition();
	jQuery(window).resize(function() { checkNavigationPosition(); });



	// Fading hover effect on icons and navigation
	if (!internetExplorer && !opera)
	{
		jQuery('head').append('<style type="text/css">.content acronym:hover { background-position: 100% 3px; } #navigation ul li#nav-portfolio a:hover, #navigation ul li#nav-portfolio a:focus { background-position: 0 0px; } #navigation ul li#nav-about-me a:hover, #navigation ul li#nav-about-me a:focus { background-position: -91px 0px; } #navigation ul li#nav-resume a:hover, #navigation ul li#nav-resume a:focus { background-position: -179px 0px; } #navigation fieldset dl dd { filter: alpha(opacity=60); -moz-opacity: 0.6; -khtml-opacity: 0.6; opacity: 0.6; } #navigation fieldset dl dd.button { filter: alpha(opacity=100); -moz-opacity: 1.0; -khtml-opacity: 1.0; opacity: 1.0; } #navigation fieldset dl dd.button button:hover, #navigation fieldset dl dd.button button:focus { background-position: -253px 0; } </style>');
		
		function fadeInSpan(getLink)
		{
			jQuery(getLink).append('<span class="hover"><!-- --></span>')
			var $span = jQuery('> span.hover', getLink).css('opacity', 0);
			jQuery(getLink).hover(function () { $span.stop().fadeTo(500, 1); }, function () { $span.stop().fadeTo(500, 0); });
		}
		
		jQuery('.content acronym').each(function () { fadeInSpan(this); });
		jQuery('#navigation fieldset dl dd.button button').each(function () { fadeInSpan(this); });		
		jQuery('#navigation ul li a').each(function ()
		{
			if (jQuery(this).attr('class') != 'selected') { fadeInSpan(this); }
		});
		
	}


	
	// Tooltips
	if (!internetExplorer)
	{
		jQuery('body').append('<div id=\"tooltip\"><p></p><div id=\"tooltip-bottom\"><!-- --></div></div>');
		var timer;
		
		function fadeInTooltip(getTooltip)
		{
			clearTimeout(timer);
			
			jQuery('#tooltip').stop(true, true);
			jQuery('#tooltip p').html('');
			jQuery('#tooltip').removeClass('visible');
			
			if(jQuery(getTooltip).attr("title") != "")
			{
				jQuery('#tooltip p').html(jQuery(getTooltip).attr('title'));
				jQuery(getTooltip).removeAttr('title');
				var position = jQuery(getTooltip).offset();
				jQuery('#tooltip').css({ top: position.top+30, left: position.left-170 }).fadeIn('300').addClass('visible');
			}	
		}
		
		function fadeOutTooltip(getTooltip)
		{
			var tooltip = jQuery('#tooltip p').html();
			if (tooltip != '')
			{
				jQuery(getTooltip).attr('title', tooltip);
				jQuery('#tooltip').fadeOut('50').removeClass('visible');
			}
			timer = window.setTimeout(function() { jQuery('#tooltip').css('display', 'none'); }, 500);
		}
		
		jQuery('#shadows a').mouseover(function() { fadeInTooltip(this); }).mouseout(function() { fadeOutTooltip(this); });
		jQuery('#shadows acronym').mouseover(function() { fadeInTooltip(this); }).mouseout(function() { fadeOutTooltip(this); });
	}
	$(window).blur(function() { jQuery('#tooltip').css('display', 'none'); });
	
	
	
	// Forms
	jQuery('#contact dl dd').each(function()
	{
		if (jQuery(this).children('textarea'))
		{
			var textArea = jQuery(this).children('textarea').val();
			if (textArea == '') { jQuery(this).addClass('no-input'); }
		}
		if (jQuery(this).children('input'))
		{
			var textField = jQuery(this).children('input').val();
			if (textField == '') { jQuery(this).addClass('no-input'); }
		}
	});
	
	jQuery('#contact dl dd textarea').focus(function()
	{
		jQuery(this).parent().children('label').animate({'left': '-94'}, 'fast');
		jQuery(this).parent().removeClass('no-input');
	}).blur(function()
	{
		var textArea = jQuery('#contact dl dd textarea').val();
		if (textArea == '')
		{
			jQuery(this).parent().children('label').animate({'left': '10'}, 'fast');
			jQuery(this).parent().addClass('no-input');
		}
	});
	
	jQuery('#contact dl dd input').focus(function()
	{
		jQuery(this).parent().children('label').animate({'left': '-94'}, 'fast');
		jQuery(this).parent().removeClass('no-input');
	}).blur(function()
	{
		var textField = jQuery('#contact dl dd input').val();
		if (textField == '')
		{
			jQuery(this).parent().children('label').animate({'left': '10'}, 'fast');
			jQuery(this).parent().addClass('no-input');
		}
	});
	
	
	
	// Open and close preview images
	var shadowHeight = jQuery('#shadows').height();
	jQuery('body').prepend('<div id="full-image"><!-- --></div>\n<div id="overlay"><!-- --></div>');
	function openImage(url)
	{
		jQuery('#full-image').stop();
		jQuery('#overlay').stop();
		
		var scrollY = jQuery(window).scrollTop() + 20;
		var time;
		if (!internetExplorer) { time = 10000; }
		else { time = 800; }

		jQuery('#full-image').css({ top: scrollY+'px', opacity: '0' }).prepend('<img src="'+url+'" alt="" />').animate({ opacity: 100 }, time);
		
		if (!internetExplorer)
		{
			window.setTimeout(function()
			{
				var pageHeight = scrollY+(jQuery('#full-image').height());
				if (shadowHeight > pageHeight) { pageHeight = shadowHeight; }
				jQuery('#overlay').css({ height: pageHeight+'px', opacity: '0' }).addClass('visible').animate({ opacity: 100 }, time);
			}, 500);
		}
	}
	
	function closeImage()
	{
		jQuery('#full-image').stop();
		jQuery('#overlay').stop();
		
		jQuery('#full-image').animate({ opacity: 0 }, 500);
		jQuery('#overlay').animate({ opacity: 0 }, 500);
		
		window.setTimeout(function()
		{
			jQuery('#full-image img').remove();
			jQuery('#overlay').removeClass('visible');
		}, 700);
		
		if (!internetExplorer)
		{
			if (jQuery('#overlay').height() > shadowHeight)
			{
				jQuery('#overlay').height(shadowHeight);
				jQuery(window).scrollTop((jQuery('#full-image').offset().top) - 20);
			}
		}
	}
	
	jQuery('#portfolio dl dt a').click(function() { var url = jQuery(this).attr('href'); openImage(url); return false; });
	jQuery('#portfolio dl dd.image a').click(function() { var url = jQuery(this).attr('href'); openImage(url); return false; });
	
	jQuery('#full-image').click(function() { closeImage(); return false; });
	jQuery('#overlay').click(function() { closeImage(); return false; });
});



// Fonts
Cufon.now();
Cufon.set('fontFamily', 'Caecilia HeavyOsF');
Cufon.replace('#navigation legend');
Cufon.set('fontFamily', 'Caecilia RomanOsF');
Cufon.replace(['#portfolio dl dt', '#portfolio dl dt a:link', '#portfolio dl dt a:hover', '#portfolio dl dt a:visited'], { hover: true });
Cufon.replace('#about-mell blockquote p');