(function ( $ ){
	
	PB.Twitter = PB.Class({
		
		constructor: function ( config ) {
			
			this.current = 0;
			
			Object.extend( this, config );

			this.length = this.data.length;
		},
		
		setTemplate: function ( html ) {
			
			this.tpl = new $.Template(html);
			
			$.ready(this.go.bind(this));
		},
		
		go: function () {
			
			this.renderTo.last().morph({opacity: 0}, .8, this.animate.bind(this));
		},
		
		animate: function () {
			
			var childs = this.tpl.replace(this.renderTo.last(), this.data[this.current]);

			this.renderTo.last().setStyle('opacity', 0)
				.morph({opacity: 1}, 1);
			
			this.current++;
			
			if( !this.data[this.current] ) {
				
				this.current = 0;
			}
			
			window.setTimeout(this.go.bind(this), 7000);
		}
	});
})( PB );
