var Headline=new Class({
	Implements:[Events,Options],
	options:{
	 duration: 10000,
	 wait: 2000,
	 content_from:['sede','dati'],
	 box: null,
	 content:'',
	 eff:null
	},
	initialize:function(conf)
	{
	 this.setOptions(conf);
	 this.addContent();
	 this.start();
	}
});
Headline.prototype.addContent=function()
{
	this.options.content_from.each(function(item,index,arr){
		var tc ='';
		try {
			tc=($(item)) ? $(item).get('html') : $$(item)[0].get('html');
			 this.options.content+=(index%2>0) ? '<span class="blue">'+tc.stripTags().tidy().clean()+'</span> ' : tc.stripTags().tidy().clean()+' ';
			 this.options.box.set('html','<div class="moving-text-wrapper"><span class="moving-text">'+this.options.content+'</span></div>');
		}catch(e){}
	  
	}.bind(this));
	
	this.setupLayout();
}
Headline.prototype.setupLayout=function()
{
	this.options.startX=this.options.box.getDimensions().x;
	var bh=this.options.box.getDimensions().y;
	this.options.box.getElement('.moving-text-wrapper').setStyles({
		'left': this.options.startX + 'px',
		'position': 'absolute',
		'display': 'block',
		'width': '10000px',
		'cursor': 'default'
	}).addEvents({
		'mouseover':function(){
			this.pause();
		}.bind(this),
		'mouseout':function(){
			this.resume();
		}.bind(this)
	});
	this.options.endX=-(this.options.box.getElement('.moving-text').getDimensions().x+20);
	this.options.box.getElement('.moving-text').setStyle('line-height',(bh+'px'));
	this.options.eff=new Fx.Morph(this.options.box.getElement('.moving-text-wrapper'),{duration:this.options.duration,transition:Fx.Transitions.linear,onComplete:function(){this.playagain()}.bind(this)});
}
Headline.prototype.pause=function(){
	this.options.eff.pause();
}
Headline.prototype.resume=function(){
	this.options.eff.resume();
}
Headline.prototype.start=function(){
	this.options.eff.start({'left':this.options.endX});
}
Headline.prototype.playagain=function()
{
	$$('.moving-text-wrapper')[0].setStyle('left',this.options.startX+'px');
	this.start.delay(this.options.wait,this);
}

