
var Fader = new Class({
  initialize: function(el) {
    var _this = this;
    this.el = el;

    var first = true;
    el.getChildren().each(function(child) {
      if (first) {
        _this.currentChild = child;
        first = false;
      }

      child.setStyle('opacity', 0);
      child.store('fader_fx', new Fx.Morph(child, {duration: 'long'}));
    });

    this.cycle();
  },

  cycle: function() {
    var current = this.currentChild;
    var next = current.getNext();

    if (next == null) {
      next = current.getParent().getFirst();
    }

    current.retrieve('fader_fx').start({ opacity: 0 }).chain(function() {
        next.retrieve('fader_fx').start({ opacity: 1 });
    });

    this.currentChild = next;
    this.cycle.delay(10000, this);
  }
});

window.addEvent('domready', function() {
  $$('.fader').each(function(el) {
    new Fader(el);
  });
});
