var IE5, NN4, IE4, timerID, showTimerID, imgName, imgSource, whichDiv, childMenu, parentDiv, parentRow;
timerID = 0;

//browser detect
if (document.getElementById) IE5 = true;
else if (document.layers) NN4 = true;
else IE4 = true;
//if (IE5){document.write('This is IE 5 or greater')}

function showMenu(whichDiv) {		
	if (timerID) clearTimeout(timerID);	
	if (showTimerID) clearTimeout(showTimerID); //if something else is about to show, don't let it - it's too late!	
		
	if (IE5 || IE4) {												
		if (IE5) {
			allDivs = document.getElementsByTagName("div");	
			thisDiv = document.getElementById(whichDiv);
			parentDiv = document.getElementById(whichDiv + "parent");															
		}
		else {					
			allDivs = document.all.tags("div");
			thisDiv = document.all(whichDiv);			
			parentDiv = document.all(whichDiv + "parent");			
		}													
		
		//hide all other menus (if showing)
		for (i=0; i < allDivs.length; i++) {			
			if (allDivs[i].id != whichDiv && allDivs[i].id.indexOf("parent") == -1 && allDivs[i].id.indexOf("menu") != -1) {
				allDivs[i].style.visibility = 'hidden';					
			}		 		 		  		  
			//unhighlight all other parent rows													
			if (allDivs[i].id.indexOf("parent") != -1 && allDivs[i].id != parentDiv.id && allDivs[i].id.indexOf("special") == -1) {					
				IE5 ? thisRow = document.getElementById(allDivs[i].id) : thisRow = document.all(allDivs[i].id);				
				thisRow.className = 'menubg'; //unhighlight
			}
		}							
		
		parentDiv.className = "menuhighlightbg";  //highlight parent row
		//thisDiv.style.visibility = 'visible';														
		showTimerID = setTimeout("thisDiv.style.visibility = 'visible'", 150);			//show selected div					
	}
	else if (NN4) {					
		thisDiv = document.layers[whichDiv];		
		
		//hide all other menus (if showing)				
		for (i=0; i < document.layers.length; i++) {									
			if (document.layers[i].visibility == 'show' && document.layers[i].id != whichDiv && document.layers[i].id.indexOf("parent") == -1 && document.layers[i].id.indexOf("menu") != -1) {
				document.layers[i].visibility = 'hide';		 
			}
		}									
							
		//thisDiv.visibility = 'show';													
		showTimerID = setTimeout("thisDiv.visibility = 'show'", 150);			//show selected layer		
	}						
}

function hideMenu(whichDiv) {
	if (showTimerID) clearTimeout(showTimerID); //if something is about to show, don't let it - it's too late!
	//menuBase = whichDiv.split("menu");
	
	if (IE5 || IE4) {
		//hide every visible div just in case
		IE5 ? allDivs = document.getElementsByTagName("div") : allDivs = document.all.tags("div");
		for (i=0; i < allDivs.length; i++) {			
		  if (allDivs[i].id.indexOf("parent") == -1 && allDivs[i].id.indexOf("menu") != -1) {
				allDivs[i].style.visibility = 'hidden';											
		  }
		  
			//unhighlight all other parent rows													
			if (allDivs[i].id.indexOf("parent") != -1 && allDivs[i].className == 'menuhighlightbg' && allDivs[i].id.indexOf("special") == -1) {									
				allDivs[i].className = 'menubg'; //unhighlight									
			}   
		}
						
	}
	else if (NN4) {	
		//hide every visible layer just in case
		for (i=0; i < document.layers.length; i++) {				
		  if (document.layers[i].visibility == 'show' && document.layers[i].id.indexOf("parent") == -1 && document.layers[i].id.indexOf("menu") != -1) {														
				document.layers[i].visibility = 'hide';    	     	 
		  }   
		}		
	}	
}

/*
function hideChildren(whichMenu) {
	if (IE5 || IE4) {						
		//hide all child divs within the current menu
		if (IE5) {allDivs = document.getElementsByTagName("div")}
		else {allDivs = document.all.tags("div")}								
		for (i=0; i < allDivs.length; i++) {			
		  if (allDivs[i].style.visibility == 'visible' && allDivs[i].id.indexOf(whichMenu + "Child") != -1) {														
				allDivs[i].style.visibility = 'hidden';								
				unHighlightParentRow(allDivs[i].id);			//make sure parent row is not still highlighted
		  }   
		}
	}
	else if (NN4) {
		for (i=0; i < document.layers.length; i++) {				
		  if (document.layers[i].visibility == 'show' && document.layers[i].id.indexOf(whichMenu + "Child") != -1) {														
				document.layers[i].visibility = 'hide';    	     	 
		  }   
		}
	}
}
*/

function setTimer(whichDiv) { 	
	//find out which div is currently showing 	
	if (IE5 || IE4) {					
		if (IE5) activeDiv = document.getElementById(whichDiv).id;
		else activeDiv = document.all(whichDiv).id;
		timerID = setTimeout('hideMenu(activeDiv)', 100);														
	}
	else if (NN4) {	
		activeDiv = document.layers[whichDiv].id;									
		timerID = setTimeout('hideMenu(activeDiv)', 100);								
	}				        
}

function stopTimer() {	
	clearTimeout(timerID);			
}

function menuHiLite(row,arrowImg) {		
	if (IE4 || IE5) {								
		//change bg color of current row					
		if (row.className == 'menubg') row.className='menuhighlightbg';
		else if (row.className == 'menuhighlightbg') row.className='menubg';		
		
		else if (row.className == 'submenubg') row.className='submenuhighlightbg';	
		else if (row.className == 'submenuhighlightbg') row.className='submenubg';	
		
		//change cursor to hand (clickable)
		row.style.cursor='hand';
		
		pageHeight = document.body.clientHeight;
		pageTop = document.body.scrollTop; 
		pageBottom = pageHeight + pageTop;			
		rowHeight = 15;			 
			
		//get current mouse y coordinate															
		curPos = event.y;
			
		//scroll window down
		if (curPos + pageTop + rowHeight > pageBottom) {								
			window.scrollTo(0,pageTop + rowHeight);
		}
			
		//scroll window up - kinda annoying!
		if (curPos + pageTop < pageTop + rowHeight + 10) {						
			window.scrollTo(0,pageTop - rowHeight);
		}														
	}
}