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');
            first_list_lis = menu.getFirst().getChildren(),
        	first_list_lis[0].addClass('first');
		
		
		first_list_lis.each(function(el){

            var second_list = el.getElement('ul');
            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.1);
            
            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.1);
				//	img_opacity.start(1);
                }
            });
 
        }.bind(this));
    }
});

window.addEvent('load', function() {
		if ($defined($('totop'))) {
		    var myWidth = 0, myHeight = 0;
		    docheight = document.getElementById('wrapper').offsetHeight;
		   
		    if (typeof(window.innerWidth) == 'number') {
		        //Non-IE
		        myWidth = window.innerWidth;
		        myHeight = window.innerHeight;
		    }
		    else
		        if (document.documentElement && (document.documentElement.clientWidth ||
		document.documentElement.clientHeight)) {
		            //IE 6+ in 'standards compliant mode'
		            myWidth = document.documentElement.clientWidth;
		            myHeight = document.documentElement.clientHeight;
		        }
		        else
		            if (document.body && (document.body.clientWidth ||
		document.body.clientHeight)) {
		                //IE 4 compatible
		                myWidth = document.body.clientWidth;
		                myHeight = document.body.clientHeight;
		            }
		    if (myHeight + 100 > docheight) {
		        $('totop').dispose();
		    }
		}
   
});
