var Fradid2 = new Class({
   Implements: [Options, Events],

   options: {
       duration: 3000,
       delay: 1000,
       direction: 'h',
       transition: Fx.Transitions.linear
   },

   initialize: function(element,options) {
       this.setOptions(options);
       this.element = $(element);
       this.items = this.element.getElements('div');

       this.element.addEvent('mouseenter', this.fireEvent.pass('onMouseEnter',this));
       this.element.addEvent('mouseleave', this.fireEvent.pass('onMouseLeave',this));

       var w = 0;
       var h = 0;

       if(this.options.direction.toLowerCase()=='h') {
           h = this.element.getSize().y;
           this.items.each(function(el,index) {
               w += el.getSize().x;
           });
       }
       else {
           w = this.element.getSize().x;
           this.items.each(function(el,index) {
               h += el.getSize().y;
           });
       }

       this.element.setStyles({
           position: 'absolute',
           top: 0,
           left: 0,
           width: w,
           height: h
       });

       this.myEffect = new Fx.Morph(this.element, {
           duration:this.options.duration, 
           transition:this.options.transition, 
           onComplete:function() {
               var i = (this.current==0) ? this.items.length : this.current;
               this.items[i-1].injectInside(this.element);
               this.element.setStyles({
                  left:0,
                  top:0
               });

               this.play.bind(this).delay(this.options.delay);
           }.bind(this)
       });

       this.current = 0;
       //this.play();
       this.play.bind(this).delay(this.options.delay);
   },

   play: function() {
       this.current++;
       if (this.current >= this.items.length) { this.current = 0; }
       var pos = this.items[this.current];

       this.myEffect.start({
          top: -pos.offsetTop,
          left: -pos.offsetLeft
       });
   },

   pause: function() {
       this.myEffect.pause();
   },

   resume: function() {
       this.myEffect.resume();
   }
});
