var FadeScroller = new Class({
	Implements: Options,
	options: {
		fs_class: "fs_showed",
		fs_delay: 200
	},
	fs_container:false,
	fs_previous:false,
	fs_next:false,
	fs_list:false,
	
	initialize: function(el,previous,next,list,options){
		this.setOptions(options);
		
		this.fs_container = $(el);
		this.fs_previous = $(previous);
		this.fs_next = $(next);
		this.fs_list = (list)?$(list):list;
		
		this.fs_previous.addEvent('click',function(){ this.previous(); }.bindWithEvent(this));
		this.fs_next.addEvent('click',function(){ this.next(); }.bindWithEvent(this));
		
		this.panes = this.fs_container.getChildren("div");
		this.total_panes = this.panes.length;
		if(list){
			this.listoptions = this.fs_list.getElements("a");
			this.total_options = this.listoptions.length;
			
			if(this.total_panes != this.total_options) { alert("Numero de Paneles y Enlaces son diferentes ["+this.total_options+""+this.total_panes+"] "); return; }
			
			this.listoptions.each(function(opt,idx){
				opt.addEvent("click",function(){
					this.showPane(idx);
				}.bindWithEvent(this));
			}.bind(this));
		}
		 
		this.current_idx = 0;
		this.transfx = new Fx.Tween(this.fs_container,{ property: 'opacity', duration: this.options.fs_delay,transition: Fx.Transitions.Quart.easeInOut, link:'chain'});

		this.setCurrent(this.current_idx);
	},
	setCurrent:function(idx){
		this.panes.setStyle("display","none");
		this.current_idx = idx;
		this.panes[idx].setStyle("display","block");
	},
	showPane:function(idx){
		this.transfx.start(0).chain(function(){
			this.setCurrent(idx);
			this.transfx.start(1);
		}.bind(this));
	},
	previous:function(){
		if(this.current_idx <= 0)
			this.showPane(this.total_panes-1);
		else
			this.showPane(--this.current_idx);
	},
	next:function(){
		if(this.current_idx >= this.total_panes-1)
			this.showPane(0);
		else
			this.showPane(++this.current_idx);
	}
});