Slideshow = function(ul_id, current_frame, delay)
{
	this.ul_id = ul_id;
	this.start_frame = 0;
	this.end_frame = this.start_frame;
	this.current_frame = current_frame;
	this.next_frame;
	this.delay = delay;
	this.running = true;
	this.lis = false;
	this.init(ul_id);
}

Slideshow.prototype.init = function(ul_id)
{
	this.lis = $(ul_id).select('li');
	if(this.lis.length > 0) {
		for(i=0;i<this.lis.length; i++) {
			if(i!=this.current_frame) {
				this.lis[i].style.display = 'none';
			}
		}
		this.end_frame = this.lis.length-1;
		this.next_frame = 1;
	}

	this.start(this.start_frame);
}

Slideshow.prototype.start = function()
{
	var tmp = this;
	new PeriodicalExecuter(function(pe) {
		if(tmp.running) {
			tmp.fadeInOut();
		}
	}, tmp.delay);
}

Slideshow.prototype.fadeInOut = function()
{
	if(this.next_frame > this.end_frame) {
		this.next_frame = this.start_frame;
	}
	var tmp_scope = 'slide-show-'+this.ul_id;
	
	Effect.Fade(this.lis[this.current_frame], {duration:.50,queue:{position:'end', scope:tmp_scope}});
	this.current_frame = this.next_frame;
	Effect.Appear(this.lis[this.current_frame], {duration:.50,queue:{position:'end', scope:tmp_scope}});

	this.next_frame++;
}

Slideshow.prototype.goto = function(frame_index)
{
	if(frame_index >= this.start_frame && frame_index <= this.end_frame) {
		this.running = false;
		this.next_frame = frame_index;
		this.fadeInOut();
	}
}
