// --------------------------- HWAM.js ------------------------------
// 2005-04-10 DRH	Register window.onResize/onScroll in positionElement.
// 2005-04-11 DRH	Register window.onResize/onScroll in positionElement()
//								to closeMenuAndRepositionElement().  Repositioning alone
//								wasn't enough.
// 								Moved onScroll/onResize to NJSKC.js for integration with 
//								Panoramic.js.


var remember = new Array();
var remember2 = new Array();
var checkIt;
var positionX;
var positionY;
var DHTML = (document.getElementById || document.all || document.layers);
var fSpillIt = false;
var	theElement;			// Save these so we can reposition whenver the scroll bar appears/disappears
var	theHere;				// repositionElement() called from show();

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function findPositionX(obj) {

	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 findPositionY(obj) {

	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 spillIt(s) {
	var e = document.getElementById('output');
	if(e) {
		e.innerHTML = s;		
	}
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function show(subMenu,lvl,obj) {

	var xMe = findPositionX( obj);
	var yMe = findPositionY( obj);
	var wMe = obj.clientWidth;
	var hMe = obj.clientHeight;
	if (wMe == 0) {											// IE reports width of <A> as 0, in tables
		wMe = obj.parentNode.clientWidth;	// at least.  Going up to the parent <TD> 
	}																		// seems to work and doesn't break others.
	var topMe = obj.style.top;
	var leftMe = obj.style.left;
	/* Remove below for production */
	if (fSpillIt) {
		spillIt(    '<BR> findPositionX: ' + xMe 				+ ' &nbsp; xLeft:   ' + xLeft( obj) 
							+ '<BR> findPositionY: ' + yMe 				+ ' &nbsp; xTop:    ' + xTop( obj) 
							+ '<BR> obj.clientWidth: ' + wMe 	+ ' &nbsp; xWidth:  ' + xWidth( obj) 
							+ '<BR> obj.clientHeight: ' + hMe + ' &nbsp; xHeight: ' + xHeight( obj) 
							+ '<BR> obj.style.top: ' + topMe
							+ '<BR> obj.style.left: ' + leftMe
							+ '<BR> text: ' + obj.text
							+ '<BR> parent.className: ' + obj.parentNode.className
							+ '<BR> parent.nodeName: ' + obj.parentNode.nodeName
							+ '<BR> parent.clientWidth: ' + obj.parentNode.clientWidth
						)
	}
	/* Remove above for production */

	if (!DHTML) return;
	checkUserInput();
	if (remember[lvl] && remember[lvl] == subMenu) return;
	if (remember[lvl]) {
		closeAll(lvl);
	}
	if (subMenu) {
		var x = getObjStyle(subMenu);
		x.top = yMe;
		x.left = xMe + wMe + 5;				/* Should figure out padding and margins of this and parent.*/
		x.visibility = 'visible';
	}

	remember[lvl] = subMenu;
	if (obj.parentNode) {
		var eParent = obj.parentNode;
	} else if (obj.parentElement) {
			var eParent = obj.parentElement;
	} else {
		return;
	}
	if (eParent.className == 'over') return;
	eParent.className = 'over';
	if (remember2[lvl]) {
		remember2[lvl].className = 'Links';
	}
	remember2[lvl] = eParent;

	repositionElement();						
	//	Sometimes, depending on the exact window size, mousing over two 
	//	levels with submenus will cause FireFox to repaint the screen and 
	//	REMOVE the scroll bar.  No resize or scroll event is generated 
	//	(FF 1.0.2).  repositionElement() here is a workaround.
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function closeAll(lvl) {
	for (i = remember.length - 1; i >= lvl; i--) {
		if (remember[i]) {			//IE4 Mac
			var x = getObjStyle(remember[i]);
			x.visibility = 'hidden';
		}
		remember[i] = null;
		if (remember2[i])	{
			remember2[i].className = 'Links';
			remember2[i] = null;
		}
	}
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function checkUserInput() {
	if (checkIt) {
		clearTimeout(checkIt);
	}
	checkIt = setTimeout('closeAll(1)', 3500);
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function getObjStyle(name) {
  if (document.getElementById) {
    return document.getElementById(name).style;
  } else if (document.all) {
    return document.all[name].style;
  } else if (document.layers) {
    return document.layers[name];
  } else {
		return false;
	}
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function repositionElement() {

	positionElement( theElement, theHere);
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function closeMenuAndRepositionElement() {
	closeAll(1);
	repositionElement();
}

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

function positionElement( element, here) {

	theElement = element;			// Save these so we can reposition whenver the scroll bar appears/disappears
	theHere = here;						// repositionElement() called from show();

	var eHere = document.getElementById( here);
	var eHereX = findPositionX( eHere);
	var eHereY = findPositionY( eHere);
	var eElement = document.getElementById(element);
	eElement.style.top = eHereY;
	eElement.style.left = (eHereX + 2);
	eElement.style.visibility = 'visible'
}

// --------------------------- HWAM.js ------------------------------
