Slider = new Class({

    initialize: function(el, menu) {
        this.el = $(el);
        this.scroll = new Fx.Scroll(this.el, {
            wait: false,
            duration: 250,
            transition: Fx.Transitions.Cubic.easeIn
        });
        window.addEvent('domready', this.setup.bind(this));
    },

    setup: function() {
        this.menu = $$('.submenu a');
        this.menu.each(function(link) {
            if (!link.hasClass('link')) {
                tgt = link.href.replace(/^.*?#/, '');
                link.tgt = tgt;
                link.flag = false;
                link.fx = new Fx.Tween(link, {
                    duration:200,
                    wait: false
                });
                link.setOpacity(0.4);
                link.addEvent('click', function(event) {
                    event = new Event(event).stop();
                    this.el.get('tween', {
                        property: 'height',
                        duration:100
                    }).start($(link.tgt).getCoordinates().height).chain(function() {
                        this.scroll.toElement(link.tgt);
                    }.bind(this));
                    this.menu.each(function(linkoff) {
                        if (linkoff.fx) {
                            linkoff.flag = false;
                            linkoff.fx.start('opacity', 0.4);
                        }
                    }.bind(this));
                    link.flag = true;
                    link.fx.start('opacity', 1);
                }.bind(this));
                link.addEvent('mouseover', function(event) {
                    event = new Event(event).stop();
                    link.fx.start('opacity', 1);
                }.bind(this));
                link.addEvent('mouseout', function(event) {
                    event = new Event(event).stop();
                    tgt = (link.flag) ? 1 : 0.4;
                    link.fx.start('opacity', tgt);
                }.bind(this));
            }
        }.bind(this));
        this.el.setStyle('overflow', 'hidden');
        this.el.get('tween', {
            property: 'height'
        }).start($(this.menu[0].tgt).getCoordinates().height).chain(function() {
            this.scroll.toTop();
            $$('.closed', this.el).each(function(item) {
                item.setStyle('display', 'block');
            });
        }.bind(this));
        this.menu[0].fx.start('opacity', 1);
    }
});