var Carrusel = new Class({
	Implements:[Options,Events],
	foto_actual:0,
	ancho_fotos: 518,
	interval_id: 0,
	fotos_total: null,
	fotos_visualizar: 1,
	btn_activo: null,
	duracion_morph: 1200,
	scroll_amount: 5,
	speed: 10,
	morphing: false,
	onStart: function(){},
	options:{//set all the options here
		delay_promo: 7000,
		container_promos: '',
		transition_in: 'quad:out',
		transition_out: 'elastic:out',
		container_carrusel: ''
	},
	initialize: function (options){
		this.container_carrusel = $(options.container_carrusel);
		if(options.ancho_fotos != undefined)
			this.ancho_fotos = options.ancho_fotos;
		if(options.fotos_visualizar != undefined)
			this.fotos_visualizar = options.fotos_visualizar;
		this.panel = $$('#'+options.container_carrusel+' .panel')[0];
		this.fotos_total = $$('#'+options.container_carrusel+' .panel span')[0].getChildren().length;
		this.setNav();
		this.onStart();
	},
	setNav: function(){
		var left = this.container_carrusel.getChildren('.left')[0];
		var right = this.container_carrusel.getChildren('.right')[0];
		left.setStyle('cursor', 'pointer');
		right.setStyle('cursor', 'pointer');
		left.addEvent('click', this.move_left.bindWithEvent(this));
		right.addEvent('click', this.move_right.bindWithEvent(this));
	},
	move_left: function(){
		if(!this.morphing){
			if(this.foto_actual > 0)
			{
				this.foto_actual --;
				this.morphing = true;
				var morph = this.panel.get('morph', {duration: this.duracion_morph, transition: this.options.transition_in});
				morph.start({'left': (this.foto_actual * this.ancho_fotos)*-1}).chain(this.fin_morph.bindWithEvent(this));
			}
		}
		this.panel.blur();
	},
	move_right: function(){
		if(!this.morphing){
			if(this.foto_actual < this.fotos_total - this.fotos_visualizar)
			{
				this.foto_actual ++;
				this.morphing = true;
				var morph = this.panel.get('morph', {duration: this.duracion_morph, transition: this.options.transition_in});
				morph.start({'left': (this.foto_actual * this.ancho_fotos)*-1}).chain(this.fin_morph.bindWithEvent(this));
			}
		}
		this.panel.blur();
	},
	fin_morph: function(){
		this.morphing = false;
	}	
});
