function mainmenu(){
	var top_nav 						= $("#topnav");	
	var second_nav_children 			= top_nav.siblings('div.subnav'); // Siblings are at same level as parent
	second_nav_children.hide(); 		// Hide all by default
	var active_top_level_article		= top_nav.children('.selected');
	
	if ( active_top_level_article.length > 0 ){
		var active_top_level_article_name 	= active_top_level_article.filter('a').attr('href').split('/')[1];
		var active_subnav					= second_nav_children.filter('.' + active_top_level_article_name);
		active_subnav.show();
		
		// Move subnav into the centre of the screen
		active_subnav.css('margin-left', ( top_nav.outerWidth() - active_subnav.outerWidth() ) / 2);		
	}
}

$(document).ready(function(){					
	mainmenu();
});
