var EMenu = new Class({
    Implements: [Events, Options],

    options: {
        autocalc: true,
        image_speed: 400,
        menu_speed: 500
    },

    initialize: function(id, options){
        this.setOptions(options);
        // this.over = false;
        var menu = $(id),
			// fader = $$('div.fader'),
			mainmenu = $$('a.firstlevel');

      if (!menu) return;
            
      first_list_lis = menu.getFirst().getChildren();
      if (first_list_lis[0]) first_list_lis[0].addClass('first');


		first_list_lis.each(function(el){

            var second_list = el.getElement('ul');
            if (second_list != null)
            {
              second_list.setOpacity(0).getFirst().addClass('first');

            var fx = new Fx.Tween(second_list, {
				property: 'opacity',
                link: 'cancel',
                duration: this.options.menu_speed
            });
            }

			var menupunkt = el.getElement('a.firstlevel');
            menupunkt.setOpacity(0);

            var menu_ani = new Fx.Tween(menupunkt, {
				property: 'opacity',
                link: 'cancel',
                duration: this.options.menu_speed
            });





          var that = this;

            el.addEvents({
                mouseenter: function(){

					fx.start(1).chain(function(){
                   //     that.fireEvent('onMenuShow', this);
                     (function(){that.over = true;}).delay(50); // delay prevents race conditions
                   }.bind(this));
                   // this.addClass('hover');
					menu_ani.start(1);
				//	img_opacity.start(0.25);
                },
                mouseleave: function(){
                    fx.start(0).chain(function(){
                       if (that.over) {
                            that.fireEvent('onMenuHide', this);
                           that.over = false;
                      }
                  }.bind(this));
                   // this.removeClass('hover');
					menu_ani.start(0);
				//	img_opacity.start(1);
                }
            });

        }.bind(this));
    }
});