var timeout	= 500;
var closetimer	= 0;
var prev_dropdown = 0;
var menu_active = 0;

//activate or deactive Top Nav
function toggleTopNav(dropdown){
	if (menu_active){
		menu_active = 0;
		closeTopNav();
	}else{
		menu_active = 1;
		openTopNav(dropdown);
	}
	clearSelection();
}

//open Top Nav heading
function openTopNav(dropdown){
	if (menu_active){
		cancelCloseTopNavTime();
		if(prev_dropdown) closeTopNav();
		if(document.getElementById(dropdown)) document.getElementById(dropdown).className = 'topnav_dropdown_visable';
		if(document.getElementById(dropdown+'_heading')) document.getElementById(dropdown+'_heading').className = 'topnav_heading_selected';
		prev_dropdown = dropdown
		menu_active = 1;
	}
}

// Close Top Nav heading
function closeTopNav(){
	if(prev_dropdown){
		if(document.getElementById(prev_dropdown)) document.getElementById(prev_dropdown).className = 'topnav_dropdown_hidden';
		if(document.getElementById(prev_dropdown+'_heading')) document.getElementById(prev_dropdown+'_heading').className = 'topnav_heading';
		prev_dropdown = 0
		menu_active = 0;
	}
}

//close Timeer
function closeTopNavTime(){
	closetimer = window.setTimeout(closeTopNav, timeout);
}

// cancel close timer
function cancelCloseTopNavTime(){
	if(closetimer)
	{
		window.clearTimeout(closetimer);
		closetimer = null;
	}
}

//open Sub Nav heading
function openSubNav(subnav){
	if(document.getElementById(subnav+'_heading')) document.getElementById(subnav+'_heading').className = 'subnav_heading_selected';
	if(document.getElementById(subnav)) document.getElementById(subnav).className = 'subnav_dropdown_visable';
}

//close Sub Nav heading
function closeSubNav(subnav){
	if(document.getElementById(subnav+'_heading')) document.getElementById(subnav+'_heading').className = 'subnav_heading';
	if(document.getElementById(subnav)) document.getElementById(subnav).className = 'subnav_dropdown_hidden';
}


// stops text from being selected when double clicking it (use with ondblclick event handler)
function clearSelection() {
	var sel;
	if(document.selection && document.selection.empty){
		document.selection.empty() ;
	}else if(window.getSelection) {
		sel=window.getSelection();
		if(sel && sel.removeAllRanges)
			sel.removeAllRanges();
   }
}

