var NS4 = (document.layers) ? 1 : 0;
var IE4 = (document.all) ? 1 : 0;
var DOM = ((document.getElementById) && (!IE4)) ? 1 : 0;
var isOver = false;
var timer = null;

if (NS4) {
	origWidth = innerWidth;
	origHeight = innerHeight;
}

if (NS4) onresize = reDo;
if (DOM) onload = InitObj;

function reDo() {
	if (innerWidth != origWidth || innerHeight != origHeight) {
		location.reload();
	}
}

function InitObj() {
	keepGoing = 1;
	i = 1;
	while (keepGoing) {
		var whichEl = "menu" + i;
		if (DOM) {
			whichEl = document.getElementById(whichEl);
		} else if (NS4) {
			whichEl = document.layers[whichEl];
		} else if (document.all[whichEl]) {
			whichEl = document.all[whichEl].style;
		} else {
			whichEl = "";
		}
		if (whichEl) {
			whichEl.onmouseover = OverLayer;
			whichEl.onmouseout = OutLayer;
		} else {
			keepGoing = 0;
		}
		i++;
	}
}

function ShowLayer(showEl, event) {
	clearTimeout(timer);
	HideAllLayers();

	var whichEl;

	if (DOM) {
		whichEl = document.getElementById(showEl);
	} else {
        if (NS4) {
            whichEl = document.layers[showEl];
        } else {
            whichEl = document.all[showEl].style;
        }
	}

	whichAnchor = showEl + "A";
	menuTop = 0;
	menuLeft = 0;

	if (IE4) {
		if (document.all[whichAnchor]) {
			menuTop = findy(document.all[whichAnchor]) + 20;
			menuLeft = findx(document.all[whichAnchor]);
		}
	}
	if (NS4) {
		if (document.anchors[whichAnchor]) {
			menuTop = document.anchors[whichAnchor].y + 20;
			menuLeft = document.anchors[whichAnchor].x;
		}
	}
	if (DOM) {
		if (document.anchors[whichAnchor]) {
			menuTop = 20;
			menuLeft = -2;
			var myObject = document.anchors[whichAnchor];
			while (myObject.offsetParent) {
				menuTop = menuTop + myObject.offsetTop;
				menuLeft = menuLeft + myObject.offsetLeft;
				myObject = myObject.offsetParent;
			}
		}
	}
   if (whichEl) {
        if (DOM) {
            whichEl.style.visibility = "visible";
            whichEl.style.top = menuTop;
            whichEl.style.left = menuLeft;
        } else {
            whichEl.visibility = "visible";
            whichEl.top = menuTop;
            whichEl.left = menuLeft;
        }
	}
}

function findy(item) {
	if (item.offsetParent) {
		return item.offsetTop + findy(item.offsetParent);
	} else {
		return item.offsetTop;
	}
}

function findx(item) {
	if (item.offsetParent) {
		return item.offsetLeft + findx(item.offsetParent);
	} else {
		return item.offsetLeft;
	}
}

function HideAllLayers() {
	keepGoing = 1;
	i = 1;
	while (keepGoing) {
		whichEl = "menu" + i;
		if (DOM) {
			whichEl = document.getElementById(whichEl);
		} else if (NS4) {
			whichEl = document.layers[whichEl];
		} else if (document.all[whichEl]) {
			whichEl = document.all[whichEl].style;
		} else {
			whichEl = "";
		}
		if (whichEl) {
			if (!isOver) {
				if (DOM) {
					whichEl.style.visibility = "hidden";
				} else {
					whichEl.visibility = "hidden";
				}
			}
		} else {
			keepGoing = 0;
		}
		i++;
	}
}

function OverLayer() { clearTimeout(timer); isOver = true; }

function OutLayer() {
	clearTimeout(timer);
	isOver = false;
	timer = setTimeout("HideAllLayers()",300);
}
