var RacePlayer = new Class({

  Implements: Options,

  initialize: function(el, options) {
    this.el = $(el);
    this.setOptions(options);
    this.init();
  },

  init: function() {
    this.pageLinks = this.el.getElement('.paginatorecorse').getElements('a');
    this.pageLinks.each(function(link) {
      link.addEvent('click', this.handlePageClick.bindWithEvent(this, link));
    }, this);
  },

  uninit: function() {
    this.pageLinks.each(function(link) {
      link.removeEvent('click');
    }, this);
    // TODO
    this.el.setStyle('height', '');
  },

  handlePageClick: function(e, link) {
    e.stop();
    this.uninit();
    var spinner = new Spinner().show(this.el.getElement('.screen'));
    new Request.HTML( {
      url: CONTEXT_PATH + this.options.url,
      data: Hash.toQueryString({
        async: true,
        uuid: this.options.uuid
      }) + '&' + link.href.replace(/^.*\?/, ''),
      update: this.el,
      evalScripts: true,
      onComplete: function() {
        if (spinner) spinner.hide().destroy();
        this.init();
      }.bind(this)
    }).get();
  }

});

