/* ========================== */
// 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.customNavList 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 customMenuActive = null;
var customSubMenuActive = null;
var customMenuTimeout = null;
var customSubMenuTimeout = null;
var customSubMenuOn = 0;
var customMenuOn = 0;
var customMenuShowHideSelects = 1; //1 or 0, includes hiding of SELECTs with menu operation
var customMenuFormat = "horizontal"; //This may be changed via xsl 

function customMenuShow(menuId)
{
	/*Shows menu and sets menu active toggle*/
	
	customSetVisibilityStyle('customNav' + menuId,'visible');
	customMenuOn = 1;
	//customMenuImgToggle(menuId,1);
}

function customMenuHide(menuId)
{
	/*Hides menu only if menu not still active*/

	if(customMenuOn == 0)
	{	
		customSetVisibilityStyle('customNav' + menuId,'hidden');
		customMenuOn = 0;
		customMenuActive = null;
		//customMenuImgToggle(menuId,0);
		customSelectsToggle(0);
	}
}

function customMenuInit(menuId)
{
	/*Inits new menu and hides any other ones*/
	
	clearTimeout(customMenuTimeout); //cancel any pending actions for other menus
	if(customMenuActive != null) //hide other active menus
	{
		customMenuHide(customMenuActive);
	}
	
	customMenuShow(menuId); //show requested menu
	customMenuActive = menuId; //set this menu as current active
	customSelectsToggle(1);
}

function customMenuDrop(menuId)
{
	/*Sets customMenuOn to 0 but Timeout() allows time for customMenuOn to be
	/set to 1 if rolling onto a new menu of same list*/

	customMenuOn = 0;
	customMenuTimeout = eval("setTimeout('customMenuHide(" + menuId + ")',100)");
}

// Menu show/hide
/* ========================== */



/* ========================== */
// Sub-menu show/hide

function customSubMenuInit(menuId,subMenuId)
{
	/*Inits sub menu ('third' level)*/
	
	var thisMenuRef = 'customNav' + 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 (customMenuStyle=="cells") { if(thisMenuTop != 0) { thisMenuTop = thisMenuTop - 1;}}*/
	
	//Not using the 3rd level menu item display for now  
	/*var thisSubMenu = document.getElementById(thisMenuRef + 'Menu');
	thisSubMenu.style.top = thisMenuTop + 'px';
	
	clearTimeout(customSubMenuTimeout);
	if(customSubMenuActive != null)//hide other active menus
	{
		customSubMenuHide(menuId,customSubMenuActive);
	}
	customSubMenuShow(menuId,subMenuId);//show requested sub menu
	customSubMenuActive = subMenuId;*/
}

function customSubMenuDrop(menuId,subMenuId)
{
	/*Inits sub menu ('third' level)*/

	var thisSubMenu = document.getElementById('customNav' + menuId + subMenuId + 'Menu');
	
	customSubMenuOn = 0;
	customSubMenuTimeout = eval("setTimeout('customSubMenuHide(" + menuId + "," + subMenuId + ")',100)");
}

function customSubMenuShow(menuId,subMenuId)
{
	/*Shows menu and sets menu active toggle*/

	customSetVisibilityStyle('customNav' + menuId  + subMenuId + 'Menu','visible');
	customSubMenuOn = 1;
}

function customSubMenuHide(menuId,subMenuId)
{
	/*Hides menu only if menu not still active*/

	if(customSubMenuOn == 0)
	{
		customSetVisibilityStyle('customNav' + menuId  + subMenuId + 'Menu','hidden');
		customSubMenuOn = 0;
		customSubMenuActive = null;
	}
}

// Sub-menu show/hide
/* ========================== */


/* ========================== */
// Menu common functions

function customSetVisibilityStyle(idRef,styleRef)
{
	/*Sets style.visibility for idRef (Not using 'display' for older Opera support)*/

	var el = document.getElementById(idRef);
	el.style.visibility = styleRef;
}

function customSelectsToggle(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(customMenuShowHideSelects)
	{
		//show/hide selects
		var selectsOnPage = document.getElementsByTagName('SELECT'); //TODO: 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 customMenuImgToggle(idRef,showActiveImg)
{
	/*On rollover of menu tab img, changes src to 'over' image as
	/specified in images array*/

	var imgElement = document.getElementById('customNavImg' + idRef);
		
	if(showActiveImg)
	{
		imgElement.src = eval("umiover" + idRef + ".src");
	}
	else
	{
		imgElement.src = eval("umidefault" + idRef + ".src");
	}
}

// Menu common functions
/* ========================== */