var timerID=null;
var timerOn=false;
var timecount=100;
var curobj;

function startTime(){
	if(timerOn == false){
		timerID=setTimeout("closeMenu()",timecount);
		timerOn = true;
	}
}
function stopTime(){
	if(timerOn){
		clearTimeout(timerID);
		timerID = null;
		timerOn = false;
	}
}
function findX(e){
	obj = e.srcElement || e.target;
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}
function findY(e){
	obj = e.srcElement || e.target;
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}
function popMenu(which,direction,e){
	closeMenu();
	//direction: 0=vertical pop, 1=horizontal pop
	if(!e){
		e = event;
	}
	dv = document.getElementById(which);
	x = findX(e);
	y = findY(e);
	if(!document.all){
		x--;
		y--;
	}
	ob = e.srcElement || e.target;
	curobj = ob;
	if(direction == 0){
		cellHeight = ob.offsetHeight;
		dv.style.left = x + getHOffset(which); // this is so ghetto
		dv.style.top = y + cellHeight + getVOffset();  // this, not so much
	}else if(direction == 1){
		cellWidth = ob.offsetWidth;
		dv.style.left = x + cellWidth;
		dv.style.top = y;
	}
	if (navigator.userAgent.indexOf("MSIE") == -1)
	{
		
	}
	dv.style.visibility="visible";
}
function closeMenu(){
	if(curobj){
		curobj = null;
	}
	allDivs = document.getElementsByTagName("DIV");
	for(i=0;i<allDivs.length;i++){
		if(allDivs[i].id.indexOf("OPT") != -1){
			allDivs[i].style.visibility="hidden";
		}
	}
}
function swapMenuClass(d){
	if(d.className=="MENU_OPT"){
		d.className="MENU_HL";
	}else{
		d.className="MENU_OPT";
	}
}

function takeMeTo(loc){
	document.location = loc;
}

function getHOffset(name)
{
	var offset = 0;
	
	if (navigator.userAgent.indexOf("MSIE") == -1)
	{
		offset++;
	}
	
	switch (name) {
		case "OPT1":
			offset += 3;
			break;
		case "OPT2":
			offset += 6;
			break;
		case "OPT5":
			offset += 2;
		case "OPT6":
			offset += -3;
		case "OPT3":
			offset += 6;
			break;
		case "OPT4":
			offset += 7;
			break;

		default:
			break;
	}

	return offset;
}

function getVOffset()
{
	if (navigator.userAgent.indexOf("MSIE") == -1)
	{
		return 1;
	}
	else
	{
		return 0;
	}
}
