var uID = 0;
var loadTimer = '';
var menuToHide = null;
var hideFields = new Array();
var macOffX = 1;
var macOffY = 1;
if(isMac) {
	macOffX = 0;
	macOffY = 0;
}

function startLayer(c,l,t,w,h,id) {
	//c = content
	//l,t,w,h = left,top,width,height
	//id = optional id override
	var n = null;
	uID += 1;
	if(arguments.length<6 || id==null) {
		id = "dynLayer"+uID;
	}
	if (isNS4) {
		n = window[id];
		n = window[id] = new Layer(h,window);
		n.document.write(c);
		n.visibility = "hide";
		n.moveTo(l,t);
		n.clip.right = w;
		n.onmouseover = NSlayerOver;
		n.onmouseout = NSlayerOut;
		n.document.close();
	} else if (isIE4) {
		eval("dynLayerObj"+uID+" = new Object()");
		n = eval("dynLayerObj"+uID);
		document.body.insertAdjacentHTML("BeforeEnd","<DIV ID='"+id+"' STYLE='position:absolute;visibility:hidden;width:166;' >"+c+"</DIV>");
		layerLyr = document.all(id);
		n = layerLyr;
		with(n.style) {
			//color = "#000000";
			font = "normal 11pt Arial";
			pixelWidth = w;
			pixelLeft = l;
			pixelTop = t;
		}
	} else if (isDOM) {
		n = document.createElement("DIV");
		n.id = id;
		n.style.position = "absolute";
		n.style.visibility = "hidden";
		n.innerHTML = c;
		with(n.style) {
			//color = "#000000";
			font = "normal 10pt Arial";
			width = w+"px";
			height = h+"px";
			left = (l+macOffX)+"px";
			top = (t+macOffY)+"px";
		}
		document.body.appendChild(n);
		n.on = false;
		n.zIndex = 1000;
	}
	return n;
}

function showLayer(on,n,e) {
	if(menuToHide) {
		if(menuToHide!=n) {
			setVisHide(menuToHide);
		}
		clearTimeout(menuToHide.hideTimer);
	}
	if(!on) {
		menuToHide = n;
		menuToHide.hideTimer = setTimeout("setVisHide(menuToHide);",100);
	} else {
		setVisShow(n);
	}
	showFormFields(on);
	self.status = "";
}

function setVisHide(which) {
	if(isNS4)
		which.visibility = 'hide';
	else if (isDOM || isIE4)
		which.style.visibility = 'hidden';
}

function setVisShow(which) {
	if(isNS4)
		which.visibility = "show";
	else if (isDOM || isIE4) 
		which.style.visibility = "visible";
}

function showFormFields(on) {
	if(hideFields.length > 0) {
		if(isNS4) {
			for(var x = 0; x < hideFields.length; x++) {
				if(eval(hideFields[x])) eval(hideFields[x]).visibility = on ? "hidden" : "visible";
			}
		} else if (isDOM || isIE4) {
			for(var x = 0; x < hideFields.length; x++) {
				if(eval(hideFields[x])) eval(hideFields[x]).style.visibility = on ? "hidden" : "visible";
			}
		}
	}
}

function layerOver(n) {
	if(n) {
		n.on = true;
		showLayer(true,n);
	}
}

function layerOut(n) {
	if(n) {
		n.on = false;
		showLayer(false,n);
	}
}

function NSlayerOver() {
	this.on = true;
	showLayer(true,this);
}

function NSlayerOut() {
	this.on = false;
	showLayer(false,this);
}

function layerClick(n) {
	if(n) {
		if(n.on) {
			n.on = false;
			showLayer(false,n);
		} else {
			n.on = true;
			showLayer(true,n);
		}
	}
}

function addToLoadTimer(v) {
	loadTimer += v;
}

function executeLayerTimer() {
	if(loadTimer.length>0) {
		if(isNS4) setTimeout(loadTimer,500);
		else eval(loadTimer)
	}
}

function getAbsolutePosition(image) {
	var rd = {x:0, y:0};
	if(isNS4) {
		rd.x = image.x;
		rd.y = image.y;
	} else {
		do {
			rd.x += image.offsetLeft;
			rd.y += image.offsetTop;
			image = image.offsetParent;
		} while(image);
	}
	return(rd)
}


