var Fader = new Class({
        Implements: Options,
        options: {
                pause: 5000,
                duration: 1000,
                loop: true,
                onComplete: Class.empty,
                onStart: Class.empty
        },
        initialize: function(container,menucontainer,options) {
            this.setOptions(options);
            this.container = $(container);
            this.menucontainer = $(menucontainer);
            this.imgs = this.container.getElements('img');
            this.menuitems = this.menucontainer.getElements('li');
            this.imgs.each(function(el) {
                el.set('tween', {'duration': options.duration});
                });
            this.imgs.setStyles({
                'position': 'absolute',
                'top': 0,
                'left': 0,
                'opacity': 0
                });
            this.imgs[0].setStyle('opacity',1);
            this.el = new Element('div',{'styles': {
                    'position':'relative'
                }});
            this.el.injectInside(this.container);
            this.el.adopt(this.imgs);
                this.current = -1;
        },
        start: function() {
                this.show();
                this.periodical =
                this.show.bind(this).periodical(this.options.pause);
        },
        stop: function() {
                $clear(this.periodical);
        },
        show: function() {
                if (!this.options.loop && this.current==this.imgs.length-1)
                    this.stop();
                if (this.current == -1) {
                    this.menuitems[0].set('class', 'selected');
                    this.current = 0;
                    return;
                }
                var next = (this.current==this.imgs.length-1)?0:this.current+1;

                this.imgs[this.current].fade('out');
                this.imgs[next].fade('in');
                this.menuitems[this.current].set('class', '');
                this.menuitems[next].set('class', 'selected');
                this.current = next;
        }

}); 
