var catalogueExpanded = false;
var standardlineExpanded = false;

function navmenu(){
	$(" #header #menu ").css({top: "70px"}); // correct the positioning here for accessibilty
	$(" ul#standardline-menu ").css({visibility: "hidden"}); // initially hide it
	
	$(" #nav-menu a#catalogue ").click(
		function(){	
			if(!catalogueExpanded) {
				expandCatalogue(true);
			}
			else {
				contractCatalogue();
			}
			return false;
	});	
	$(" #nav-menu a#standardline ").click(
		function(){
			if(!standardlineExpanded) {
				expandStandardLine(true);
			}
			else {
				contractStandardLine();
			}
			return false;
	});	
}	

function expandCatalogue(animate) {
	catalogueExpanded = true;
	if(animate)
		$(" #header #menu ").animate({top: "42px"},{duration: 1000, easing:"easeOutExpo"});			
	else
		$(" #header #menu ").css({top: "42px"});
		
	$(" #nav-menu a#catalogue ").addClass("active");
}

function contractCatalogue() {
	$(" #header #menu ").animate({top: "70px"});
	catalogueExpanded = false;
	standardlineExpanded = false;
	$(" ul#standardline-menu ").css({visibility: "hidden"});
	$(" #nav-menu a#standardline ").removeClass("active");
	$(" #nav-menu a#catalogue ").removeClass("active");
}

function expandStandardLine(animate) {
	standardlineExpanded = true;
	$(" ul#standardline-menu ").css({visibility: "visible"});
	
	if(animate)
		$(" #header #menu ").animate({top: "18px"},{duration: 1000, easing:"easeOutExpo"});	
	else
		$(" #header #menu ").css({top: "18px"});
		
	$(" #nav-menu a#standardline ").addClass("active");
}

function contractStandardLine() {
	$(" #header #menu ").animate({top: "42px"});
	standardlineExpanded = false;
	$(" ul#standardline-menu ").css({visibility: "hidden"});
	$(" #nav-menu a#standardline ").removeClass("active");
}

function expandCurrentNode() {
	var path = window.location.pathname; // get the path name from the URL
	if(path=="/") {
		$("a#home").addClass("active"); // hightlight the homepage link
		return;
	}

	path = path.substring(1); // remove the first /	
	var pathSplit = path.split('/'); // split it
	
	for ( var i in pathSplit )
	{
		__expandCorrectNode(pathSplit[i]);
	}	
	

	// now that we have expanded, highlight the correct node
	$("a#"+pathSplit[pathSplit.length-1]).addClass("active");
}

function __expandCorrectNode(nodename) {
	if (nodename=="catalogues")
		expandCatalogue(false);
	else if (nodename=="standardline")
		expandStandardLine(false);		
}