var Ticker = Class.create();
Ticker.prototype = {
    messages: new Array(),
    counter: 0,
    interval: 0,
    target: null,
    source: null,
    initialize: function(target, source, options) 
    {
        this.target = $(target); 
		this.source = $(source);
        this.options = Object.extend({
		updateRate: 2, 
		duration: 1.5,
		beforeStart:function()
        { 
			this.counter++;
		}.bind(this) 
	}, options || {});

        Element.cleanWhitespace(this.source);
        $A($(this.source).childNodes).each(function(sel) {
           this.messages.push(sel.innerHTML.strip());
        }.bind(this));  

	this.start();
    },
    
    start: function()
    {
	this.interval = new PeriodicalExecuter(function() {
		this.target.update('&nbsp;').appendChild(Builder.node('span',{style:'opacity:0'}, this.messages[this.counter])); 
		new Effect.Appear(this.target.lastChild, this.options);
		if(this.counter == this.messages.length){ this.counter = 0;}
	}.bind(this), this.options.updateRate);
    },
    
    stop: function()
    {
	this.interval.stop();
    }
};

var DataTicker = Class.create();
DataTicker.prototype = {
    messages: new Array(),
    counter: 0,
    interval: 0,
    target: null,
    source: null,
    initialize: function(target, source, options) 
    {
        this.target = $(target); 
		this.source = $(source);
        this.options = Object.extend({
		updateRate: 3.5, 
		duration: 1.5,
		beforeStart:function()
        { 
			this.counter++;
		}.bind(this) 
	}, options || {});

        this.messages = this.source;
        
        //Element.cleanWhitespace(this.source);
       // $A($(this.source).childNodes).each(function(sel) {
       //    this.messages.push(sel.innerHTML.strip());
        //}.bind(this));  

	this.start();
    },
    
    start: function()
    {
	this.interval = new PeriodicalExecuter(function() {
		this.target.update('&nbsp;').appendChild(Builder.node('span',{style:'opacity:0'}, this.messages[this.counter])); 
		new Effect.Appear(this.target.lastChild, this.options);
		if(this.counter == this.messages.length){ this.counter = 0;}
	}.bind(this), this.options.updateRate);
    },
    
    stop: function()
    {
	this.interval.stop();
    }
};
