var images = 'images/menu/', menu_name = '', menu_obj, mtimer

// put menu items into secondary menu (not on home section)

function add_menu2_items()
{ if (document.getElementById('menu2items2'))	//(section != 'home')
  { var menu_items = document.getElementById('m2' + section).innerHTML		// set submenu contents
//alert(menu_items)
    document.getElementById('menu2items2').innerHTML = menu_items
  }
}

// menuover: show cyan button, change menu ends to squared, show menu2 with appropriate content

function menuover(item,e)
{ if (!e) var e = window.event;
  e.cancelBubble = true;
  if (e.stopPropagation) e.stopPropagation();

  clearTimeout(mtimer)

  if (menu_name != '')
    if (menu_name == section) menu_obj.src = images + 'menu_' + menu_name + '_orange.gif'	// replace with orange menu item
    else menu_obj.src = images + 'menu_' + menu_name + '_grey.gif'		// replace with grey menu item

  menu_obj = item
  menu_name = menu_obj.id.substr(1)
  //alert(menu_name)
  menu_obj.src = images + 'menu_' + menu_name + '_cyan.gif'			// current menu item becomes cyan

  menu_items = document.getElementById('m2' + menu_name).innerHTML		// set submenu contents
  document.getElementById('menu2items').innerHTML = menu_items

  document.getElementById('menu2').style.display = 'block'
  document.getElementById('menu_left_end').src = images + 'menu_left_end_squared.gif'
  document.getElementById('donate').src = images + 'menu_donate_squared.jpg'
}

function menu2over(item,e)
{ if (!e) var e = window.event;
  e.cancelBubble = true;
  if (e.stopPropagation) e.stopPropagation();

  clearTimeout(mtimer)
}
// menuout: show standard button, change menu ends to rounded if home page

function menuout(e)
{ 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,'floating_bar')) return	// don't hide submenu if still inside floating_bar

  mtimer = setTimeout('menuhide()',1000)
}

function menuhide()
{ if (menu_name != '')
    if (menu_name == section) menu_obj.src = images + 'menu_' + menu_name + '_orange.gif'	// replace with orange menu item
    else menu_obj.src = images + 'menu_' + menu_name + '_grey.gif'	// replace with grey menu item

  document.getElementById('menu2').style.display = 'none'	// hide submenu
  menu_name = ''

  if (section == 'home')	// put appropriate ends on main menu (section set by php in calling page)
  { document.getElementById('menu_left_end').src = images + 'menu_left_end_rounded.gif'
    document.getElementById('donate').src = images + 'menu_donate_rounded.jpg'
  }
}

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 == "content") break;	// that's high enough up the tree
  }
  while (obj.parentNode)
  //alert(elem.id+" in "+match+": "+isContained)
  return isContained
}
