//Dropdown flyout menu functions
function setUpNavDivs() {
	for(var i=0;i<allDivs.length;i++) {
		if (allDivs[i].className == 'navDiv') {
			allDivs[i].setAttribute("id", 'navDiv_' + i);
			allNavs.push('navDiv_' + i);
			// assumes that the layout is consistent, with 
			// a positioning div around the nav div
			tmpThing = allDivs[i].parentNode;
			//flyout menus positioning
			if (tmpThing.className != 'stopHere') {
				tmpThingTwo = node_before(tmpThing);
				allDivs[i].style.left = (tmpThingTwo.offsetWidth - pullIn) + 'px';
				allDivs[i].style.top = '-' + Math.floor(((tmpThingTwo.offsetHeight/2) + pullUp)) + 'px';
				//debugging code
				//if there is an element in the page with id of 'heyYou' your debugging code will appear here
				if(document.getElementById('heyYou')) {
					document.getElementById('heyYou').innerHTML += 'tmpThingTwo offsetWidth: ' + tmpThingTwo.offsetWidth + '\n';
					document.getElementById('heyYou').innerHTML += 'tmpThingTwo offsetHeight: ' + Math.floor(((tmpThingTwo.offsetHeight/2) + pullUp)) + '\n';
					}
				}
			}
		if (allDivs[i].className == 'sectionSubNav') {
			sideNavs.push(allDivs[i]);
			}
		}


	//when page loads navDivs are display: block visibility: hidden - otherwise we can't measure them. This sets them to display: none visibility: visible and display is toggled on mouseover.
	for(var i=0;i<allDivs.length;i++) {
		if (allDivs[i].className == 'navDiv') {
			allDivs[i].style.display='none';
			allDivs[i].style.visibility='visible';
			}
		}
	}

function waitASec(elem) {
	window.clearTimeout(winTimer);
	//winTimer = window.setTimeout("clearAll()", 1000);
	winTimer = window.setTimeout("clearAll()", 500);
	if(document.getElementById('heyYou')) {
		document.getElementById('heyYou').innerHTML += 'waitASec setting timer\n';
		document.getElementById('heyYou').innerHTML += elem + ' ' + elem.id + '\n';
		}
	}
	
function clearAll() {
	window.clearTimeout(winTimer);
	if(document.getElementById('heyYou')) {
		document.getElementById('heyYou').innerHTML += 'clearAll clearing timer\n';
		}
	notThese = [];
	for(var i=0;i<allNavs.length;i++) {
		document.getElementById(allNavs[i]).style.display='none';
		}
}

function showAfter(elem) {
    var walkOut = "";
    var thisNode = "";
	var mySib;
	var myChild;
	var prevSib;
	var m;
	if(document.getElementById('heyYou')) {
		document.getElementById('heyYou').innerHTML += '\nshowAfter ' + elem + '\n';
		}
	window.clearTimeout(winTimer);
	notThese = [];
	thisElem = elem;
    if (elem) {
		mySib = node_after(elem);
		// catch the main ones
		if (mySib && (mySib.className == 'stopHere' || !mySib.className)) {
			// get the first child of that div
			mySib = first_child(mySib);
			}
		
		if (mySib) {
			if (mySib.tagName=='div'|| mySib.tagName=='DIV' && mySib.className == 'navDiv') {
				if(document.getElementById('heyYou')) {
					document.getElementById('heyYou').innerHTML += 'mySib ' + mySib.id + '\n';
					}
				mySib.style.display='block';
				notThese.push(mySib.id);
				}
			}
		walkOut = elem.parentNode;
		if(document.getElementById('heyYou')) {
			document.getElementById('heyYou').innerHTML += 'walkOut parent: ' + walkOut.id + '\n';
			}
		if (walkOut && walkOut.className == "navDiv" && walkOut.className != 'stopHere') {
			walkOut.style.display='block';
			notThese.push(walkOut.id);
			prevSib = node_before(walkOut);
			}
		while(walkOut && walkOut.className != 'stopHere') {
			walkOut = walkOut.parentNode;
			if (walkOut && walkOut.className != 'stopHere' && walkOut.className == 'navDiv') {
				if(document.getElementById('heyYou')) {
					document.getElementById('heyYou').innerHTML += 'walkOut ' + walkOut.id + '\n';
					}
				walkOut.style.display='block';
				notThese.push(walkOut.id);
				}
			}
        }
	clearIt();
	}
	
function clearIt() {
	window.clearTimeout(winTimer);
	if(document.getElementById('heyYou')) {
		document.getElementById('heyYou').innerHTML += 'clearIt clearing timer\n';
		}
	for(var i=0;i<allNavs.length;i++) {
		if (inArray(allNavs[i], notThese)) {
			document.getElementById(allNavs[i]).style.display='block';
			if(document.getElementById('heyYou')) {
				document.getElementById('heyYou').innerHTML += allNavs[i] + ' is in notThese -- setting block\n';
				}
			}
		else {
			document.getElementById(allNavs[i]).style.display='none';
			if(document.getElementById('heyYou')) {
				document.getElementById('heyYou').innerHTML += allNavs[i] + ' is not in in notThese -- setting none\n';
				}
			}
		}
	}