Noticias = Class.create({
	url			: "http://www.esbasura.com",
	div			: 'noticias',
	keys		: false,
	news		: false,
	i			: false,
	erval		: false,
	curel		: false,
	nextel		: false,
	elcont		: false,
	rewrite_url	: false,
	
	int		: 5,//Segundos

	initialize: function(news){//Gets a Hash as argument
		this.keys = news.keys();
		this.news = news;
		this.elcont = $(this.div);
		if(!this.elcont) throw('No encontre newscont');
		this.int *= 1000;
		this.change_new();
	},
	
	change_new: function(){
		if(this.i === false)
			this.i=0;
		else{
			this.i++;
			if(this.i >= this.keys.length)
				this.i=0;
			this.hide_current();
		}
		current = this.news.get(this.i);
	    nlink = current.get('url');

		this.nextel = new Element(
		    'a',{
		    	'href': nlink,
		    	'style': 'display: none'
		    }
		);
		val = (this.i+1) + ': ' +current.get('value');
		this.nextel.update(val);
		this.nextel.onmouseover = this.elover.bind(this);
		this.nextel.onmouseout = this.elout.bind(this);
		this.show_next();
		clearTimeout(this.erval);
		this.erval=false;
		this.erval = setTimeout(this.change_new.bind(this), this.int);
	},
	
	show_next: function(){
		this.elcont.appendChild(this.nextel);
		new Effect.Appear(this.nextel, {
			queue: 'end',
			afterFinish: function(){
				if(this.curel)
					this.elcont.removeChild(this.curel);
				this.curel = this.nextel;
			}.bind(this)
		});
	},
	
	hide_current: function(){
		element = this.curel;
		new Effect.Parallel(
			[
				new Effect.Move(element, { sync: true, x: 280, y: 0, mode: 'relative' }), 
				new Effect.Opacity(element, { sync: true, from: 1, to: 0 }) 
			],{
				duration: 0.8,
				queue: 'end',
				afterFinish: function(){
					element.style.display='none';
				}
			}
		);
	},
	
	elover: function(){
		if(this.erval)
			clearTimeout(this.erval);
		this.erval = false;
	},

	elout: function(){
		this.erval = setTimeout(this.change_new.bind(this), this.int);
	}
});