var SwTicker = new Class({
    Implements: Options,
    el: 0,
    firstCall: true,
    periodical: 0,
    options: {
        speed: 3000,
        delay: 8000
    },
    initialize: function(el, options){
        this.setOptions(options);
        this.el = $(el);
        if (this.el.getChildren().length < 2) 
            return;
        this.fx = new Fx.Scroll(this.el, {
            duration: this.options.speed
        });
        var firstQuoteIndex = Math.floor(Math.random()*this.el.getChildren().length);
        for (var i=0; i<firstQuoteIndex; i++) {
        	this.el.getFirst().inject(this.el);
        }
        this.fx.set(0, 0);
        this.periodical = this.scrollToNext.periodical(this.options.delay, this);
    },
    
    scrollToNext: function(){
        if (!this.firstCall) {
            this.el.getFirst().inject(this.el);
            this.fx.set(0, 0);
        }
        else {
            this.firstCall = false;
        }
        this.fx.toElement(this.el.getChildren()[1]);
    },
    restoreScroll: function(){
        var resumeTicker = new Chain();
        resumeTicker.chain(function(){
            this.scrollToNext.delay(this.options.delay / 3, this);
            resumeTicker.callChain();
        }
.bind(this));
        resumeTicker.chain(function(){
            this.periodical = this.scrollToNext.periodical(this.options.delay, this);
        }
.bind(this));
        resumeTicker.callChain();
    },
    stopScroll: function(){
        $clear(this.periodical);
    }
});

