var SlideShow = {
	quantity: 0,
	still: 10,
	transition: 5,
	id: "image",
	url: "",
	sig: 0,
	next: function(){
		if(SlideShow.quantity==0){
			new Ajax.Updater(SlideShow.id,SlideShow.url, { // URL for next <IMG> tag 
				asynchronous: true,
				onSuccess: function() { 
					new Effect.Opacity(SlideShow.id, {
						duration: SlideShow.transition/2,
						from:0.0, to:1.0
					});
				}
			});
		}
		else if(SlideShow.quantity>0){
			var rand=Math.floor(Math.random()*SlideShow.quantity)+1;
			$(SlideShow.id).src = SlideShow.url+rand+".jpg";
			new Effect.Opacity(SlideShow.id,{
				duration: SlideShow.transition/2,
				from:0.0, to:1.0
			});
		}
		else{
			var rand=(++SlideShow.sig%Math.abs(SlideShow.quantity))+1;
			$(SlideShow.id).src = SlideShow.url+rand+".jpg";
			new Effect.Opacity(SlideShow.id,{
				duration: SlideShow.transition/2,
				from:0.0, to:1.0
			});
		}
	},
/**
 * Inicia el pase de diapositivas
 * @param url origen de las imagenes: si q==0, direccion de un codigo de servidor para AJAX;
 * de lo contrario, directorio donde se almacenan las imagenes
 * @param i id de la imagen a cambiar
 * @param s tiempo en segundos que la imagen permanece estatica
 * @param t tiempo en segundos para la transicion
 * @param q cantidad de imagenes a usar: si q==0, numero indefinido y se usa AJAX;
 * de lo contrario, las imagenes deben ser nombradas 1.jpg, etc. hasta {q}.jpg
*/
	startup: function(url,i,s,t,q){
		if (url !== undefined) SlideShow.url = url;
		if (i !== undefined) SlideShow.id = i;
		if (s !== undefined) SlideShow.still = s;
		if (t !== undefined) SlideShow.transition = t;
		if (q !== undefined) SlideShow.quantity = q;
		new PeriodicalExecuter(SlideShow.cycle,SlideShow.still+SlideShow.transition);
	},
	cycle: function(){
		new Effect.Opacity(SlideShow.id, {
			duration:SlideShow.transition/2,
			from:1.0, to:0.0,
			afterFinish: function(){ 
				SlideShow.next();
			}
		});
	}
}

