function enable_menu_item(item) {
	$(item).addClass('active_menu');

	if ($(item).parent().parent().parent().attr('id') != 'navigation') {
		$(item).parent().parent().parent().find('a:first').addClass('active_menu');
		$(item).parent().parent().show();
	}
	else {
		$(item).parent().find('ul').show();
	}
}

$(function() {
	//
	// Ensure the correct menu items are highlighted
	//
	$('#navigation ul li ul').hide();

	var menu_items = $('#navigation a');

	var current_menu_item = menu_items.filter(function () {
		return this.href == location.href;
	});

	if (current_menu_item.length == 1) {
		enable_menu_item(current_menu_item);
	}
	else {
		var meta_menu = $('meta[name="active_menu"]');

		if (meta_menu.length == 1) {
			var current_menu_item = menu_items.filter(function () {
				return this.href == meta_menu[0].content;
			});

			if (current_menu_item.length == 1) {
				enable_menu_item(current_menu_item);
			}
		}

		// Disabled since it could cause odd menus to be activated depending on the referrer.
		// This code is being retained for future reference, but not expected to be used here.
		//
		// var current_menu_item = menu_items.filter(function () {
		// 	return this.href == document.referrer;
		// });
		// 
		// if (current_menu_item.length == 1) {
		// 	enable_menu_item(current_menu_item);
		// }		
	}
	
	//
	// Ensure the page content is tall enough to avoid issues if there is not enough content on the page.
	//
	var navigation = $('#navigation');
	var content = $('#content');
	
	if (content.height() < navigation.height()) {
		content.height(navigation.height());
	}	
});
