﻿/* ========================== */
// Windows IE bug fix

/*For Windows IE only, make the LIs 'inline' to work around spacing bug.*/

if (document.createStyleSheet)//IE only
{ 
	if(navigator.userAgent.indexOf("Mac") == -1)//but not MacIE
	{
		with (document.createStyleSheet())
		{
			addRule("ul.unityNavList li","display:inline"); //add rule
			
			/*Applying this directly stopped Opera being able to get
			/offsetHeight. Also should be left as block in theory.*/
		}
	}
} 

// Windows IE bug fix
/* ========================== */


/* ========================== */
// Menu show/hide

/*These are rendered with element.style.visibility and setTimeout() as key
/operational elements for widest browser compatibility.*/

var unityMenuActive = null;
var unitySubMenuActive = null;
var unityMenuTimeout = null;
var unitySubMenuTimeout = null;
var unitySubMenuOn = 0;
var unityMenuOn = 0;
var unityMenuShowHideSelects = 1;//1 or 0, includes hiding of SELECTs with menu operation
var unityMenuFormat = "horizontal"; //This may be changed via xsl 

function unityMenuShow(menuId)
{
	/*Shows menu and sets menu active toggle*/

	unitySetVisibilityStyle('unityNav' + menuId,'visible');
	unityMenuOn = 1;
	unityMenuImgToggle(menuId,1);
}

function unityMenuHide(menuId)
{
	/*Hides menu only if menu not still active*/

	if(unityMenuOn == 0)
	{	
		unitySetVisibilityStyle('unityNav' + menuId,'hidden');
		unityMenuOn = 0;
		unityMenuActive = null;
		unityMenuImgToggle(menuId,0);
		unitySelectsToggle(0);
	}
}

function unityMenuInit(menuId)
{
	/*Inits new menu and hides any other ones*/
	
	clearTimeout(unityMenuTimeout);//cancel any pending actions for other menus
	if(unityMenuActive != null)//hide other active menus
	{
		unityMenuHide(unityMenuActive);
	}
	
	unityMenuShow(menuId);//show requested menu
	unityMenuActive = menuId;//set this menu as current active
	unitySelectsToggle(1);
}

function unityMenuDrop(menuId)
{
	/*Sets unityMenuOn to 0 but Timeout() allows time for unityMenuOn to be
	/set to 1 if rolling onto a new menu of same list*/

	unityMenuOn = 0;
	unityMenuTimeout = eval("setTimeout('unityMenuHide(" + menuId + ")',100)");
}

// Menu show/hide
/* ========================== */



/* ========================== */
// Sub-menu show/hide

function unitySubMenuInit(menuId,subMenuId)
{
	/*Inits sub menu ('third' level)*/
	
	var thisMenuRef = 'unityNav' + menuId  + subMenuId;
	
	//align sub menu block next to parent menu item
	var thisMenu = document.getElementById(thisMenuRef);
	var thisMenuTop = thisMenu.offsetTop;
	<!--trim for border width-->
	if (unityMenuStyle=="cells") { if(thisMenuTop != 0) { thisMenuTop = thisMenuTop - 1;}}

	var thisSubMenu = document.getElementById(thisMenuRef + 'Menu');
	thisSubMenu.style.top = thisMenuTop + 'px';
	
	clearTimeout(unitySubMenuTimeout);
	if(unitySubMenuActive != null)//hide other active menus
	{
		unitySubMenuHide(menuId,unitySubMenuActive);
	}
	unitySubMenuShow(menuId,subMenuId);//show requested sub menu
	unitySubMenuActive = subMenuId;
}

function unitySubMenuDrop(menuId,subMenuId)
{
	/*Inits sub menu ('third' level)*/

	var thisSubMenu = document.getElementById('unityNav' + menuId + subMenuId + 'Menu');
	
	unitySubMenuOn = 0;
	unitySubMenuTimeout = eval("setTimeout('unitySubMenuHide(" + menuId + "," + subMenuId + ")',100)");
}

function unitySubMenuShow(menuId,subMenuId)
{
	/*Shows menu and sets menu active toggle*/

	unitySetVisibilityStyle('unityNav' + menuId  + subMenuId + 'Menu','visible');
	unitySubMenuOn = 1;
}

function unitySubMenuHide(menuId,subMenuId)
{
	/*Hides menu only if menu not still active*/

	if(unitySubMenuOn == 0)
	{
		unitySetVisibilityStyle('unityNav' + menuId  + subMenuId + 'Menu','hidden');
		unitySubMenuOn = 0;
		unitySubMenuActive = null;
	}
}

// Sub-menu show/hide
/* ========================== */




/* ========================== */
// Menu common functions

function unitySetVisibilityStyle(idRef,styleRef)
{
	/*Sets style.visibility for idRef
	(Not using 'display' for older Opera support)*/

	var el = document.getElementById(idRef);
	el.style.visibility = styleRef;
}

function unitySelectsToggle(showSelects)
{
	/*Uses DOM to loop through all SELECTs on page and toggle visiblity.
	On some systems SELECTs always higher z-index than DHTML elements.
	Enables pull down menus not be obstructed.*/
	var count = 0;
	if(unityMenuShowHideSelects)
	{
		//show/hide selects
		var selectsOnPage = document.getElementsByTagName('SELECT');//TODO:Rod ?? set on BODY onload event ??
		
		/*Note: not using gt or lt*/
		if(selectsOnPage.length!=0)
		{
			for ( ; ; )
			{
				//cannot use a "for-in" loop here - ask RB for details
				try 
				{
					selectsOnPage[count].style.visibility = (showSelects)? 'hidden':'visible';					
					count++;
					if(count==selectsOnPage.length)
					{
						break;
					}
				} 
				catch(e) 
				{
					break;
				}
			}
		}
	}
}

function unityMenuImgToggle(idRef,showActiveImg)
{
	/*On rollover of menu tab img, changes src to 'over' image as
	/specified in images array*/

	var imgElement = document.getElementById('unityNavImg' + idRef);
		
	if(showActiveImg)
	{
		imgElement.src = eval("umiover" + idRef + ".src");
	}
	else
	{
		imgElement.src = eval("umidefault" + idRef + ".src");
	}
}

// Menu common functions
/* ========================== */