// Menu-Generator Methode
// oliver, oliver@webwichtel.de
// july 2001
// v 1.2.1
// _____________________________________________________________________________________________________

// variablen
var topics = new Array; // HV fuer layer index fuer menu-generator
var tmpTopics = new Array; // Arbeitsarray fuer menu-generator
var menDir, topicLayWidth, topicLayHeight, newTop, newLeft, initTop, initLeft, anzLay, menTimeOut; // HV fuer createMenu
var menDur = menTimeOut = count = menDelay = 0; // HV fuer ausblenden der submenüs bei inaktivitaet
var isVis = 0; // HV fuer sichtbaren teil des menus
var elemStart = new Array; // HV fuer anzahl bereichselemente
var elemEnd = new Array; // HV fuer anzahl bereichselemente
var anzElem = new Array; // HV fuer anzahl bereichselemente
var menOpen = false; // Flag fuer timersteuerung

// aus allen Layern, deren Id mit "men" beginnt ein pulldown(hor) oder popup(ver) menu erstellen
function createMenu(menDir,topicLayWidth,topicLayHeight,initLeft,initTop,dx,dy,delay){
 menDelay = delay;
 isVis = 1; // initial fuer bereichsgroesse ermitteln
 if(menDir == "hor") initLeft -= topicLayWidth; // provide error for hor-construction
 var a = 0; // index for topics array
 for(i=0; i<=anzLay; i++){
  // read layer name
  if(isIE){
   if(document.all) tmpID = document.all[i].id; 
  }
  if(isNN){
   tmpID = document.layers[i].id;
   document.layers[i].zIndex = 50+i;
  }
  if(isGecko){
   tmpID="";
   if(geckoLay[i].getAttribute('id')){
    tmpID = geckoLay[i].getAttribute('id');
   }
  }
  if(tmpID != ""){ // exception: layer has got no name
   if(tmpID.substr(0,3) == "men"){ // check if layer is menu-element
    tmpTopics[a] = tmpID;
    a++;
   }
  }
 }
 for(i=0; i<=tmpTopics.length-1; i++){
  if(tmpTopics[i].substr(0,3) == "men"){ // check if layer is menu-element
   topics[i] = tmpTopics[i].substr(3); // clear string to have index
   if(topics[i].length > 1) hide(tmpTopics[i]); // hide submenus
   thePos = topics[i].split("_"); // get index elements
   // vertical menu layer-positions
   if(menDir == "ver"){
	  newTop = initTop;
	  for(k=0; k<=thePos.length-1; k++){
	  newTop += (parseInt(thePos[k])-1) * topicLayHeight;
	  }
	  newLeft = initLeft + ((thePos.length - 1) * topicLayWidth);
   }
   // horicontal menu layer-positions
   if(menDir == "hor"){
	  newLeft = initLeft + (parseInt(thePos[0]) * topicLayWidth);
	  newTop = initTop;
	  if(thePos.length != 1){
	    newLeft += ((parseInt(thePos.length-2) * topicLayWidth));
	    for(k=0; k<=thePos.length-1; k++){
	      newTop += ((parseInt(thePos[k])-1) * topicLayHeight);
	    }
	    // exception: submenu index starts with 1
	    if((thePos[0] == "1") && (thePos.length >= 2)) newTop += topicLayHeight;
	    // exception: new pos is maintopic >= 3
	    if(thePos[0] >= "3") newTop = newTop - ((parseInt(thePos[0])-2) * topicLayHeight);
	  }
   }
   // verschiedbungen berechnen
   newDx = 0;
   for(k=0; k<=thePos.length-1; k++){
    if(thePos[k]) newDx += parseInt(thePos[k]) * dx;
   }
   newLeft += newDx;
   setLayPos(tmpTopics[i],newLeft,newTop);
  }
  elemStart[1] = 0;
  // ermitteln der area-groessen fuer menubereiche in anzElem[1] .. anzElem[n]
  if (parseInt(tmpTopics[i].substr(3,1)) != isVis){
   isVis++;
   elemStart[isVis] = elemEnd[isVis-1] + 1;
   count = 0;
  }
  if((parseInt(tmpTopics[i].substr(3,1)) == isVis) &&
	 (tmpTopics[i].length > 4)){
   count++;
   anzElem[isVis] = count;
   elemEnd[isVis] = elemStart[isVis] + count;
  }
  if(tmpTopics[i].length <= 5)show(tmpTopics[i]);
 }
 isVis = 1; // default, men1 eingeblendet
}

// anzeigen/ausblenden von subMenus
var lay_X, tov_X; // ALS: HV für Verzögerung beim Einblenden
function showSubMenu(lay,tov){
 if(lay) lay_X = lay;
 if(tov) tov_X = tov;
 if(bischenWartenIdx >= 2){ // ALS: Prüfung für Verzögerung beim Einblenden
  theArea = parseInt(lay_X.substr(3,lay_X.length));
  for(i = 0;i < tmpTopics.length; i++){
    tmpLay = lay_X.split("_");
    tmpMen = tmpTopics[i].split("_");
    if(tmpLay[0] == tmpMen[0]){
      show(tmpTopics[i]);
    } else {
      if(tmpTopics[i].indexOf("_") != -1) hide(tmpTopics[i]);
    }
  }
  isVis = theArea;
  // verzoegerung fuer menu schliessen wenn maus nicht im menu aktiv
  window.clearTimeout(menTimeOut);
  menTimeOut = window.setTimeout("menVisDur()",tov_X);
  bischenWartenIdx = 0; // ALS: Verzögerungszähler wieder nullen
  
  window.clearTimeout(menuTimeout);
  
 }else{
  // ALS: Timer für Verzögerung beim Einblenden
  menuTimeout = window.setTimeout("bischenWarten()",250);
  
 }
}
// ALS: Zähler für Verzögerung beim Einblenden
var bischenWartenIdx = 0;
function bischenWarten(){
  bischenWartenIdx++;
  showSubMenu();
}

function menVisDur(){
 for(i = 0; i <= tmpTopics.length-1; i++){
  if((tmpTopics[i].substr(0,3) == "men") && (tmpTopics[i].length > 5) && (menOpen == false)) hide(tmpTopics[i]);
 }
 window.clearTimeout(menTimeOut);
 // für als-verlag !!! Nicht löschen !!!!!
 if(navigator.appVersion.indexOf("MSIE 5.01") != -1){
  if(document.getElementById("content")) show("content");
 }
 return;
}