  /*makeJSmenu version 0.1
   (c) by Henning Mersch <henning(at)mersch.it>
   Homepage: http://www.moth.de/index.html#makeJSmenu

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more detais.

   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

  */

//var for store color of menu before mouseover
var formerColor;

//main function
//hides all menus other than given id
function showMenu(id) {
  hideAllMenu(); //at start all menus are visible (for browsers not supporting js)
  makeVis(id);
}

// hides all menus and submenues (id=menuX0 set to invisible)
function hideAllMenu() {
  var i = 1;
  while (true) {
    var menueM = document.getElementById("menu"+i+"M");
	if (menueM) {
          var menue = document.getElementById("menu"+i+"0");
          if(menue) {
	    menue.style.visibility="hidden";
	    menue.style.display="none";
          }
	} else {
	  break;
	}
    i++;
  }                                                              
}


// makes visible the menu of given id and all top menues
function makeVis(id) {
  //mark current sub menu, if any
  var curElement = document.getElementById(id);
  if (curElement) {
    curElement.style.visibility="visible";
    curElement.style.display="block"; 
    curElement.childNodes[0].style.color="rgb(169,18,42)";
  }
  if (id.substring(id.length-1,id.length-0) == "0" ) { //if at top menu element, mark this
      var topMenu = document.getElementById(id.substring(0,id.length-1)+"M"); // color corresonding menupoint
      topMenu.childNodes[0].style.color="rgb(169,18,42)"
  }
  makeTopVis(id);
}

// make all top menus of given id visible
// recursive funtion
function makeTopVis(id) {
  var topElement = document.getElementById(id.substring(0,id.length-1)+"0");
  if (topElement) {
    topElement.style.visibility="visible";
    topElement.style.display="block"; 
    makeTopVis(id.substring(0,id.length-2)+"0");
  }
}

//
// make menu red on mouseover (and store orig color)
function mark(element) {
  formerColor = element.style.color;
  element.style.color="rgb(169,18,42)";
}

// restore menu color after mouseover
function unmark(element) {
  element.style.color=formerColor;
}
