var selectedItem;//Current Selected menu item
var LIitem;//Selected List item
var firstItem;//First menu item
var t;//Menu timeout

function hideSubmenu(id) {
	t = setTimeout('hideItemWithNoSubmenu()',1000);
}

function hideItemWithNoSubmenu(){
	//if the selecteditem is set, then set it selected.
	if(selectedItem){
		selectedItem.className = "selected";
		if(selectedItem==firstItem)selectFirstItem();
		else deselectFirstItem();
	}
	
	if(LIitem==firstItem&&!selectedItem)deselectFirstItem();
	
	if(LIitem&&LIitem!==selectedItem){
		//if it exists don't highlight it
		LIitem.className = "";
	}
}

function getStartedItem(){
	var lis = document.getElementById('navigationContent').getElementsByTagName("li");
	for(var i=0;i<lis.length;i++){
		//set the first item if its the first occurense of a LI
		if(i==0)firstItem = lis[i];
		//Set selected item if encoutered a list item with the class selected
		if(lis[i].className=="selected"){
			selectedItem = lis[i];
			break;
		}
	}
	//if nothing is slected, give selectedItem a empty object so nothing gets selected at homepage
	if(!selectedItem)selectedItem = {
			name : 'leeg object'
		};
}

function stayShown(){
	if(!selectedItem)getStartedItem();
	clearTimeout(t);
}

//ShowSub occurs on mouseover, it shows the corrosponding submenu
function showSub(obj, e) {
	//IF selectedItem is not set yet, then get it.
	if(!selectedItem)getStartedItem();
	
	//Check if the submenu does exist
	if(document.getElementById(obj)){
		//Check if a menu item was selected previously, LIitem wil be set.
		if(LIitem&&LIitem!==e.parentNode){
			//If a menu item was selected, then remove the class "selected"
			LIitem.className = "";
		}
		//display the current submenu
	}else{
		//The selected menu item should not be highlighted
		if(LIitem)LIitem.className = "";
	}
	//Check if the current list item (e.parentNode) is already selected
	if(e.parentNode.className !== "selected"){
		//If LItem or selectedItem is the same as the first List item, don't highlight it.
		if(LIitem==firstItem||selectedItem==firstItem)deselectFirstItem();
		//set the current List item as slected
		e.parentNode.className = "selected";
		//if selectedItem is not the same as the current list Item, then don't highlight it
		if(selectedItem&&selectedItem!==e.parentNode)selectedItem.className = "";
	}
	//if the current list item ist the same as the first list item, then highlight it
	if(e.parentNode==firstItem)selectFirstItem();
	//set the LIitem again
	LIitem = e.parentNode;
	clearTimeout(t);
}


