var section = 'index';
var oldSection = null;
var atHome = true;
var welcomeContent;
var navContent;

function urlRouter(currentFile) {
	if(section) oldSection = section;
	section = currentFile;
	if(section != 'index' && atHome == true ) destroyHome();
	if(section == 'index') createHome();

	$("#logo").fadeOut(1000, function(){
	
		$("#loadZone").html('');
		
		$("#logo").fadeIn(1400);
		
		if(section != 'index'){
			$("#loadZone").load(currentFile+'.html', function() {
				$("#loadZone").fadeIn(1400);
			});
		}	
		
	});

	$("#loadZone").fadeOut(1000, function(){

		
	});
	
	$('ul#smallNav').find('li').removeClass('active');
	$('ul#smallNav').find('li').animate({opacity: .5},1000);

	if(oldSection != 'index') setSection();

	return false;
}
function setSection () {
	if(section != 'index') {
		$('ul#smallNav').find('li a.'+section).parent().animate({opacity: 1},1000);
		$('ul#smallNav').find('li a.'+section).parent().addClass('active');
	}
}

function destroyHome() {
	atHome = false;
	
	//Destroy the main menu
	$('ul#nav').stop(true).fadeOut(1000, function(){
		$('ul#smallNav').show();
		
		if(navContent) navContent.appendTo('#smallNavHolder');
		setSection();
		
		$('ul#smallNav').css({opacity:0});	
		$('ul#smallNav').animate({opacity:1, top: 0}, 600);
	});
	$('#placeholder').stop(true).fadeOut(1000);
	
	//Remove the welcome banner, but save its height
	$('div#welcome').animate({opacity:0, top: 40}, 1000, function(){
		welcomeContent = $('div#welcome').detach();
	})
	
	//Shorten top banner
	$('#header').animate({height:100}, 1000)
	
}

function createHome() {
	atHome = true;

	//Drop the small menu, bring in the main elements
	$('ul#smallNav').animate({opacity:0, top: 20}, 1000, function(){
		navContent = $('ul#smallNav').detach();
		$('ul#nav').fadeIn(1000);
		
		if(welcomeContent) welcomeContent.appendTo('#welcomeHolder');
		$('div#welcome').animate({opacity:1, top: 0}, 1000)
		$('#placeholder').fadeIn(1000);
		$('#header').animate({height:175}, 1000)
	});
}

