/* rotate a series of testimonial_cycle_cycles */
var testimonial_cycle = { 
  index: 0,
  testimonials: [],

  startup: function() { 
    if (this.testimonials.length > 0) {
      $('testimonial').update(this.format(this.testimonials[this.index]));
      new Effect.SlideDown('testimonial');
      this.index++;
      new PeriodicalExecuter(this.cycle.bind(this), 10);
    }
  }, 

  cycle: function() { 
    new Effect.SlideUp('testimonial', {
      duration: 1, 
      fps: 50, 
      afterFinish: function() { 
        this.index++
        if (this.index == this.testimonials.length - 1) {
          this.index = 0;
        }
        $('testimonial').update(this.format(this.testimonials[this.index]));
        new Effect.SlideDown('testimonial', {
          duration: 1,
          fps: 50,
          queue:'end'
        })
      }.bind(this)
    }) 
  },

  format: function(testimonial) {
    return '<div class="description">"' + testimonial.description + '"</div>' +
           '<div class="author">' + testimonial.fullname + ',<br />' + testimonial.location + '</div>';
  }
}
