var mooNewsPanel=new Class({
	Implements: Options,

	options: {
		containerID: 	'mooNewsPanel_container',
		titleID:		'mooNewsPanel_title',
		leadID:			'mooNewsPanel_lead',

		width:			null,
		height:			null,

		delta:			null,

		news:			[]
	},

	elements: {
		container:		null,
		background:		null,
		title:			null,
		lead:			null
	},

	timer:				null,
	current:			-1,

	initialize: function(options){
		this.setOptions(options);

		window.addEvent('domready',function(){
			this.elements.container	= $(this.options.containerID);
			this.elements.title		= $(this.options.titleID);
			this.elements.lead		= $(this.options.leadID);
			if(this.elements.container) this.create();
			else throw this.options.containerID+' does not exists';
		}.bind(this));
	},

	create: function(){
		this.elements.container.setStyles({
			position	: 'relative',
			overflow	: 'hidden',
			background	: 'none',
			width		: (this.options.width)?this.options.width:this.elements.container.getStyle('width'),
			height		: (this.options.height)?this.options.height:this.elements.container.getStyle('height')
		});

		this.elements.background=new Element('img',{
			'id'	: this.options.containerID+'_image',
			styles	: {
				position	: 'absolute',
				top			: 0,
				left		: 0,
				width		: this.elements.container.getStyle('width'),
				height		: this.elements.container.getStyle('height'),
				zIndex		: 0
			}
		});

		this.elements.container.getChildren().setStyles({'position':'relative','overflow':'hidden','zIndex':1,'display':'none'});
		this.elements.background.inject(this.elements.container);

		this.setNews();
		this.timer=this.hide.bind(this).delay(2000);
	},

	setNews: function(){
		this.current++;
		if(this.current>=this.options.news.length) this.current=0;

		this.elements.background.set('src',this.options.news[this.current].image);
		this.elements.title.set('html',this.options.news[this.current].title);
		this.elements.lead.set('html',this.options.news[this.current].lead);
	},

	hide: function(){
		var next=((this.current+1)>=this.options.news.length)?0:this.current+1;
		this.elements.container.setStyle('background','url('+this.options.news[next].image+')');
		this.elements.background.tween('opacity',1,0);
		//this.elements.title.tween('top',0,30);
		//this.elements.lead.tween('top',0,-150);
		this.timer=this.show.bind(this).delay(1000);
	},

	show: function(){
		this.setNews();
		this.elements.background.setStyle('opacity',1);
		//this.elements.title.tween('top',30,0);
		//this.elements.lead.tween('top',-150,0);

		this.timer=this.hide.bind(this).delay(5000);
	}
});
