function getInnerWindowWidth()
{
	if (window.innerWidth != null)
	{
		return window.innerWidth;
	}
	if (document.body.clientWidth != null)
	{
		return document.body.clientWidth;
	}
	//alert("Error: getInnerWindowWidth Failed!!!");
	return 0;
}

function getInnerWindowHeight()
{
	if (window.innerHeight != null)
	{
		return window.innerHeight;
	}
	if (document.body.clientHeight != null)
	{
		return document.body.clientHeight;
	}
	//alert("Error: getInnerWindowHeight Failed!!!");
	return 0;
}

function setPos(item, x, y)
{
	innerWindowWidth = getInnerWindowWidth();

	if (innerWindowWidth == 0)
	{
		//alert("Error: setPos Failed: received innerWindowWidth = 0");
		return 0;
	}

	innerWindowCenter = innerWindowWidth/2;

	posLeft = innerWindowCenter - 690/2; // innerWindowCenter minus half the content table width should give left edge of content table

	// adjust posLeft for smaller windows
	if (posLeft < invisibleborder)
	{
		posLeft = invisibleborder;
	}

	if (window.document.getElementById(item))
	{
		obj = window.document.getElementById(item);
	}
	else
	{ 
		//alert("Error: setPos Failed: obj = null");
		return 0;
	}

	obj_style = obj.style;

	adjX = posLeft + x;

	// most browsers automatically recast numbers as strings when 
	// assigning a number to a string variable, but ie/mac requires 
	// explicit casting and since this also works in all other tested browser, 
	// we use explicit recast for all.
	xs = adjX.toString() + "px";
	ys = y.toString() + "px";

	obj_style.left = xs;
	obj_style.top = ys;

	return 1;
}

function show(item)
{
	if (window.document.getElementById(item)) 
	{ 

		// initialize menu positions ( baseline )

		xposobj = window.document.getElementById(item + "xpos");
		xposi = xposobj.value;
		xpos = xposi - 1;

		yposobj = window.document.getElementById(item + "ypos");
		ypos = yposobj.value;
		ypos = ypos - 1;

		levelobj = window.document.getElementById(item + "level");
		level = levelobj.value;

		if (level == 1)
		{
			xRel = xpos*menuwidth;
		}
		else
		{
			xRel = xpos*menuwidth + (level - 1)*(submenuwidth - menuwidth);
		}

		innerWindowWidth = getInnerWindowWidth();
		innerWindowCenter = innerWindowWidth/2;

		//if ( xRel > innerWindowCenter && level > 1 )
		if ( ( xRel > innerWindowCenter && level > 1 ) || (xposi > xposmax && level > 1) )
		{
			xRel = xRel - 2*submenuwidth;
		}

		// top level submenu on far right is to flop inward ???		//if ( item == farrightsubmenu )
		//if ( (xposi == xposmax && level == 1) || (xposi >= xposmax && level > 1) )
		if ( (item == farrightsubmenu) || (xposi > xposmax && level > 1) )
		{
			xRel = xRel - (submenuwidth - menuwidth);
		}


		yAbs = menuYpos + ypos*menuheight;
		zAbs = level + 1;


		// adjust menu positions based on browser and platform

		innerWindowWidth = getInnerWindowWidth();

		if ( bd.platform == "Win") 
		{
			if ( (bd.browser == "Gecko") && (window.scrollMaxY != 0) && (innerWindowWidth >= 760))
			{
				xRel = xRel - scrollbarwidth;
			}
			else if ( bd.browser == "MSIE" && bd.majorver == "5" ) // MSIE 5.x
			{
				yAbs = yAbs - scrollbarwidth;
			}
			else
			{
				// no adjustment
			}

		} // end if Win


		if ( bd.platform == "Unix") 
		{
			if ( (bd.browser == "Gecko") && (window.scrollMaxY != 0) && (innerWindowWidth >= 760))
			{
				xRel = xRel - scrollbarwidth;
			}

		} // end if Unix


		if ( bd.platform == "Mac") 
		{
			if ( (bd.browser == "Gecko") && (window.scrollMaxY != 0) && (innerWindowWidth >= 760))
			{
				xRel = xRel - scrollbarwidth;
			}

		} // end if Mac


		xRel = xRel - submenupadding; // adjust for submenu padding
		setPosResult = setPos(item, xRel, yAbs);
		if (setPosResult == 1)
		{
			dv = window.document.getElementById(item);
			dv_style = dv.style;
			dv_style.visibility = "visible";
			dv_style.zIndex = zAbs;
		}

	}
	else
	{
		// window.document.getElementById(item) returns null
		//alert("Error: show Fails: window.document.getElementById(item) returns null");

	} // end if getElementById(item)

} // end show(item) 


function hide(item)
{
	if (window.document.getElementById(item)) 
	{ 
		dv = window.document.getElementById(item);
		dv_style = dv.style;
		dv_style.visibility = "hidden";
	}
}

function hidelevels(lvl, smla, length) {
	for (var i=0; i<=length - 1; i+=1){
		if (!smla[i]) { break; };
		sml = smla[i];
		smll = sml + "level";
		if (!document.getElementById(smll)) { throw("No Dom for smll !!!"); return; };
		if (!document.getElementById(sml)) { throw("No Dom for sml !!!"); return; };
		zeleml = document.getElementById(smll); 
		zelem = document.getElementById(sml); 
		if ( zeleml.value > lvl )
		{
			zelem.style.visibility = "hidden";
		}
	}
}

function hideall()
{
	for (var i=0; i<=submenuslist.length - 1; i+=1){
		if (!submenuslist[i]) { break; };
		smli = submenuslist[i];
		hide(smli);
	}
}

