var Splash = {
  init: function() {
    this.list    = $E('#splash');
    this.entries = this.list.getElements('li');
    this.current = 0;
    // Hide all but the first
    this.entries.forEach(function(entry) {
      if (entry != this.entries[0]) entry.setStyle('opacity', 0);
    }, this);
    // Set a timeout to fade em
    this.setTimeout();
  },
  select: function() {
    if (this.timeout) window.clearTimeout(this.timeout);
    // Determine the current entry to fade out and the next to fade in
    var currentEntry = this.entries[this.current];
    var nextIndex = this.entries[(this.current + 1)] ? this.current + 1 : 0;
    var nextEntry = this.entries[nextIndex];
    var fadeFx = new Fx.Elements([currentEntry, nextEntry]);
    // Do the fade
    fadeFx.start({
      '0': {'opacity': [1, 0]},
      '1': {'opacity': [0, 1]}
    });
    this.current = nextIndex;
    this.setTimeout();
  },
  setTimeout: function() {
    this.timeout = window.setTimeout(this.select.bind(this), 10000);
  }
};

window.addEvent('domready', Splash.init.bind(Splash));