$(document).ready(function()
	{
		// Placeholder plugin for non-compliant browsers
		if($.fn.placeholder){
			$('input[placeholder]').placeholder();
		}
		
		// Simple animation for #top links
		$('a[href="#top"]').click(function(){
			$('html, body').animate(
				{ scrollTop:0 }, 500
			);
			return false;
		});
					
		// Make external links open in new windows	
		$('a').each(function(){
			if (this.href.match('^https?://(?!'+document.location.hostname+')')) {
				this.target = '_blank';
			}
		});
		
		// Add Analytics tracking to PDFs
		$('a[href$=".pdf"]').click(function(){
				_gaq.push(['_trackEvent', 'PDF', $(this).attr("href")]);
		});
		
		// Navigation
		if($.fn.hoverIntent){
			$("#nav li").hoverIntent(showMenu, hideMenu);
		}
		function showMenu(){
			$(this).addClass('hover');
			$("ul", this).fadeIn('fast');
		}
		function hideMenu(){
			current = $(this);
			$("ul", this).fadeOut('fast', function(){$(current).removeClass('hover')});
		}	


		// Updates toggling
		
		$('ul#homeUpdates div.updateFull').hide();
		$('ul#homeUpdates div.updateSummary').show();
		$('ul#homeUpdates h3 span').addClass('toggle');
		
		$('ul#homeUpdates h3 span').click(function(){
			$(this).toggleClass('expanded');
			scope = $(this).parents('li');
			$('div.updateSummary', scope).toggle();
			$('div.updateFull', scope).toggle();
		});

		// General toggling
		$('.toggle-content').hide();
		$('ul.toggle h3 span').addClass('toggle');
		
		$('ul.toggle h3 span').click(function(){
			$(this).toggleClass('expanded');	
			$(this).parent('h3').next('.toggle-content').toggle();
		});
		
		// Toggle content based on the URL hash
		if ( document.location.hash.length > 0 ) {
			section = document.location.hash;
			$('ul.toggle li' + section + ' h3 span').addClass('expanded');
			$('ul.toggle li' + section + ' .toggle-content').show();
		}
		
		$('.more-content').hide();
		$('.more-link').click(function(){
			$(this).parent('p').hide().next('.more-content').fadeIn();
			return false;
		});
		
		$('a.back').click(function(){
			history.go(-1);
			return false;
		});
	
			
	}
);
