var Quotator = new Class({ Implements: [Options, Events], options:{ json : '/solutions/inc/quotator/quotes.php', speed : 5000, start : 0 }, initialize: function(element, options){ this.setOptions(options); this.element = $(element); var quoteLoader = new Request.JSON({ url: this.options.json, onSuccess: function(response){ this.quotes = response.quotes; this.element.set( 'html' , "
" + this.quotes[this.options.start].quote + "
" + this.quotes[this.options.start].author + "
" ); //setInterval(this.changeQuote.bind(this), this.options.speed); setInterval(this.changeQuote.bind(this), 6000); }.bind(this) }); quoteLoader.send(); }, changeQuote : function(){ if(this.options.start == this.quotes.length - 1){ this.options.start = 0; } else{ this.options.start++; } this.fadeIn(this.options.start); }, fadeIn : function(index){ var fader = new Fx.Tween(this.element,{property : 'opacity'}); fader.start(0).chain( function() { this.element.set( 'html', "
" + this.quotes[index].quote + "
" + this.quotes[index].author + "
" ); fader.start(1); }.bind(this) ); } });