<PUBLIC:COMPONENT
    lightWeight = true
>

<PUBLIC:DEFAULTS
    contentEditable = false
    tabStop = true
/>

<PUBLIC:attach event="ondocumentready" onevent="initElement()" />
<PUBLIC:attach event="onmouseover" onevent="elementOnMouseOver()" />
<PUBLIC:attach event="onmouseout" onevent="elementOnMouseOut()" />
<PUBLIC:attach event="onclick" onevent="elementOnClick()" />
<PUBLIC:attach event="onselectstart" onevent="elementOnSelect()" />
<PUBLIC:attach event="oncontextmenu" onevent="elementOnContextMenu()" />
<PUBLIC:attach event="ondetach" onevent="cleanupElement()" />

<PUBLIC:method   name="showMenu" />
<PUBLIC:method   name="hideMenu" />
<PUBLIC:method   name="setMenuEnabled" />
<PUBLIC:method   name="setMenuItem" />
<PUBLIC:method   name="getMenuItem" />

<PUBLIC:property name="menuState" value />
<PUBLIC:property name="subMenuState" value />

<script language="jscript">

// ----------------------------------------------------
// 2k3Widgets: 2k3Menu
//                                                     
// Copyright ©2002-2004 Stedy Software and Systems     
// Please see http://www.stedy.com for terms of use.   
// ----------------------------------------------------

var currentMenuItem = null ;
var currentSubMenu = null ;
var menuShadowArray = new Array(null, null, null, null) ;

function initElement() {
	element.menuState = makeBooleanOfAttribute("menuState") ;
	element.subMenuState = makeBooleanOfAttribute("subMenuState") ;
	for (var i = 0; i < element.children[1].children.length; i++) {
		var childElement = element.children[1].children[i] ;
		if (childElement.className != "2k3MenuSeperator") {
			if (!isElementEnabled(childElement)) {
				showDisabled(childElement) ;
			}
		}
	}
	childElement = null ;
	for (var i = 3; i >= 0; i--) {
		menuShadowArray[i] = window.document.createElement("SPAN") ;
		menuShadowArray[i].className = "2k3ShadowElement" ;
		element.parentElement.insertAdjacentElement("afterBegin", menuShadowArray[i]) ;
	}
}

function cleanupElement() {
	for (var i = 0; i <= 3; i++) {
		if (menuShadowArray[i] != null) {
			menuShadowArray[i].style.visibility = "hidden" ;
			menuShadowArray[i].removeNode(true) ;
			menuShadowArray[i] = null ;
		}
	}
}

function elementOnMouseOver() {
	var el = getRealItem(window.event.srcElement) ;
	if (el.className == "2k3MenuItem") {
		if (isElementEnabled(el)) {
			if (element.subMenuState) {
				if (currentSubMenu != null) {
					currentSubMenu.hideMenu() ;
					currentSubMenu = null ;
					showNormal(currentMenuItem) ;
					currentMenuItem = null ;
					element.subMenuState = false ;
				}
			}
			subMenuName = getElementSubMenu(el) ;
			if (subMenuName != "") { 
				showSubMenu(el) ;
			}
			showOver(el) ;
		}
	}
}

function elementOnMouseOut() {
	var el = getRealItem(window.event.srcElement) ;
	if (el != null) {
		var toEl = getRealItem(window.event.toElement) ;
		if (el.className == "2k3MenuItemOver") {
			if (toEl != currentMenuItem && el == currentMenuItem) {
				if (isElementEnabled(el)) {
					if (element.subMenuState) {
						if (toEl.className == "2k3MenuItem") {
							toEl = toEl.parentElement.parentElement ;
						}
						if (toEl != currentSubMenu) {
							if (currentSubMenu != null) {
								currentSubMenu.hideMenu() ;
								currentSubMenu = null ;
								showNormal(currentMenuItem) ;
								currentMenuItem = null ;
								element.subMenuState = false ;
							}
						}
						else {
							return ;
						}
					}
					showNormal(el) ;
				}
			}
		}
	}
}

function elementOnClick() {
	var el = getRealItem(window.event.srcElement) ;
	if (el.className == "2k3MenuItemDisabled") {
		with (window.event) {
			cancelBubble = true ;
			returnValue = false ;
		}
	}
}

function elementOnSelect() {
	with (window.event) {
		cancelBubble = true ;
		returnValue = false ;
	}
	return false ;
}

function elementOnContextMenu() {
	with (window.event) {
		cancelBubble = true ;
		returnValue = false ;
	}
	return false ;
}

function getRealItem(el) {
	if (el != null) {
		if (el.tagName.toLowerCase() == "img") {
			return el.parentElement.parentElement ;
		}
		if (el.tagName.toLowerCase() == "b") {
			el = el.parentElement ;
		}
		switch (el.className) {
			case "2k3MenuVerticalSpacerLeft":
				return el.parentElement ;
				break ;
			case "2k3MenuImage":
				return el.parentElement ;
				break ;
			case "2k3MenuCaption":
				return el.parentElement ;
				break ;
			case "2k3MenuMore":
				return el.parentElement ;
				break ;
			case "2k3MenuNoMore":
				return el.parentElement ;
				break ;
			case "2k3MenuVerticalSpacerRight":
				return el.parentElement ;
				break ;
			default:
				return el ;
				break ;
		}
	}
	else {
		return el ;
	}
}

function isElementEnabled(el) {
	if (el.enabled == null) {
		return true ;
	}
	el.enabled = (((el.enabled).toLowerCase() == "true") || el.enabled == "1") ;
	return (el.enabled) ;
}

function getElementSubMenu(el) {
	if (el.subMenu == null) {
		return "" ;
	}
	return el.subMenu ;
}

function showNormal(el) {
	el.className = "2k3MenuItem" ;
	currentMenuItem = null ;
}

function showOver(el) {
	el.className = "2k3MenuItemOver" ;
	currentMenuItem = el ;
}

function showDisabled(el) {
	with (el) {
		if (className == "2k3MenuItemDisabled") {
			return ;
		}
		className = "2k3MenuItemDisabled" ;
		onbeforecut = onclick ;
		onclick = null ;
	}
}

function showEnabled(el) {
	with (el) {
		if (className == "2k3MenuItem") {
			return ;
		}
		className = "2k3MenuItem" ;
		onclick = onbeforecut ;
		onbeforecut = null ;
	}
}

function setMenuEnabled(elName, blnState) {
	var el = window.document.getElementById(elName) ;
	if (el != null) {
		switch (blnState) {
			case true:
				showEnabled(el) ;
				break ;
			case false:
				showDisabled(el) ;
				break ;
		}
	}
}

function showMenuShadow(el, x, y) {
	el.style.zIndex = 1000 ;
	for (var i = 3; i >= 0; i--) {
		with (menuShadowArray[i].style) {
			left = x + (4 + i) ;
			top = y + (4 + i) ;
			width =  el.offsetWidth - (i * 2) ;
			height = el.offsetHeight - (i * 2) ;
			zIndex = el.style.zIndex - 1 ;
			visibility = "visible" ;
		}
	}
}

function hideMenuShadow() {
	for (var i = 0; i <= 3; i++) {
		if (menuShadowArray[i] != null) {
			menuShadowArray[i].style.visibility = "hidden" ;
		}
	}
}

function showMenu(x, y, w) {
	with (element.style) {
		left = x ;
		top = y ;
		try {
			if (w != 0) {
				with (element.children(0).children(0).children(0).children(0).style) {
					display = "" ;
					width = w ;
					top = element.offsetTop - y - 1 ;
					left = element.offsetLeft - x ;
				}
			}
			else {
				with (element.children(0).children(0).children(0).children(0).style) {
					width = 0 ;
				}
			}
		}
		catch(e) {
		
		}
		showMenuShadow(element, x, y) ;
		visibility = "visible" ;
	}
	element.menuState = true ;
}

function hideMenu() {
	if (element.subMenuState) {
		if (currentSubMenu != null) {
			currentSubMenu.hideMenu() ;
			currentSubMenu = null ;
		}	
		if (currentMenuItem != null) {
			showNormal(currentMenuItem) ;
			currentMenuItem = null ;
		}
		element.subMenuState = false ;
	}
	hideMenuShadow() ;
	element.style.visibility = "hidden" ;
	element.menuState = false ;
}

function showSubMenu(el) {
	currentSubMenu = window.document.getElementById(el.subMenu) ;
	if (currentSubMenu != null) {
		with (element) {
			var x = offsetLeft + offsetWidth - 1 ;
			var y = offsetTop + el.offsetTop ;
		}
		currentSubMenu.showMenu(x, y, 0) ;
		currentSubMenu.style.zIndex = element.style.zIndex + 5 ;
		element.subMenuState = true ;
	}
}

function setMenuItem(el) {
	currentMenuItem = el ;
}

function getMenuItem() {
	return currentMenuItem ;
}

function makeBooleanOfAttribute(attName) {
	a = element.getAttribute(attName) ;
	if (typeof(a) == "boolean") {
		return a ;
	}
	else if (a == null) {
		a = false ;
	}
	else if (typeof(a) == "string") {
		a = a.toLowerCase() ;
		a = (a == "true" || a == "1" || a == "yes") ;
	}
	else {
		a = new Boolean(a) ;
	}
	return a ;
}

</script>

</PUBLIC:COMPONENT>