// JavaScript Document
// Author: Kevin Fargason
// Date: 4/13/2009
function getCurrentPageName(){
	var curPath = window.location.pathname; 
	curPage =  curPath.substring(curPath.lastIndexOf('/') + 1);	 //get name of current page
	periodLocation = curPage.indexOf(".");
	var elemID = curPage.substring(0,periodLocation);  //remove file extention from name
	return elemID;
}
function setTopMenu(id){
	$("."+id).addClass('selected');
}
function setMenuPage(){
	var curPage = getCurrentPageName();  //get name of current page with file extention removed
	if ($("#"+curPage).length > 0 ){      //check if the page is listed in the left menu (check anchor tag IDs)
		$("#"+curPage).addClass('selected'); //set the correct left menu element to class 'selected'
		updateSidebar(curPage);
		setParents(curPage);  //set the correct top menu item to active
		
		//bubbleUpMenu()
	}else{ //if page is not listed in the menu, find which menu item it is a decentant of
		bubbleUpMenu();
	}
}
function bubbleUpMenu(){  //this will bubble up the menu and set the correct elements to selected
		var curPath = window.location.pathname;  //get path in url
		var found = 'n';
		var i = 0;
		while(found == 'n'){ //loop up through folder structure looking for matching menu items
		curPath =  curPath.substring(0,curPath.lastIndexOf('/')) //trim off file name
		if(curPath.length > 0){
			curLevel =  curPath.substring(curPath.lastIndexOf('/') + 1);	 //get name of current directory level
			if ($("#"+curLevel).length > 0 ){		//check if the page is listed in the left menu
				$("#"+curLevel).addClass('selected');//set the correct left menu element to class 'selected'
				found = 'y';
				setParents(curLevel);  //set the correct top menu items to active
			}
		}else{found = 'y';}
		}
}
function setParents(curLevel){	
	var i=0;
	var foundParent = 'n';
	var parentElement = '';
	var classOrID = "#";
	var topID = "";


	var anchorParentClass = $("#"+curLevel).parent().attr("class");
	if(anchorParentClass == "level-four"){ // we are on a submenu, so set parent level and top menu to selected
		$("#"+curLevel).parent().addClass('selected'); //set level-four li to selected
		$("#"+curLevel).parent().parent().addClass('selected'); //set level-three ul to selected
		$("#"+curLevel).parent().parent().parent().addClass('selected'); //set level-two li to selected
		$("#"+curLevel).parent().parent().parent().children("a").addClass('selected'); //this sets the level-two anchor to selected
		$("#"+curLevel).parent().parent().parent().parent().addClass('selected');// sets the level-one ul to selected
		
		topID = $("#"+curLevel).parent().parent().parent().parent().attr("id"); //get id of level-one ul 
		setTopMenu(topID); //use id to activate corresponding top menu item
		
		imageID = $(classOrID+curLevel).parent().parent().parent().children("a").attr("id");
		updateSidebar(imageID); //this function is in sidebar.js.  it set the appropriate image according to the subsection
	}else{ //otherwise we are on level-two
		$("#"+curLevel).parent().addClass('selected');	 //set level-two li to selectd
		$("#"+curLevel).parent().parent().addClass('selected'); //set level-one ul to selected
		updateSidebar(curLevel); //this function is in sidebar.js.  it set the appropriate image according to the subsection
		
		topID = $("#"+curLevel).parent().parent().attr("id"); //get id of level-one ul  
		setTopMenu(topID); //use id to activate corresponding top menu item
	
	}	
}

$(document).ready(function(){
	setMenuPage();
	disableImageContextMenus();
});