/* 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 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;
		document.getElementById(thisPage).src=imageDir+thisImage;
	}
	for (i=0; i<preloadImage.length; i++) {
		imgz=newImage(imageDir+preloadImage[i]);
	}
}

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

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

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

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

function collapseMenu(z) {			// Collapse all menus when I get to this point.
	if (z==collapseCount) {
		for (i=0; i<allMenus.length; i++) {
			document.getElementById(allMenus[i]).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";
}

// 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 locateMenuSouth(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.offsetHeight+obj2.offsetTop+obj3.offsetTop+1);	// +1 for the border width, -1 in the next line for same
	if (!isNaN(forcedWidth[source])) ttop=(forcedWidth[source]+obj2.offsetTop+obj3.offsetTop+1);
	left=(obj2.offsetLeft+obj3.offsetLeft-1);
	obj.style.left=left+"px";
	obj.style.top=ttop+"px";
}

function rossNewWindow(mypage, myname, w, h, scroll)
{
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = "height="+h+",width="+w+",top="+wint+",left="+winl+",scrollbars="+scroll
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}

function rossFindHeight(arg) {
	obj=document.getElementById(arg);
	if (obj.offsetHeight) return obj.offsetHeight;
	else return 0;
}

function talkHeight() {
	maxxie=0;
	for(i=0; i<talkHeight.arguments.length; i++) { // alert(isNaN(talkHeight.arguments[i]));
		if (isNaN(talkHeight.arguments[i])) maxxie=Math.max(maxxie, rossFindHeight(talkHeight.arguments[i]));
		else maxxie=Math.max(maxxie, parseInt(talkHeight.arguments[i]));
	}
	for(i=0; i<talkHeight.arguments.length; i++) {
		if (typeof(talkHeight.arguments[i])!="number") document.getElementById(talkHeight.arguments[i]).style.height=maxxie+"px";;
	}
}
