var activeMenuLayer      = null;
var switchMenuTimer      = null;
var switchMenuTimerDelay = 1;

var activeSwitchLayer = null;

/**
 * Boolean check
 * accepts 1,0 / true/false / yes,no as boolean values.
 */
function bool(val) {
	retVal = val;
	if (typeof retVal=="string") {
		switch (retVal.toLowerCase()) {
			default:
			case 'false':
			case 'no': 
			case '0': retVal = false;
					  break;
			case 'true':
			case 'yes': 
			case '1': retVal = true;
					  break;
		}
	}
	return (retVal)?true:false;
}

/**
 * Object class attribute may consist of a space separated list of class names.
 * This function iterates thorugh an objects <obj> class list and checks for a match of <match>.
 */
function hasClassName(obj, match) {
	var retVal = false;
	var list = obj.className.split(" ");
	for (var i=0; i<list.length; i++) {
		if (list[i]==match) {
			retVal = true;
			break;
		}
	}
	return retVal;
}
/**
 * Object class attribute may consist of a space separated list of class names.
 * This function adds <name> to an objects <obj> class list and optionally replaces class <remove> with the given class name.
 */
function setClassName(obj, name, remove) {
	var list = obj.className.split(" ");
	if (remove) {
		for (var i=0; i<list.length; i++) {
			if (list[i]==remove) {
				list[i] = name;
				name = "";
				break;
			}
		}
	}
	if (name) list[list.length] = name;
	obj.className = list.join(" ");
}

function toggleMenuLayer(id) {
	var obj;
	if (obj = document.getElementById(id)) {
		 if (hasClassName(obj, "switchLayerShow")) {
			/* use this function if you are using an onclick event instead of onmouseover */
			//closeMenuLayer(id);
		 }	else { 
		 	openMenuLayer(id); 
		 }
	}
}

function openMenuLayer(id) {
	killMenuLayerTimer();
	var objRef;
	if (objRef = document.getElementById(id)) {
		if (activeSwitchLayer!=id) {
			closeMenuLayer(activeMenuLayer);
			setClassName(objRef, "switchLayerShow", "switchLayerHide");
			if (objRef.getAttribute("showfunc")!=null) eval(objRef.getAttribute("showfunc"));
			activeMenuLayer = id;
		}
	}
}

function closeMenuLayer(id) {
	killMenuLayerTimer();
	var objRef;
	if (id!=null) {
		if (objRef = document.getElementById(id)) {
			setClassName(objRef, "switchLayerHide", "switchLayerShow");
			if (objRef.getAttribute("hidefunc")!=null) eval(objRef.getAttribute("hidefunc"));
			activeMenuLayer = null;
		} 
	}
}

function killMenuLayerTimer() {
	if (switchMenuTimer!=null) {
		clearTimeout(switchMenuTimer);
		switchMenuTimer = null;
	}
}

function closeMenuLayerTimer(id) {
	killMenuLayerTimer();
	switchMenuTimer = setTimeout("closeMenuLayer('"+id+"');", switchMenuTimerDelay*1000);
}

function mclick(m) {
	if (!m){ m = window.event; }
	
	if ((m.type && m.type == "contextmenu") || (m.button && m.button == 2) || (m.which && m.which == 3)) {
    	if (window.opera){  }
    	return false;
	}
}
if (document.layers){
	document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown = mclick;
document.oncontextmenu = mclick;