/* These are some routines to handle a hierarchical pull-down or pop-up menu system */
/* (c)2007, Red Beagle Web Development */

var collapseCount=0;			// This indicates the most recent collapse request. Only the most recent collapse will be honored
//var collapseFlag=false;			// The flag says if the collapse request should be honored.
var thisPage='';
var thisImage='';
var collapseDelay=400;			// milliseconds of delay until the menu disappears, after rollout.

function highlight() {		// Hightlight an area
	for (i=0; i<highlight.arguments.length; i+=2) {
		if (highlight.arguments[i]!=thisPage) {
			var obj=document.getElementById(highlight.arguments[i]);
			var str=highlight.arguments[i+1];
			if (str.indexOf(".")>-1) {	// Then it's an image
				obj.src=imageDir+str;
			} else {
				obj.style.background=str;
			}
		}
	}
}

function newImage(arg) { 
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function setActivePageButton(aa, bb) {		// The image with the id thisPage should stay frozen at image thisImage.
											// This is intended to indicate the active page. The menu should still operate like normal
	if (aa.length>0) {
		thisPage=aa;
		thisImage=bb;
		var obj=document.getElementById(thisPage);
		obj.src=imageDir+thisImage;
	}
	for (i=0; i<preloadImage.length; i++) {
		imgz=newImage(imageDir+preloadImage[i]);
	}
}

function rossReveal(id) {			// Reveal a menu
	var obj=document.getElementById(id);
	obj.style.display="block";
}

function rossConceal() {			// Conceal all the <div> in the argument list
	for(i=0; i<rossConceal.arguments.length; i++) {
		var obj=document.getElementById(rossConceal.arguments[i]);
		obj.style.display="none";
	}
}

function cancelCollapse() {			// Cancel the current collapse request(s)
									// Simply incrementing collapseCount will cause collapseMenu to fail for any
									// scheduled collapse.
//	collapseFlag=false;
	collapseCount++;
}

function scheduleCollapse() {		// Schedule a new collapse. Note this increments the collapseCount, so no previous collapse request will be honored
	collapseCount++;
//	collapseFlag=true;
	setTimeout("collapseMenu("+collapseCount+")", collapseDelay);
}

function collapseMenu(z) {			// Collapse all menus when I get to this point.
//	if (z==collapseCount && collapseFlag) {
	if (z==collapseCount) {
		for (i=0; i<allMenus.length; i++) {
			var obj=document.getElementById(allMenus[i]);
			obj.style.display="none";
		}
		collapseFlag=false;
	}
}

// locateMenu(target, source submenu, source menu): locate a menu on the screen in keeping w proper locations.
// target is placed just to the right of its submenu.
function locateMenu(targ, source, source2) {
	var obj=document.getElementById(targ);
	var obj2=document.getElementById(source);
	var obj3=document.getElementById(source2);
	left=(obj2.offsetWidth+obj2.offsetLeft+obj3.offsetLeft+1);	// +1 for the border width, -1 in the next line for same
	// If the source item has a forced width, impose this width instead of the natural width, object2.offsetWidth
	if (!isNaN(forcedWidth[source])) left=(forcedWidth[source]+obj2.offsetLeft+obj3.offsetLeft+1);
	ttop=(obj2.offsetTop+obj3.offsetTop-1);
	obj.style.left=left+"px";
	obj.style.top=ttop+"px";
}
