/*
 * PROC Banner
 * Copyright (C) 2003 Alexander Nofftz
 *
 * This script 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.
 */

// Zuletzt dargestelltes Menü
var lastMenu = null;
// Neu einzublendendes Menü
var newMenu = null;
// Das PROC-Banner-Element (<div id="procbanner">)
var procBanner = null;
// Der News-Clip (<ul id="newsclip">)
var newsClip = null;
// Die Einträge im News-Clip
var newsClips = null;
// Die momentane linke Schranke des Newsclip
var newsClipLeft = 2;
// Der aktuell dargestellte News-Eintrag
var newsClipPos = 0;

// Opera mag keine Einheiten im style-Objekt
var pixel = ( navigator.userAgent.indexOf("Opera") >= 0 ) ? "" : "px";

/**
 * Wechselt die Anzeige des aktuellen Newsclips
 */
function newsClipSwitch() {
  newsClips.item(newsClipPos).style.visibility = "hidden";
  newsClipPos = (newsClipPos + 1) % newsClips.length;
  newsClips.item(newsClipPos).style.visibility = "visible";
}
/**
 * Animation, um die News langsam auszublenden
 */
function newsClipHide() {
  newsClipLeft += 2;
  newsClip.style.clip="rect(auto,auto,auto,"+newsClipLeft+pixel+")";
  if( newsClipLeft >= 200 ) {
    newsClipSwitch();
    window.setTimeout("newsClipShow()", 50);
  } else {
    window.setTimeout("newsClipHide()", 50);
  }
}
/**
 * Animation, um die News langsam einzublenden
 */
function newsClipShow() {
  newsClipLeft -= 2;
  newsClip.style.clip="rect(auto,auto,auto,"+newsClipLeft+pixel+")";
  if( newsClipLeft <= 0 ) {
    newsClipLeft = 2;
    window.setTimeout("newsClipHide()", 1000);
  } else {
    window.setTimeout("newsClipShow()", 50);
  }
}
/**
 * Animation, um ein Untermenü herauszufahren und einzublenden
 */
function showMenuAnim(h) {
  if( lastMenu != null ) {
    lastMenu.style.visibility = "visible";
    if( ++h < 7 ) {
      procBanner.style.height = (15 + h * 2) + pixel;
      window.setTimeout("showMenuAnim(" + h + ")", 50);
    } else {
      procBanner.style.height = 30 + pixel;
    }
  }
}
/**
 * Animation, um ein Menü einzufahren und auszublenden
 */
function hideMenuAnim(h) {
  if( ++h < 7 ) {
    procBanner.style.height = (30 - h * 2) + pixel;
    window.setTimeout("hideMenuAnim(" + h + ")", 50);
  } else {
    procBanner.style.height = 15 + pixel;
    lastMenu.style.visibility = "hidden";
    lastMenu = newMenu;
    showMenuAnim(0);
  }
}
/**
 * Blendet das alte Menü aus und das angegebene Menü ein
 */
function toggleMenu(menu) {
  if( procBanner != null ) {
    if( menu != null )
      menu = document.getElementById(menu);
    if( lastMenu == menu )
      return;
    if( lastMenu != null ) {
      newMenu = menu;
      hideMenuAnim(0);
    } else {
      lastMenu = menu;
      showMenuAnim(0);
    }
  }
}
/**
 * Initialisierung des PROC-Banners
 */
function init() {
  // MSIE 5 und 6 unterstützen kein position:fixed und kein
  // hasFeature, obwohl sie DOM unterstützen :-(
  var userAgent = navigator.userAgent;
  var MSIEIndex = userAgent.indexOf("MSIE");
  if( userAgent.indexOf("Win")  != -1 && userAgent.indexOf("MSIE") != -1
      && userAgent.substring((MSIEIndex + 5),(MSIEIndex + 6)) > 4 ) {
    DOM = true;
  } else {
    DOM = document.implementation.hasFeature("HTML", "1.0");
  }
  if( !DOM ) {
    // Ohne DOM funktioniert das PROC-Banner nicht,
    // daher die Version ohne JavaScript aktiviert lassen
    return;
  }
  procBanner = document.getElementById("procbanner");
  newsClip = document.getElementById("procnewsclip");
  newsClips = newsClip.getElementsByTagName("LI");
  if( newsClips.length < 1) {
    // Bei XHTML bleiben die Tag-Namen klein geschrieben
    newsClips = newsClip.getElementsByTagName("li");
  }
  newsClipSwitch();
  newsClipHide();

  // href der Untermenüs auf # setzen
  a = document.getElementById("procprojekte").getElementsByTagName("A");
  if( a.length < 1 ) {
    a = document.getElementById("procprojekte").getElementsByTagName("a");
  }
  for( i = 0; i < a.length; i++ ) {
    if( (a.item(i).className == "procsubmenu") || (a.item(i).getAttribute("class") == "procsubmenu") ) {
      a.item(i).href = "#";
    }
  }
}
