var EMenu = new Class({
    Implements: [Events, Options],
    
    options: {
        image_speed: 700,
        menu_speed: 300,
        menu_height: 300
    },
    
    initialize: function(id, options){
        this.setOptions(options);
        var menu = $(id),
		first_list_lis = menu.getFirst().getChildren(),
		count = first_list_lis.length,
		width = menu.getStyle('width').toInt(),
		li_width = Math.floor(width / count),
		img_opacity = new Fx.Tween(menu.getElement('.menu_content'), {
            property: 'opacity',
            link: 'cancel',
            duration: this.options.image_speed
        });
        
        menu.getFirst().addEvents({
            mouseenter: function(){
                img_opacity.start(0.6);
            },
            mouseleave: function(){
                img_opacity.start(1);
            }
        });
        var fnChain = new Chain();
        first_list_lis[0].addClass('first');
        first_list_lis.each(function(el){
        
            var second_list = el.getElement('ul');
            second_list.setOpacity(0);
            second_list.setStyle('height', this.options.menu_height);
            
            var fx = new Fx.Tween(second_list, {
                property: 'opacity',
                link: 'cancel',
                duration: this.options.menu_speed
            });
            el.set('id', el.get('class'));
            el.addEvents({
                mouseenter: function(){
                    fx.start(0.8);
                    this.addClass('hover' + this.get('id'));
                },
                mouseleave: function(){
                    fx.start(0);
                    this.removeClass('hover' + this.get('id'));
                }
            });
            
            var menu_title_list = el.getElement('h2');
            menu_title_list.setStyle('opacity', 0);
            menu_title_list.set('morph', {
                duration: 300,
                onComplete: function(){
                    fnChain.callChain()
                }
            });
            fnChain.chain(function(){
                menu_title_list.morph({
                    opacity: 1
                });
            });
        }, this);
        fnChain.callChain();
    }
});

