(function() {
  
  function initCarousel() {
    // The kind of layout we want won't look so good in IE6-7 -> Avoid loading stuff entirely.
    var base = $('universes');
    if (!base) return;
    var list = base.down('ul'), item = list.down('li'), thumbWidth = item.getWidth();
    var items = list.select('li'), width = items.length * thumbWidth;
    list.setStyle('width: ' + width + 'px; height: ' + item.getStyle('height') + ';');
    var carousel = new UI.Carousel(base, {
      previousButton: '.nav.previous', nextButton: '.nav.next', direction: 'horizontal'
    });
    if (items.length > 2) // 3+ items -> center to 2nd
      list.setStyle('left: -' + thumbWidth + 'px');
    if (items.length > 1)
      items.invoke('show');
      base.select('.nav').invoke('show').invoke('observe', 'click', function(e) {
        e.stop();
        this.blur();
      });
  } // initCarousel

  document.observe('dom:loaded', initCarousel);
})();
