
/*  JavaScript: Menü-Navigation für ein HTML-Dokument.
    Browser der Generation 6 empfohlen.
    Copyright (C) 2002 by Henning Tillmann, www.henning-tillmann.de
    Dieses Skript darf nicht ohne Erlaubnis kopiert oder weitergegeben werden!
    
    thisId = addMenu(Beschriftungen, URIs)
    fügt ein Hauptmenü hinzu.
    
    thisId = addSub(Beschriftungen, URIs)
    fügt ein Untermenü hinzu.
    
    'Beschriftungen' und 'URIs' im String-Format wie folgt:
    'Wert1; Wert2; Wert3; ...'
    
    Um auf ein Submenü zu verweisen, muss als URI-Wert einfach die ID des Menüpunkts angegeben werden.
    Ein Menü wird per showMenu(id) angezeigt.
*/

var menuCount = -1;
var menuCaptions = new Array();
var menuUris = new Array();
var menuCurrent = -1;
			
var subCount = -1;
var subCaptions = new Array();
var subUris = new Array;

// Speichert die Position des TD bevor ein Submenü angezeigt wird, damit es daran ausgerichtet wird.
var tdParentTop = 0;

var hTimer;
var keepMenu = true;

var browserSupported = false;
var browserVersion = String(navigator.appVersion);
var browserName = String(navigator.appName);

if (browserName == 'Microsoft Internet Explorer') {
  browserVersion = eval(browserVersion.substring(22, 25));
  if (browserVersion >= 5.5)
    browserSupported = true;
} else if (browserName == 'Netscape') {
  browserVersion = eval(browserVersion.substring(0, 1));
  if (browserVersion >= 5)
    browserSupported = true;
}

function addMenu(captions, uris) {
  if (!browserSupported) return;
  menuCount++;
  menuCaptions.push(captions);
  menuUris.push(uris);

  return subCount;
}

function addSub(captions, uris) {
  if (!browserSupported) return;
  subCount++;
  subCaptions.push(captions);
  subUris.push(uris);

  return subCount;
}

function showMenu(id, type) {
  var sContents, pxLeft, pxTop, sVisibility, sUrl;
  var arrayCaptions, arrayUris;
  var i;

  // ++++++++++++++++++++++++++++++++++++++++++++++
  return;
  // ++++++++++++++++++++++++++++++++++++++++++++++
  
  if (!browserSupported) return;
	
  sContents = '<table class="' + type + 'DropDown" cellspacing="0" cellpadding="0">';

  if (type == 'menu') {
    if (menuCurrent > -1)
      document.getElementById('tdmenu' + menuCurrent).style.background = 'transparent';

    menuCurrent = id;
    document.getElementById('tdmenu' + id).style.background = 'rgb(51,51,51)';
    arrayCaptions = menuCaptions[id].split('; ');
      arrayUris = menuUris[id].split('; ');
  } else if (type == 'sub') {
    arrayCaptions = subCaptions[id].split('; ');
    arrayUris = subUris[id].split('; ');
  }
				
  for (i = 0; i < arrayCaptions.length; i++) {
    
    if (!isNaN(arrayUris[i])) {
      sVisibility = 'visible';
      sUrl = 'javascript:showMenu(' + arrayUris[i] + ', \'sub\')' 
    } else {
      sVisibility = 'hidden';
      sUrl = arrayUris[i];
    }

    /* IDs:
       menuIDelemIx
       für x:
       i: TD des Ninja-Bildes
       g: IMG - Ninja-Bild
       t: TD der Caption
       h: A der Caption
       a: TD des Pfeiles
       w: IMG - Pfeil
     */

    sContents += '<tr>' +
                    '<td id="' + type + id + 'elem' + i + 'i" class="menuNormal" style="border-right:none; padding-left:2px; width:20px" onmouseover="menuHiLight(this)" onmouseout="menuLoLight(this)"><img id="' + type + id + 'elem' + i + 'g" style="visibility:hidden" src="/images/gfx/menu_small_ninja.gif" width="15" height="15" alt="" /></td>' +
                    '<td id="' + type + id + 'elem' + i + 't" class="menuNormal" style="border-right:none; border-left:none" onclick="menuExecute(this)" onmousedown="menuDnLight(this)" onmouseover="menuHiLight(this)" onmouseout="menuLoLight(this)" onmouseup="menuHiLight(this)"><a class="menu" id="' + type + id + 'elem' + i + 'h" href="' + sUrl + '">' + arrayCaptions[i] + '</a></td>' +
                    '<td id="' + type + id + 'elem' + i + 'a" class="menuNormal" style="border-left:none; width:20px; text-align:right" onmouseover="menuHiLight(this)" onmouseout="menuLoLight(this)"><img id="' + type + id + 'elem' + i + 'w" style="visibility:' + sVisibility + '" src="/images/gfx/menu_small_arrow.gif" width="15" height="15" alt="" /></td>' +
                  '</tr>';
  }

  sContents += '</table>';	
				
  if (type == 'menu') {
    with (document.getElementById(type + id)) {
      pxLeft = offsetParent.offsetLeft + offsetLeft + 4; // 4 => body.margin
      pxTop = offsetParent.offsetParent.offsetTop + offsetParent.offsetTop + offsetTop + offsetHeight + 10;
    }
  } else if (type == 'sub') {
    with (document.getElementById('menuDropDown')) {
      pxLeft = getNumericValue(style.left) + 149;
      pxTop = getNumericValue(style.top) + tdParentTop;
    }
  }

  document.getElementById(type + 'DropDown').innerHTML = sContents;
  document.getElementById(type + 'DropDown').style.left = pxLeft + 'px';
  document.getElementById(type + 'DropDown').style.top = pxTop + 'px';
  document.getElementById(type + 'DropDown').style.visibility = 'visible';
}

function menuHiLight(objCell) {
  var thisId = String(objCell.id);
  var thisIdLen = thisId.length;
  var thatId = thisId.substring(0, thisIdLen - 1);
  var thisSub;

  window.clearTimeout(hTimer);

  objCell.className = 'menuHover';

  // Graphik anzeigen (nur für Pulldown-Menu):
  if (thisId.substring(0, 4) != 'elem')
    document.getElementById(thatId + 'g').style.visibility = 'visible';
  else {
    document.getElementById(thatId + 'g').src = '/images/menu/' + document.getElementById(thatId + 'g').alt + '1.gif';
  }

  menuChangeClass(thisId, thatId, 'menuHover');

  if (document.getElementById(thatId + 'w').style.visibility == 'visible') {
    thisSub = String(document.getElementById(thatId + 'h').href)
    if (thisSub.substring(0, 19) == "javascript:showMenu") {
      thisSub = thisSub.substring(20, 21);
      tdParentTop = objCell.offsetTop;
      showMenu(thisSub, 'sub');
    }
  }
}

function menuLoLight(objCell) {
  var thisId = String(objCell.id);
  var thisIdLen = thisId.length;
  var thatId = thisId.substring(0, thisIdLen - 1);
  
  objCell.className = 'menuNormal';

  // Graphik anzeigen (nur für Pulldown-Menü):
  if (thisId.substring(0, 4) != 'elem')
    document.getElementById(thatId + 'g').style.visibility = 'hidden';  
  else
    document.getElementById(thatId + 'g').src = '/images/menu/' + document.getElementById(thatId + 'g').alt + '0.gif';

  menuChangeClass(thisId, thatId, 'menuNormal');
  
  if (thisId.substring(0, 3) == 'sub')
    keepMenu = true;
  else
    keepMenu = true;      // Bei Pulldown auf False

  if (thisId.substring(0, 1) != 'x')
    hTimer = window.setTimeout("hideMenu()", 100);
}

function menuDnLight(objCell) {
  var thisId = String(objCell.id);
  var thisIdLen = thisId.length;
  var thatId = thisId.substring(0, thisIdLen - 1);

  objCell.className = 'menuDown';

  // Graphik anzeigen
  document.getElementById(thatId + 'g').style.visibility = 'hidden';  
  menuChangeClass(thisId, thatId, 'menuDown');
}

function hideMenu() {
  if (!keepMenu) {
    document.getElementById('tdmenu' + menuCurrent).style.backgroundColor = 'transparent';

    with (document.getElementById('menuDropDown')) {
      innerHTML = '';
      style.visibility = 'hidden';
      style.left = '-100px';
      style.top = '-100px';
    }
  }

  with (document.getElementById('subDropDown')) {
    innerHTML = '';
    style.visibility = 'hidden';
    style.left = '-100px';
    style.top = '-100px';
  }
}

function menuChangeClass(thisId, thatId, thisClass) {
  var thisIdLen = thisId.length;
  if (thisId.substring(thisIdLen - 1, thisIdLen) == 't') {
    document.getElementById(thatId + 'i').className = thisClass;
    document.getElementById(thatId + 'a').className = thisClass;    
  } else if (thisId.substring(thisIdLen - 1, thisIdLen) == 'i') {
    document.getElementById(thatId + 't').className = thisClass;
    document.getElementById(thatId + 'a').className = thisClass;
  } else if (thisId.substring(thisIdLen - 1, thisIdLen) == 'a') {
    document.getElementById(thatId + 'i').className = thisClass;
    document.getElementById(thatId + 't').className = thisClass;
  }
}

function menuExecute(objCell) {
  var thisId = String(objCell.id);
  var thisIdLen = thisId.length;
  var thatId = thisId.substring(0, thisIdLen - 1);
  
  location.href = document.getElementById(thatId + 'h').href;
}

function getNumericValue(sValue) {
  return (eval(sValue.substring(0, sValue.length - 2)));
}