var hideId;

var navtime = new Array();

function switchnav(id, initiate) {
	if(initiate==null) {
		navtime[id] = setTimeout("switchnav('"+id+"', 1)", 150);
		return;
	}
	hide_all_subnav();
	var d = document.getElementById('submenu'+id);
	var m = document.getElementById('mainnav'+id);
	for (var i = 0; i<=10; i++) {
		if (document.getElementById('submenu'+i)) {
			document.getElementById('submenu'+i).style.display='none';
			document.getElementById('mainnav'+i).className = "";
		}
	}
	if (d) {d.style.display='block';}
	if (m) {m.className="nav_on";}
	currTab = id;
}

function cancelnav(id) {
	clearTimeout(navtime[id]);
}

function showsub(id) {
	var d2 = document.getElementById(id);
	for (var i = 1; i<=100; i++) {
		if (document.getElementById('tmenu'+i)) {
			document.getElementById('tmenu'+i).style.visibility='hidden';
		}
	}
	if (d2) {d2.style.visibility='visible';}
}

function switchTabs(id, groupids) {
	var thistab = document.getElementById(id);
	var othertabs = groupids;
	
	for (j=0; j < othertabs.size(); j++) {
		document.getElementById(othertabs[j]).style.display='none';
		document.getElementById(othertabs[j]+'tab').className="";
	}
	
	if (thistab) {
		thistab.style.display='block';
		var thistab2 = document.getElementById(id+'tab');
		thistab2.className="tabs_selected";
	}
}

function showSrchOptions(menu) {
	var d3 = document.getElementById(menu);
	if (d3) {
		if (d3.style.visibility !="visible") {
			d3.style.visibility='visible';
		}
	}
}

function clearTime() {
	clearTimeout(hideId);
}

//new navigation functions
function subnav_init() {
	var jobj = $('subnav_wrapper');		
	var links = jobj.getElementsBySelector('li');
	
	//get all links who have submenus
	links.each(function(e) {
		//check if there is a submenu
		sub = e.getElementsBySelector('.submenu')[0];
		if(sub) {
			//apply an ID we can use (if one isn't already set)
			sub.id = sub.identify();
			//get the a on which we need to add the mouseover
			alink = e.getElementsBySelector('a')[0];
			alink.onmouseover = function() {
				show_subnav(this);
			}
			alink.onmouseout = function() {
				hide_subnav(this);
			}
			//add necessary functions to all links in the submenu, so it doesn't hide when you're mousing over it
			drop_links = sub.getElementsBySelector('a').each(function(a) {
				a.onmouseover = function() {
					cancel_subnav_hide(this);
				}
				a.onmouseout = function() {

					hide_subnav(this.up('a'));
				}
			});
		}
	});
}

function show_subnav(alink) {
	hide_all_subnav();
	
	//show the desired drop menu
	var drop = $(alink).next(".submenu");
	if(drop) {
		drop.addClassName("visible");
	}
}

function hide_all_subnav() {
	clearTimeout(hideId);
	//hide any menu that's currently showing
	$$("#subnav_wrapper .submenu.visible").each(function(e) {
		e.removeClassName("visible");
	});
}

function hide_subnav(alink) {
	hideId = setTimeout("hide_all_subnav()", 2000);
}

function cancel_subnav_hide() {
	clearTimeout(hideId);
}