var options = {
	speed: 40 // circa 1000px in 80 sec
};

var isPaused = false;
var effect = null;

var Ticker = Class.create();
Ticker.prototype = {
	initialize:function (theString){
		this.tickerWidth = $('ticker').getWidth(); // la larghezza del ticker
		this.textWidth = $('tickerText').getWidth();
		this.posX = this.textWidth * -1;//+ parseInt(this.textWidth / 2) * -1;
		
		//if (!(this.textWidth < this.tickerWidth))
			run(this.posX);
		
		Event.observe($('ticker'), 'mouseover', this.pause.bind(this));
		Event.observe($('ticker'), 'mouseout', this.unpause.bind(this));
	},

	pause: function(){
		if (effect!= null){
			isPaused = true;
			effect.state = "paused";
		}
	},
	
	unpause: function(){
		if (effect != null){
			isPaused = false;
			effect.state = "running";
		}
	}
}
	
function run(deltaX){
	var durations = -1 * (deltaX / options.speed);
	effect = new Effect.Move ($('tickerText'),{ 
		x: deltaX, 
		y: 4, 
		mode: 'absolute', 
		duration: durations, 
		transition: Effect.Transitions.linear, 
		afterFinish: function(obj){
			obj.element.style.left = $('ticker').getWidth() + "px";
			window.setTimeout("run(-1 * ($('ticker').getWidth() + ($('tickerText').getWidth() / 2)))", 0);
		}
	});
}

	


