document.observe("dom:loaded", function() {
  
  Event.addBehavior({
      '.mainNavigationFirstLevelLinkAnimation' : function() {
          this.style.color = '#FFFFFF'
          new Effect.Morph(this, {
            style: 'color: #3F3F3F;', // CSS Properties
            duration: 0.8,  // Core Effect properties
            queue: 'end' }
          );
          new Effect.Morph(this, {
            style: 'color: #CCCCCC; font-weight: bold;', // CSS Properties
            duration: 0.8,  // Core Effect properties
            queue: 'end' }
          );
       }
  });

  Event.addBehavior( {
      '.abstract_title:mouseover' : function(e) {
        Event.stop(e);
      }
  });

  Event.addBehavior( {
      '.abstract_title:mouseout' : function(e) {
        Event.stop(e);
      }
  });

  //Scroll Sites
  
  Event.addBehavior( {
      '#scrollSites' : function() {
        $('contentNews').hide();
        this.show();
      }
  });

  Event.addBehavior( {
      '#newsNavigationThirdLevel' : function() {
          $('newsNavigationThirdLevelItemActiv').hide();
          $('newsNavigationThirdLevelItemHide').show();
          var links = this.select('.newsNavigationThirdLevelItemLink');
          for (var i=0; i < links.length; i++ ){
              var link = links[i];
              link.href = '#';
              link.id = i;
              Event.observe(link, 'click', function() {
                      var activClassName = 'newsNavigationThirdLevelItemActiv';
                      $('newsNavigationThirdLevel').select('.newsNavigationThirdLevelItemActiv')[0].removeClassName(activClassName);
                      this.up(0).addClassName(activClassName);
                      new Effect.Move('scrollSites', { x: -760 * this.id, y: 20, mode: 'absolute'});
                  }
              )
          }
        new Effect.Move('scrollSites', { x: -760 * $('newsNavigationThirdLevel').select('.newsNavigationThirdLevelItemActiv')[0].childElements()[0].id,
              y: 20, mode: 'absolute'});

      }
  });

	
  Event.addBehavior( {
    '.scrollNavigation' : function() {
	    if ($$('.scrollNavigationItemActiv').length != 0) {
	      $$('.scrollNavigationItemActiv')[0].hide();
        $$('.scrollNavigationItemHide')[0].show();
        var links = this.select('.scrollNavigationItemLink');
        for (var i=0; i < links.length; i++ ) {
          var link = links[i];
          link.href = '#';
          link.id = i;
	        $$('.scrollNavigationItemHide')[0].addClassName('scrollNavigationItemActivFirst');
          Event.observe(link, 'click', function() {
            var activClassName = 'scrollNavigationItemActiv';
		        $$('.scrollNavigationItemHide')[0].removeClassName('scrollNavigationItemActivFirst');
            $$('.scrollNavigationItemActiv')[0].removeClassName(activClassName);
            this.up(0).addClassName(activClassName);
					  new Effect.Move('scrollSites', { x: -760 * this.id, y: 0, mode: 'absolute'});
          });
        }
        new Effect.Move('scrollSites', { x: -760 * $$('.scrollNavigationItemHide')[0].childElements()[0].id, y: 0, mode: 'absolute'});
      }
    } 
  });


  // Blog Teaser Scroll
  Event.addBehavior({
    '.scrollOverview' : function() {
        this.style.display = 'block'
     }
  });

  Event.addBehavior( {
    '#overview' : function() {
      var childs = this.childElements();

      shiftCounter = 0;
      while (!childs[shiftCounter].hasClassName('current') && shiftCounter < childs.length) {
        shiftCounter ++;
      }
      new Effect.Move('overview', { x: -225 * shiftCounter, y: 0, mode: 'relative'});
    }

  });

  Event.addBehavior({
    '.scrollBlogDirectionRight' : function() {
        this.href = '#';
            Event.observe(this, 'click', function() {
                    new Effect.Move('overview', { x: -225, y: 0, mode: 'relative'});
                }
            )
    }
  });

  Event.addBehavior({
    '.scrollBlogDirectionLeft' : function() {
        this.href = '#';
            Event.observe(this, 'click', function() {
                    new Effect.Move('overview', { x: +225, y: 0, mode: 'relative'});
                }
            )
    }
  });


  // Home-Seite news rollover layers
  Event.addBehavior( {
    '#newsSites' : function() {
        var links = this.select('[id="newsTeaserLink1Level"]');
        for (var i=0; i < links.length; i++ ){
            var link = links[i];
            var linkpos = $('HoverArea_' + link.name).viewportOffset()[1] - 270;
            $('HoverArea_' + link.name).hide();
            var divheight = $('HoverArea_' + link.name).getHeight();
            $('HoverArea_' + link.name).style.top= linkpos - (divheight) + 'px';
            Event.observe(link, 'mouseover', function() {
                $('HoverArea_' + this.name).show();
            })
            Event.observe(link, 'mouseout', function() {
                $('HoverArea_' + this.name).hide();
            })
        }
        var submenu_divs = this.select('[name="HoverArea"]');
        for (var i=0; i < submenu_divs.length; i++ ){
            var submenu_div = submenu_divs[i];
            Event.observe(submenu_div, 'mouseover', function() {
                this.show();
            })
            Event.observe(submenu_div, 'mouseout', function() {
                this.hide();
            })
        }
    }
  }); 
}); 
