
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: 8, 
			duration: 0.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());
		   	ticker_lines = $(this.source).innerHTML.split("#");
			this.target.innerHTML = ticker_lines[0];
			this.counter++;
			ticker_lines.each(function(ticker_line) {
				this.messages.push(ticker_line);
			//});
        }.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])); 
		this.target.update('').appendChild(Builder.node('span',{style:'opacity:0'}, this.messages[this.counter])); 
		this.target.lastChild.style.visible = 'hidden';
		//delete this.target.innerHTML;
		//this.target.innerHTML.appendChild( Builder.node('span',{style:'opacity:0'}, this.messages[this.counter]) ); 
		new Effect.Move(this.target.lastChild,{ x: 740, y: 0, mode: "relative", duration: 0.1});
		//new Effect.Move(this.target.lastChild,{ x: -620, y: 0, mode: "relative", duration: 3.0});
		new Effect.Move(this.target.lastChild,{ x: 0, y: 0, mode: "absolute", queue: "end", duration: 1.4});
		new Effect.Appear(this.target.lastChild, {duration: 2.2});
		//new Effect.Pulsate(this.target.lastChild,{duration:1,pulses:3,from:2.5});
		this.counter++;
		if(this.counter == this.messages.length){ this.counter = 0;}
	}.bind(this), this.options.updateRate);
    },
    stop: function()
    {
	this.interval.stop();
    }
};


