var the_sub, the_area_name;

function show_menu(the_sub){
var the_sub_nav = document.getElementById(the_sub);
if(!the_sub_nav) return false;
the_sub_nav.style.display='block';
} 

function hide_menu(the_sub){
var the_sub_nav = document.getElementById(the_sub);
if(!the_sub_nav) return false;
the_sub_nav.style.display='none';
}

// funcion to hold menu while off main menu but on sub menu
function hold_menu(the_sub){
var the_sub_nav = document.getElementById(the_sub);
if(!the_sub_nav) return false;
var sub_nav_links = the_sub_nav.getElementsByTagName('a');
	for (var i=0; i < sub_nav_links.length; i++){	
		sub_nav_links[i].onmouseover = function(){
			if(this.className != 'active'){
				the_sub_nav.style.display='block';
				document.getElementById(the_sub.substr(1)).style.backgroundPosition='left bottom';
			}
		}
		sub_nav_links[i].onmouseout = function(){
			if(this.className != 'active'){
				the_sub_nav.style.display='none';
				document.getElementById(the_sub.substr(1)).style.backgroundPosition='left top';
			}
		}
	}
}  

function menu_over(){
var the_nav = document.getElementById('nav');
if(!the_nav) return false;
var nav_links = the_nav.getElementsByTagName('a');
	for (var i=0; i < nav_links.length-1; i++){	
	nav_links[i].onmouseover = function(){
		// uses the main link id to select the right sub menu to show
		var the_area_name = "sn" + this.id.substr(1);
		show_menu(the_area_name);
		if(the_area_name){
			if(this.className != 'active'){
				document.getElementById(the_area_name.substr(1)).style.backgroundPosition='left bottom';
			}
		}
		return false;			
		}
	}
} 
addLoadEvent(menu_over);

function menu_out(){
var the_nav = document.getElementById('nav');
if(!the_nav) return false;
var nav_links = the_nav.getElementsByTagName('a');
	for (var i=0; i < nav_links.length-1; i++){	
	nav_links[i].onmouseout = function(){
		var the_area_name = "sn" + this.id.substr(1);	
		hold_menu(the_area_name);		
		hide_menu(the_area_name);
		if(the_area_name){
			if(this.className != 'active'){
				document.getElementById(the_area_name.substr(1)).style.backgroundPosition='left top';
			}
		}
		return false;	
		}
	}
}
addLoadEvent(menu_out);


