var panel_promos = new Class
({
	Implements:[Options,Events],
	promo_actual:0,
	interval_id: 0,
	promos: null,
	btn_activo: null,
	duracion_morph_entrada: 2000,
	duracion_morph_salida: 1000,
	options:{//set all the options here
		delay_promo: 7000,
		container_promos: '',
		transition_in: 'expo:in',
		transition_out: 'expo:out'
	},
	initialize: function (options){
		this.container_promos = options.container_promos;
		this.promos = $$('#'+this.container_promos+' div.promocion');
		this.promos.each(this.hide, this);
		this.setNav();
		this.promo_uno();
	},
	restartTimer: function(){
		if(this.interval_id != 0)
			$clear(this.interval_id);
		this.interval_id = this.switchPromo.periodical(this.options.delay_promo, this);
	},
	setNav: function(){
		$("nav_1").setStyle('cursor', 'pointer');
		$("nav_1").addEvent('click', this.promo_uno.bindWithEvent(this));
		$("nav_1").setProperty('promo', 0);
		$("nav_2").setStyle('cursor', 'pointer');
		$("nav_2").addEvent('click', this.promo_dos.bindWithEvent(this));
		$("nav_2").setProperty('promo', 1);
		$("nav_3").setStyle('cursor', 'pointer');
		$("nav_3").addEvent('click', this.promo_tres.bindWithEvent(this));
		$("nav_3").setProperty('promo', 2);
	},
	promo_uno: function(){
		if(this.btn_activo != null)
			this.btn_activo.setProperty('src', 'imagenes/banners_home/boton_promociones.png');
		this.btn_activo = $("nav_1");
		$("nav_1").setProperty('src', 'imagenes/banners_home/boton_promociones_over.png');
		this.hidePromo();
		this.promo_actual = 0;
		this.showPromo();
		this.restartTimer();
	},
	promo_dos: function(){
		if(this.btn_activo != null)
			this.btn_activo.setProperty('src', 'imagenes/banners_home/boton_promociones.png');
		this.btn_activo = $("nav_2");
		$("nav_2").setProperty('src', 'imagenes/banners_home/boton_promociones_over.png');
		this.hidePromo();
		this.promo_actual = 1;
		this.showPromo();
		this.restartTimer();
	},
	promo_tres: function(){
		if(this.btn_activo != null)
			this.btn_activo.setProperty('src', 'imagenes/banners_home/boton_promociones.png');
		this.btn_activo = $("nav_3");
		$("nav_3").setProperty('src', 'imagenes/banners_home/boton_promociones_over.png');
		this.hidePromo();
		this.promo_actual = 2;
		this.showPromo();
		this.restartTimer();
	},
	hide: function (item, index){
		item.setStyle('opacity', 0 );
	},
	switchPromo: function(){
		switch(this.promo_actual){
			case 2:
				this.promo_uno();
				break;
			case 0:
				this.promo_dos();
				break;
			case 1:
				this.promo_tres();
				break;
		}
	},
	showPromo: function(){
		this.morphing = true;
		var morph = this.promos[this.promo_actual].get('morph', {duration: this.duracion_morph_entrada, transition: this.options.transition_in});
		morph.start({'opacity': 1}).chain(this.fin_morph.bindWithEvent(this));
	},
	hidePromo: function(){
		this.morphing = true;
		var morph = this.promos[this.promo_actual].get('morph', {duration: this.duracion_morph_salida, transition: this.options.transition_in});
		morph.start({'opacity': 0}).chain(this.fin_morph.bindWithEvent(this));
	},
	fin_morph: function(){
		this.morphing = false;
	}	
});

