/* "Rollover and State Control for Top Navigation" by Dave K. & modified by Aaron M. */

var DELAY = 70;
var mo = false;
var chk;
var actM = null;
var actB = null;
var actC = null;
function getTV(obj) {
	var tVal = 0;
	while (obj!=document.body) {
		tVal += obj.offsetTop;
		obj=obj.offsetParent;
	}
	return tVal;
}
function getLV(obj) {
	var lVal = 0;
	while (obj!=document.body) {
		lVal += obj.offsetLeft;
		obj=obj.offsetParent;
	}
	return lVal;
}

function roll(obj,st,sel) {
// 	if (obj.className!="sideNavActive") {
		if (!sel) {
			obj.className = (st) ? "SideNavOver" : "SideNavOut";
		} else {
			obj.className = "SideNavOver";
		}
	}
// }

function mmRoll(id,obj,st,sel) {

	if (sel) {
		roll(obj,st,sel);
		mo = false;
		chk = setTimeout("chkM()",DELAY);
		mCtrl(id,obj,st,sel);
	}
	else {
		if (st) {
			mo = true;
			clearTimeout(chk);
			mCtrl(id,obj,st);
		}
		else {
			if (!id) {
				actB = null;
			}
			mo = false;
			chk = setTimeout("chkM()",DELAY);
		}
	}
}
function smRoll(obj,st) {
	obj.className = (st) ? "SideNavMenuOver" : "SideNavMenuOut";
	mo = st;
	if (st) {
		clearTimeout(chk);
	}
	else {
		chk = setTimeout("chkM()",DELAY);
	}
}
function mCtrl(id,obj,st,sel) {

	var bVers = navigator.appVersion.toLowerCase();
	var mXPos = 0;
	var mYPos = 0;
	cMenu();
	actB = obj;
	actC = sel;
	if (id) {
		if (sel) {
			roll(obj,st,sel);
		}
		else {
			roll(obj,st);
		}
		var mTbl = document.getElementById(id);
		actM = mTbl;
		mXPos = (getLV(obj)+obj.offsetWidth);
		mYPos = getTV(obj);
		if (bVers.indexOf("mac") >= 0) {
			if (bVers.indexOf("msie") >= 0) { mXPos += 0; mYPos += 1; }
			if (bVers.indexOf("safari") >= 0) { mXPos += 0; mYPos += 0; }
		}
		mTbl.style.display = '';
		if ((mXPos + mTbl.offsetWidth) > document.body.clientWidth) {
		
			mTbl.style.left = (document.body.clientWidth - mTbl.offsetWidth);
		}
		else {
		
			mTbl.style.left = mXPos;
		}
		mTbl.style.top = mYPos;
	}
}
function cMenu() {
	if (actM) {
		actM.style.display = 'none';
		if (actC) {
			roll(actB,true,true);
		}
		else {
			if (actB) {
				roll(actB,false);
			}
		}
	}
}
function chkM() {
	if (!mo) {
		cMenu();
	}
}
