// This function enables us to load the main div of one page into another using AJAX (so that videos don't have to stop

// This function attaches the onclicks, once the page has loaded
 $(document).ready(function(){
 	//Make sure all our active <li>s have a child link. If they don't let's make one.
	if($("#bbt_menu2 li.active a").size()==0 && $("#bbt_menu2 li.active").size()==1)
	{
		var thisPage = window.location.href;
		$("#bbt_menu2 li.active").contents().wrap('<a href="'+thisPage+'"></a>');
	}
	
	$("#bbt_menu2 a").click(function(event){
		
		// Speed of fade in/fade out
		var fadeTime = 200
		
		// Remove active class from all <li>s
		$("#bbt_menu2 li").removeClass("active")
		
		// Get our links parent <li> and add "active" class to it
		$(this).parent().addClass("active");

		// Using callbacks below so our fades don't happen before we've swapped our content
		
		
		// Fade out the DIV
		$("#main").fadeOut(fadeTime, function(){
			// Do our AJAX cleverness
			// Could have just used $("#main").load(this.href +" #main") in a different context
			var link = $("#bbt_menu2 li.active a")[0].href;
			$("#main").load(link +" #main", function(){
				// Do our fadeIn
				$("#main").fadeIn(fadeTime);
			});	
		});
		
		
		// Stop the actual link being followed
		event.preventDefault();
	});
})