function containerNode(e)
{
  if (e && e.parentNode) e=e.parentNode;
  while (e && e.tagName && e.tagName!='IFRAME' && e.tagName!='DIV' && e.tagName!='BODY' && e.parentNode)
    e=e.parentNode;
  return e;
}


function showSubMenu(menu)
{
  main=document.getElementById('menu_'+menu);
  sub=document.getElementById('submenu_'+menu);

  // Hide other divisions
  elist=document.getElementsByTagName('div');
  for (i=0; i<elist.length; i++)
  {
    e=elist[i];
    if ((!sub || e!=sub) && e.className=='submenu' && e.style.visibility=='visible')
      if (!menu || menu=='') fader.fade(e.id, 0, 1000, -1500);
      else fader.fade(e.id, 0, 700, -1000);
  }

  // Position the submenu
  if (main)
  {
    cnode=containerNode(sub);
    x=main.offsetLeft;
    if (x+sub.offsetWidth>cnode.offsetWidth) x=cnode.offsetWidth-sub.offsetWidth;
    y=main.offsetTop+main.offsetHeight;
    if (navigator.appName=='Opera') y-=document.getElementsByTagName('html')[0].scrollTop; // Opera bug #270987
    sub.style.left=x+'px';
    sub.style.top=y+'px';

    // Show the submenu
    fader.fade(sub.id, 300, 1000, 300);
  }
}


function togglevis(id)
{
  e=document.getElementById(id);
  if (!e) return;

  // Hide other divisions
  elist=document.getElementsByTagName('div');
  for (i=0; i<elist.length; i++)
  {
    if (elist[i]!=e) elist[i].className='nomore';
  }

  // Toggle the requested division
  if (e.className=='nomore') e.className='more';
  else e.className='nomore';

  document.body.focus();
}


function humansonly(id, text, link)
{
  element=document.getElementById(id);
  if (element==undefined) return;

  if (text!=null)
  {
    t='';
    for (i in text) t+=String.fromCharCode(142-text[i]);
    element.innerHTML=t;
  }

  if (link!=null && element.href)
  {
    l='';
    for (i in link) l+=String.fromCharCode(142-link[i]);
    element.href=l;
  }
}


function cyclephoto(id)
{
  /* Read parameters from DOM */
  e=document.getElementById(id);
  if (!e) { alert('No element with id '+id+'!'); return false; }

  if (!e.urllist) e.urllist=e.getAttribute('cyclephoto_urllist').split('|||');
  if (!e.desclist) e.desclist=e.getAttribute('cyclephoto_desclist').split('|||');
  if (!e.width) e.width=e.getAttribute('cyclephoto_width');
  if (!e.height) e.height=e.getAttribute('cyclephoto_height');
  if (!e.urllist || !e.desclist || !e.width || !e.height) { alert('Missing attributes'); return false; }

  if (!e.current) e.current=0;
  e.current++;
  if (e.current >= e.urllist.length) e.current=0;

  e.innerHTML='<img alt="'+e.desclist[e.current]+'" src="'+e.urllist[e.current]+'" width="'+e.width+'" height="'+e.height+'">'+e.desclist[e.current];
}

