// JavaScript Document fh-menu.js

// configuration variables
var timeout = 250;
var fadeSpeed = 500;
var useFade = false;

// timers array
var timers = new Array();

// state array by id, value - active, false - inactive
var state = new Array();

// lastOpacity: used to prevent multiple timers from making the fade flicker
var lastOpacity = new Array();

// MSIE has its own way of setting opacity, so we have to detect it
// all the other major browsers support the standard DOM opacity property
var msie = false;
if(navigator.appName == "Microsoft Internet Explorer") msie = true;

// entry point: set element to visible and clear its timers
function setMenu(id,hl) {
	document.getElementById(hl).style.backgroundColor = "#CACDC1";
	var e = document.getElementById(id);
	e.style.visibility = "visible";
	state[id] = true;
	setOpacity(id, 1);
	if(timers[id]) {
		clearTimeout(timers[id]);
		timers[id] = undefined;
	}
}
function setMenuL3(id,L3) {
	var e = document.getElementById(id);
	e.style.visibility = "visible";
	state[id] = true;
	if(timers[id]) {
		clearTimeout(timers[id]);
		timers[id] = undefined;
	}
	if(timers[L3]) {
		clearTimeout(timers[L3]);
		timers[L3] = undefined;
	}
}

// set element to hidden and reset its opacity
// typically called by a timer
// may be used as an entry point to bypass timers and fades
function hideMenu(id,hl) {
	document.getElementById(hl).style.backgroundColor = "#F6F4EC";	
	var e = document.getElementById(id);
	state[id] = false;
	e.style.visibility = "hidden";
	if(useFade) setOpacity(id , 1);
}

// entry point: hide the menu using fade (if enabled)
function clearMenu(id,hl) {
//	alert ('hideMenu("' + id + '","' + hl + '")');
	if(useFade) timers[id] = setTimeout('fadeMenu("' + id + '")' , timeout);
	else timers[id] = setTimeout('hideMenu("' + id + '","' + hl + '")', timeout);
}
function clearMenuL3(id,L3) {
	var hl = "highLiteProg";
	timers[id] = setTimeout('hideMenu("' + id + '","' + hl + '")', timeout);
	timers[L3] = setTimeout('hideMenu("' + L3 + '","' + hl + '")', timeout);
}
// set the opacity
// special support for MSIE
function setOpacity(id, value) {
	var e = document.getElementById(id);
	if(state[id]) value = 1;   //menu fade was interrupted
	else if(lastOpacity[id] && (lastOpacity[id] < value)) value = lastOpacity[id]; // prevents flicker if multiple timeouts
	if(msie) e.style.filter = 'alpha(opacity=' + value * 100 + ')';
	else e.style.opacity = (value);
	if(value == 0) hideMenu(id);  // when all faded, reset the menu state
	lastOpacity[id] = value;
}

// fade a menu
// typically called by a timer
function fadeMenu (id) {
	var start = 0;
	var end = 0
	var s = Math.round(fadeSpeed / 25); // fade in 25ms increments
	var timer = 0;
	var i;
	
	state[id] = false;
	
	for(i = s; i >= 0; i--) {
		setTimeout("setOpacity('" + id + "'," + (i/s) + ")", timer++ * fadeSpeed / s)
	}
}



		
