//
// Funktionen für die Dropdown-Menüs des Moduls Navi_oben.
//
// Geschrieben für script.aculo.us 1.8.1 (http://script.aculo.us) und
// Prototype 1.6.0.1 beta (http://www.prototypejs.org)
//
// Copyright © Thomas Görres, Januar 2008
//

     hideTimers = {};

     function getDropDownFromEvent(event) {
       // wenn das Event von einem Bild ausgelöst wurde...
       if ('img' == Event.element(event).tagName.toLowerCase()) {
         // falls das Bild nicht innerhalb eines Links steckt...
         if ('a' != Event.element(event).up().tagName.toLowerCase())
           return null;
         // ...ansonsten ist das Dropdown das nächste Element eine Eben höher
         return Event.element(event).up().next();
       }

       // ...ansonsten ist das Dropdown der Auslöser selbst bzw. das nächste
       // ihn umgebende DIV
       else
         return Event.findElement(event, 'div');
     }


     function showDropDown(event) {
        dropdown = getDropDownFromEvent(event);
        if (null == dropdown) return;

        // Timer fürs ausblenden stoppen
        if (null != hideTimers[dropdown.identify()])
          hideTimers[dropdown.identify()].stop();

        // falls das Event nicht von einem Bild ausgelöst wurde
        if ('img' == Event.element(event).tagName.toLowerCase())
          Effect.BlindDown(dropdown, {duration:0.2});
     }


     function hideDropDown(event) {
       dropdown = getDropDownFromEvent(event);
       if (null == dropdown) return;

       // Timer starten, um das Dropdown auszublenden
       id = dropdown.identify();
       seconds = 0.5;
       hideTimers[id] = new PeriodicalExecuter(function(timer) {
         //Effect.BlindUp(this, {duration:0.2}); // this ist hier das Dropdown (sh. bindAsEventListener)
         Effect.Fade(this, {duration:0.2});
         timer.stop();
       }.bindAsEventListener(dropdown), seconds);
     }


     //
     // sobald die Seite geladen ist:
     //
     Event.observe(window, 'load', function() {
        // alle Dropdowns mit JS verbergen, Unsichtbarkeit
        // durch CSS aufheben
        for(i = 7; i < 14; i++) {
          Try.these(function() {$('dropdown' + i).hide();});
          Try.these(function() {$('dropdown' + i).setStyle({visibility:'visible'})});
        }

        // Event-Listening der Bilder und Dropdown-Menüs
        $$('#header img, #header div div a').each(function(s){
          s.observe('mouseover', showDropDown);
          s.observe('mouseout', hideDropDown);
        });
      });