// xmenu5.js, part of X, a Cross-Browser.com Javascript Library
// Copyright (C) 2004,2005 Michael Foster - Distributed under the terms of the GNU LGPL - OSI Certified
// File Rev: 5


/***
  xMenu5
  Only one branch per level can be open.
  Assumes btnClass element to be a direct child of an LI,
  tho it doesn't have to be the first child.
  Assumes the btn's corresponding UL to be a sibling,
  tho it doesn't have to be the next sibling.
***/

function xMenu5(idUL, btnClass, lblClass, idAutoOpen) // object prototype
{
  // Constructor
  var i, ul, btns, labelClick = true, mnu = xGetElementById(idUL);
  btns = xGetElementsByClassName(btnClass, mnu, 'DIV');
  lbls = xGetElementsByClassName(lblClass, mnu, 'DIV');
  for (i = 0; i < btns.length; ++i) {
    ul = xNextSib(btns[i], 'UL');
    btns[i].xClpsTgt = ul;
    btns[i].onclick = btn_onClick;
    lbls[i].xClpsTgt = ul;
    lbls[i].onclick = btn_onClick;
    set_display(lbls[i], 0);
  }
  if (idAutoOpen) {
    var e = xGetElementById(idAutoOpen);
    while (e && e != mnu) {
      if (e.xClpsTgt) set_display(e, 1);
      while (e && e != mnu && e.nodeName != 'LI') e = e.parentNode;
      e = e.parentNode; // UL
      while (e && !e.xClpsTgt) e = xPrevSib(e);
    }
  }
  // Private
  
  function btn_onClick()
  {
    var thisLi, fc, pUl, elClass = this.className, searchLbl = /xMenuLbl/;
	if(searchLbl.test(elClass)) labelClick = true
	else labelClick = false
	if(this.xClpsTgt){
		if (this.xClpsTgt.style.display == 'none') {
		  if(this.id != "secondLevelElement"){SetLastOpen("LastID", this.id, 1000*60*20)}
		  set_display(this, 1);
		  // get this label's parent LI
		  var li = this.parentNode;
		  thisLi = li;
		  pUl = li.parentNode; // get this LI's parent UL
		  li = xFirstChild(pUl); // get the UL's first LI child
		  // close all labels' ULs on this level except for thisLI's label
		  while (li) {
			if (li != thisLi) {
			  fc = xFirstChild(li);
			  if (fc && fc.xClpsTgt) {
				set_display(fc, 0);
			  }
			}
			li = xNextSib(li);
		  }
		}  
		else {
		  if(xPrevSib(this.parentNode.parentNode)){
		  	SetLastOpen("LastID", xPrevSib(this.parentNode.parentNode).id, 1000*60*20)
		  }else if(this.id!="topLevelElement"){
			SetLastOpen("LastID",-1, 1000*60*20)
		  }
		set_display(this, 0);
		}
	 }
  }

  function set_display(ele, bBlock)
  {
    if (bBlock) {
      if(ele.xClpsTgt){
		ele.xClpsTgt.style.display = 'block';
	  }
      if(labelClick) ;
	  else ele.innerHTML = '-';
    }
    else {
	  if(ele.xClpsTgt){
		ele.xClpsTgt.style.display = 'none';
	  }
      if(labelClick) ;
	  else ele.innerHTML = '+';
    }
  }

/*this.onUnload = function()
  {
	for (i = 0; i < btns.length; ++i) {
      btns[i].xClpsTgt = null;
      btns[i].onclick = null;
    }
  }
*/
}
function GetLastOpen () {
  var Wert = "";
  if (document.cookie) {
    var Wertstart = document.cookie.indexOf("=") + 1;
    var Wertende = document.cookie.indexOf(";");
    if (Wertende == -1)
      Wertende = document.cookie.length;
    Wert = document.cookie.substring(Wertstart, Wertende);
  }
  return Wert;
}
function SetLastOpen (Bezeichner, Wert, Verfall) {
  var jetzt = new Date();
  var Auszeit = new Date(jetzt.getTime() + Verfall);
  document.cookie = Bezeichner + "=" + Wert + "; expires=" + Auszeit.toGMTString() + ";";
}