var mfader
var mtimer

function showit(item,fade)	// show or fade in menu, hide all others
{ cancelhide()
  if (item != 'submenu2') {hideitem('submenu2')}
  if (item != 'submenu4') {hideitem('submenu4')}
  if (item != 0)
  { if (fade == 1) {fadein(item)} else {showitem(item) }  // drop could be grow, drop, slide, fadein
  }
}

function showitM(item,fade)	// show or fade in menu, hide all others - Members menu
{ cancelhide()
  if (item != 'submenuM3') {hideitem('submenuM3')}
  if (item != 'submenuM4') {hideitem('submenuM4')}
  if (item != 'submenuM5') {hideitem('submenuM5')}
  if (item != 0)
  { if (fade == 1) {fadein(item)} else {showitem(item) }  // drop could be grow, drop, slide, fadein
  }
}

// hideit is called on mouse out when a menu is to be hidden. The function checks the mouse target
// to determine if menu should not be hidden after all

function hideit (item,e)	// item is the menu being hidden, e is the event object
{ //cancelhide()
  window.clearTimeout(mtimer)
  if (!e) var e = window.event;

  e.cancelBubble = true;
  if (e.stopPropagation) e.stopPropagation();

  if (e.toElement) { eto = e.toElement }else{ eto = e.relatedTarget }

  if (containedin(eto,item)) return
  if (containedin(eto,"sub"+item)) return
  if (containedin(eto,"menuitem"+item.substr(7,1))) return
  mtimer = window.setTimeout("fadeout('" + item + "')",1000)	// set timer to fade out menu after 1 second
}

function cancelhide()		// cancel current timer and any fader in operatiuon
{ window.clearTimeout(mtimer)
  window.clearInterval(mfader)
}

function showitem(item)		// show menu instantly
{ var obj = document.getElementById(item)
  obj.style.opacity = 1
  if (obj.filters) {obj.filters.alpha.opacity = 100}
  obj.style.visibility = 'visible'
}

function hideitem(item)		// hide menu instantly
{ var obj = document.getElementById(item)
  obj.style.visibility = 'hidden'
  obj.style.opacity = 0
  if (obj.filters) {obj.filters.alpha.opacity = 0}
}

function fadeout(item)		// initiate menu fade out
{ var obj = document.getElementById(item)
  obj.style.visibility = 'visible'
  mfader = window.setInterval("fadeoutmore('" + item + "')",50)
}

function fadeoutmore(item)	// fade out a menu
{ var obj = document.getElementById(item), inc = .2, calc
  if (!obj.style.opacity) { obj.style.opacity = 1 }  
  calc = parseFloat(obj.style.opacity) - parseFloat(inc)
  obj.style.opacity = calc
  if (obj.filters) {obj.filters.alpha.opacity = (calc * 100)}
  if (obj.style.opacity <= 0)
  { window.clearInterval(mfader)
    obj.style.visibility = 'hidden'
  }
}

function fadein(item)		// initiate menu fade in
{ var obj = document.getElementById(item)
  obj.style.visibility = 'visible'
  mfader = window.setInterval("fadeinmore('" + item + "')",35)
}

function fadeinmore(item)	// fade in a menu
{ var obj = document.getElementById(item), fad = .2, opac
  if (!obj.style.opacity) { obj.style.opacity = 0 }  
  opac = parseFloat(obj.style.opacity) + parseFloat(fad)
  obj.style.opacity = opac
  if (obj.filters) {obj.filters.alpha.opacity = (opac * 100)}
  if (obj.style.opacity >= 1) {window.clearInterval(mfader)}
}

function containedin (elem,match)	// determines if elem is contained in an element whose id starts with match
{ var isContained = false, obj=elem
  do
  { if (!obj) break
    if (obj.id) if (isContained = obj.id.substr(0,match.length) == match) break;
//alert("processing "+elem.id+":\n in "+obj.id+" with parent "+obj.parentNode.id)
    if (obj.parentNode) obj = obj.parentNode; else break;
    if (obj.id == "menucontainer") break;	// that's high enough up the tree
  }
  while (obj.parentNode)
  //alert(elem.id+" in "+match+": "+isContained)
  return isContained
}
