/* rotates testimonial quotes on the front page

  NB: Assumes the quotes themselves and the people are in the correct order

  (i.e 1st quote is attributed to 1st person, 2nd to 2nd, and so on)

*/

QuoteRotater = Class.create({

  initialize : function(container) {

    container = $(container);

    this.quotes = container.select("li");

    // hide em all
    this.quotes.invoke("hide");

    new PeriodicalExecuter(this.update_quote.bind(this), 5);

    // do the first one ;)
    this.show_quote(Math.round(Math.random() * (this.quotes.size() - 1)));

  },

  update_quote : function() {

     do {

       var next_index = Math.round(Math.random() * (this.quotes.size() - 1));

     } while (this.quotes[next_index] == this.current_quote);

     var next_quote = this.quotes[next_index];

     next_quote.setStyle({ left : "250px" });

     new Effect.Parallel([

       new Effect.Appear(next_quote),

       new Effect.Fade(this.current_quote),

       new Effect.Move(next_quote, { mode : "relative", x : -250 }),

       new Effect.Move(this.current_quote, { mode : "relative", x : -300, afterFinish : function() {

         this.show_quote(next_index);

       }.bind(this) })

     ]);


  },

  show_quote : function(idx) {

    this.quotes[idx].show();
    this.current_quote  = this.quotes[idx];

  }

});
