var W3C = document.getElementById? true : false;
var NN4 = document.layers? true : false; //Netscape Navigator 4.x.
var IE4 = document.all? true : false; // IE version 4 and above.
var isHiding = false
var shownLayers = new Array(20) 
var shownLayersIndex = 0
var hidingLayers = new Array(20) 

for (i=0;i<20;i++) {
	shownLayers[i] = ""
}

function getIsHidingLayer (layerName) {
	if (isInShownLayers (layerName)) {
		//alert(indexInShownLayers (layerName) + " is " + hidingLayers [indexInShownLayers (layerName)])
		return hidingLayers [indexInShownLayers (layerName)]
	}
	
}

function setIsHidingLayer (layerName) {
	if (isInShownLayers (layerName)) {
		hidingLayers [indexInShownLayers (layerName)] = true
		//alert(indexInShownLayers (layerName) + "set to true")
	}
	
}

function clearIsHidingLayer (layerName) {
	if (isInShownLayers (layerName)) {
		hidingLayers [indexInShownLayers (layerName)] = false
		//alert(indexInShownLayers (layerName) + "set to false")
	}
	
}

function putInShownLayers (layerName) {
	if (!isInShownLayers (layerName)) {
		shownLayers[shownLayersIndex] = layerName
		shownLayersIndex = shownLayersIndex  + 1
	}
	
}

function isInShownLayers (layerName) {
	var isIn = false
	for (i=0;i<20;i++) {
		if (shownLayers[i] == layerName) {
			isIn = true
		}
	}
	return isIn
}

function indexInShownLayers (layerName) {
	var isIn = 0
	for (i=0;i<20;i++) {
		if (shownLayers[i] == layerName) {
			isIn = i
		}
	}
	return isIn
}

function hideAllExcept (layerName) {
	for (i=0;i<20;i++) {
		if (shownLayers[i] != "") {
			if (shownLayers[i] != layerName) {
				hide(shownLayers[i])
			}
		}
	}
}

function doSomething(e) {
	var posx = 0;
	var posy = 0;
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posx = e.pageX;
		posy = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posx = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posy = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}
	// posx and posy contain the mouse position relative to the document
	// Do something with this information
}


function hide(layerName) {
	if (W3C) {
		document.getElementById(layerName).style.visibility = "hidden";
	} else if (IE4) {
		document.all[layerName].style.visibility = "hidden";
	} else if (NN4) {
		document.layers[layerName].visibility = "hidden";
	}
}

function hideAll() {
//alert(0)

	for (i=0;i<20;i++) {
		if (shownLayers[i] != "") {
				hide(shownLayers[i])
		}
	}
}


function display(layerName) {
	doSomething(layerName)
	putInShownLayers (layerName)
	clearIsHidingLayer (layerName)
	hideAll()
	if (W3C) {
		document.getElementById(layerName).style.visibility = "visible";
//		document.getElementById(layerName).style.left = posx
//		document.getElementById(layerName).style.top = posy
//		document.getElementById(layerName).style.left = event.clientX
//		document.getElementById(layerName).style.top = event.clientY

	} else if (IE4) {
		document.all[layerName].style.visibility = "visible";
//		document.getElementById(layerName).style.left = posx
//		document.getElementById(layerName).style.top = posy
//		document.getElementById(layerName).style.left = event.clientX
//		document.getElementById(layerName).style.top = event.clientY
	} else if(NN4) {
		document.layers[layerName].visibility = "show";
	}
}


function delayedhide(layerName) {
	if (!getIsHidingLayer (layerName)) {
		setIsHidingLayer (layerName)
		setTimeout("Javascript:dodelayedhide('"+layerName+"')",1500)	
	}
}

function delayed2hide(layerName) {
	if (!getIsHidingLayer (layerName)) {
		setIsHidingLayer (layerName)
		setTimeout("Javascript:dodelayedhide('"+layerName+"')",800)	
	}
}

function dodelayedhide(layerName) {
	if (getIsHidingLayer (layerName)) {
		hide(layerName)
	}
}

