var rota_imagenes = new Class
({
	Implements:[Options,Events],
	instances: 0,
	transition: 'bounce:out',
	contenidos: new Array(),
	total_contenidos: 0,
	//elementos:
	options:{//set all the options here
		container : 'container_rotar',
		tema:'',
		tiempo_cambio : 3000,
		tiempo_efecto: 1000,
		velocidad: 5000,
		item_seleccionado: 0	
	},
	
	initialize: function (options){
		this.setOptions(options);
		var container = this.options.container;
		this.contenidos = $$('#'+this.options.container+' div.tab_novedad');
		this.total_contenidos = this.contenidos.length;
		this.contenidos.each(function(item, index){
			item.setStyle('left', $(container).getSize().x + $(item).getSize().x);
		});
		this.rotarContenido.periodical(this.options.tiempo_cambio, this);	
	},
	
	rotarContenido : function (){
		var cambio_estilo = 0;
		if ((this.options.item_seleccionado - 1) >=0)
			cambio_estilo = (this.options.item_seleccionado - 1);
		else
			cambio_estilo = (this.total_contenidos - 1);
		
		this.contenidos[cambio_estilo].setStyle('z-index' , 9);
		
		this.contenidos[this.options.item_seleccionado].setStyles({
		    'z-index': '10',
		    'display': 'block'
		});
		//$('titulo').innerHTML = this.contenidos[this.options.item_seleccionado].title;
		var morph = this.contenidos[this.options.item_seleccionado].get('morph', {duration: this.options.tiempo_efecto});
		morph.start({'left': 0}).chain(this.cambiarSeleccionado.bindWithEvent(this));
	},
	
	cambiarSeleccionado: function(e){
		if ((this.options.item_seleccionado - 1) >=0)
			this.contenidos[(this.options.item_seleccionado - 1)].setStyle('left', $(this.options.container).getSize().x + $(this.contenidos[this.options.item_seleccionado]).getSize().x);
		else
			this.contenidos[(this.total_contenidos - 1)].setStyle('left', $(this.options.container).getSize().x + $(this.contenidos[this.options.item_seleccionado]).getSize().x);
		
		if ((this.options.item_seleccionado + 1)>(this.total_contenidos-1))
			this.options.item_seleccionado = 0;
		else
			this.options.item_seleccionado = (this.options.item_seleccionado + 1);
	}
	
	
});
