var Slideshow = Class.create({




	initialize: function(slideshow, timeout){
		
		this.slides = $$('#slideshow div');
		this.timeout = timeout;
		this.current = 0;
		this.total = this.slides.length;
		this.slides.first().show();
		this.next = 0;

        var objBody = $('slideshow');

		objBody.appendChild(Builder.node('div',{id:'numbers'}));
		var i = 0;
		var node = null;
		/*this.slides.each(function(el){
			if(i != 0) el.hide();
			node = Builder.node('a', {id:'slideshow_shi'+i, href: '#' }, ''+(i+1));
			node.observe('click', function(event){
				event.stop();
				sh.chosenImage(node.id.substr(13,node.id.length));
			});

			//$('numbers').appendChild(node);
			i++;
		});*/

		this.styleNumber(0);

		this.pe = new PeriodicalExecuter(this.nextImage.bind(this), this.timeout);	
	},

	nextImage: function(){
			if(this.current+1 < this.total)
				this.next = this.current+1;
			else
				this.next = 0;

			Effect.Fade(this.slides[this.current], {duration: 0.5});
			Effect.Appear(this.slides[this.next], {duration: 0.5});
			this.styleNumber(this.next);
			this.current = this.next;
	},

	chosenImage: function(number){
			//alert(parseInt(number)+1);
			//alert(this.total);
			number = parseInt(number)+1;
			this.pe.stop();
			if(number < this.total)
				this.next = number;
			else
				this.next = 0;
			Effect.Fade(this.slides[this.current], {duration: 0.5});
			Effect.Appear(this.slides[this.next], {duration: 0.5});
			this.styleNumber(number);
			this.current = this.next;
			this.pe = new PeriodicalExecuter(this.nextImage.bind(this), this.timeout);
	},


	styleNumber: function(active){
		$$('#numbers a').each(function(item){ item.className = 'default'; });
		//$('slideshow_shi'+active).className = 'act';
	}


});