// MAIN SCRIPT.JS

$(document).ready(function(){


// PAGE LOAD EFFECTS
	
	$('#main_wrapper').hide().fadeIn(1000);
	
	
// NAVIGATION

	$(function(){
	  
	  // Bind an event to window.onhashchange that, when the hash changes, gets the
	  // hash and adds the class "selected" to any matching nav link.
	  $(window).hashchange( function(){
		
		// Hide all the content divs - hiding all of them instead of just visible ones compensates for really fast clicking
		$('#content').children().fadeOut(350).css({"display":"none"});
		$('.success').hide();
	
		// Set hash to either the current location's hash or, failing that, the id of the first div inside #main-content		
		var hash = window.location.hash || '#' + $('#content :first-child').attr('id');;
		
		// Get the clicked menu item
		var clickedLink = $('#main_links ul li a[href=' + hash + ']');
		
		// Get the class of the clicked menu item	
		var linkClass = clickedLink.attr('class');
		
		// Remove the active class from all the menu items
		$('#main_links ul li a').removeClass('active');
		
		// Add the active class to the clicked item
		clickedLink.addClass('active');
		
		// Show the content div with the same id as the selected menu item's class name
		$(hash).hide().fadeIn(350);
	  
	  
	  	
	  })
	  // Since the event is only triggered when the hash changes, we need to trigger
	  // the event now, to handle the hash the page may have loaded with.
	  $(window).hashchange();
	  
	});

	  
});
