var Scroller = new Class({
    Implements: [Chain, Events, Options],
    options:{
        scrollClass:'.quoteitem',
        scrollContainer:'quoteitemcontainer'
    },
    
    initialize:function(options){
        this.setOptions(options);
        
        this.scrolls = $$('.quoteitem');
        
        this.doScroll = null;
        this.startScroll();
        
        slidermoving = false;
                
        $$('.skipbutton').addEvents({
            click: function(){
                this.skipScroll();
            }.bind(this)
        });	
        
        $$('.quoteplay').addEvents({
            click: function(){
                this.startScroll();
            }.bind(this)
        });	
        
        $$('.quotestop').addEvents({
            click: function(){
                this.stopScroll();
            }.bind(this)
        });	
        
    },
    
    stopScroll:function(){
		//console.log('stop scroller - ' + this.doScroll);
		
		clearTimeout(this.doScroll);
		//$$('.quotepause').setStyle('display','none');
		$$('.quoteplay').setStyle('display','block');
		$$('.quotestop').setStyle('display','none');
		
		//console.log('scroller - ' + this.doScroll);
    },
    
    skipScroll:function(){
		
		clearTimeout(this.doScroll);
		$$('.quoteplay').setStyle('display','block');
		$$('.quotepause').setStyle('display','block');
		$$('.quotestop').setStyle('display','none');
		this.moveLeft();
		
    },
    
        
    startScroll:function(){		
		this.doScroll = this.moveLeft.periodical(8500);
		$$('.quotepause').setStyle('display','none');
		$$('.quoteplay').setStyle('display','none');
		$$('.quotestop').setStyle('display','block');
		//console.log('start scroller - ' + this.doScroll);
    },
    
    moveLeft:function(){
		
		el=$$('.quoteitem')[0];//this.options.scrollClass)[0];
		
		$$('.quoteitem').setStyle('margin-left',0);
		var w = $$('.quoteitem')[0].offsetWidth;
		var myFx = new Fx.Tween(el, {property: 'margin-left',duration:1000});
		
		myFx.start(w * -1).chain(
            
			//Notice that "this" refers to the calling object (in this case, the myFx object).
			function(){ 
				first = $$('.quoteitem')[0];
				$$('.quoteitem')[0].inject($('quoteitemcontainer'),'bottom');//this.options.scrollContainer,'bottom');
				first.style.marginLeft = '0px';							 
			}		
		);		
		
    }        

});
