/*
' Start Header-----------------------------------------------------------
'
'     Creo Inc.
'     Burnaby, BC, Canada
'     V5G 4M1
'
'     Copyright (c)2004 Creo Inc.
'     Reproduction or disclosure of this file or its contents without
'     the prior written consent of Creo Inc. is prohibited.
'
'     File Name:   incMenus.js
'
'     Purpose:     JavaScript functions to provide support for DHTML
'                  menus using image maps.  Currently only used by
'                  webRUser/login.asp.
'
'                  Assumes the image names are <menuId>Up and 
'                  <menuId>Over for the regular and hover states.
'
'     Language(s): JavaScript
'
'     Platform:    IIS 5.0 on Windows 2000
'
'     Project:     InSite
'
' End Header-------------------------------------------------------------
*/

// Local constants -- also defined in incLogin.asp
var kImageSuffix_RegularState = "Up";
var kImageSuffix_HoverState = "Over";


/************************************************************ InitMaps()
*
* Initializes the image maps on this page.  Accepts a list
* of string IDs identifying maps.
*
************************************************************/
function InitMaps() {
  
	if ( document.getElementById ) {
		var mapIds = InitMaps.arguments;			// pass string IDs of containing map elements
		var i, j, area, areas;
		for (i = 0; i < mapIds.length; i++) {
			areas = document.getElementById(mapIds[i]).getElementsByTagName("area");
	
			for (j = 0; j < areas.length; j++) {// loop thru image elements
				area = areas[j];
				area.onmouseout = ImageSwap;        // set event handlers
				area.onmouseover = ImageSwap;
			}
		}
	}
} // InitMaps


/************************************************************ ImageSwap()
*
* Swaps in the correct map and clips out everything but
* the item we need.
*
************************************************************/
function ImageSwap( evt ) {
  
	evt = (evt) ? evt : event;
	var menuElement = (evt.target) ? evt.target : evt.srcElement;
	var menuId = menuElement.parentNode.name;
	var coords = menuElement.coords.split(",");
	var clipVal = "rect(" + coords[1] + "px " +
							coords[2] + "px " +
							coords[3] + "px " +
							coords[0] + "px)";
	var imgStyle;
	
	switch (evt.type) {
		case "mouseout" :
			document.getElementById( menuId + kImageSuffix_HoverState ).style.visibility = "hidden";
			break;
		case "mouseover" :
			imgStyle = document.getElementById( menuId + kImageSuffix_HoverState ).style;
			imgStyle.clip = clipVal;
			imgStyle.visibility = "visible";
			break
	}
	evt.cancelBubble = true;
	return false;
	
} // ImageSwap


/************************************************************ ToggleMenu()
*
* Shows or hides the menu, depending on its current 
* visibility.
*
************************************************************/
function ToggleMenu( menuId )
{
  var menuElement;
  
  menuElement = document.getElementById( menuId + kImageSuffix_RegularState );
  
  if ( menuElement.style.visibility == "visible" )
  {
    HideMenu( menuId );
  }
  else
  {
    menuElement.style.visibility = "visible";
  }
    
} // ToggleMenu


/************************************************************ HideMenu()
*
* Hides the menu.
*
************************************************************/
function HideMenu( menuId )
{
  document.getElementById( menuId + kImageSuffix_RegularState ).style.visibility = "hidden";
  document.getElementById( menuId + kImageSuffix_HoverState ).style.visibility = "hidden";
  
} //HideMenu

