Slideshow = function(parent_id, start_frame, delay)
{
	this.start_frame = start_frame;
	this.end_frame = start_frame;
	this.current_frame = start_frame;
	this.next_frame;
	this.delay = delay;
	this.running = true;
	this.elements = false;
	this.parent_id = parent_id;
	this.swap_action = false;
	this.fadeInOut = this.mozTransition;
	if(navigator.appVersion.indexOf('MSIE 6') == -1) {
		this.init();
	}
}

Slideshow.prototype.init = function()
{
	this.elements = document.getElementById(this.parent_id).children;
	if(this.elements.length > 0) {
		this.end_frame = this.elements.length-1;
		this.next_frame = 1;
	}

}

Slideshow.prototype.start = function()
{
	var tmp = this;
	var timer_id = 0;
	tmp.running = true;

	timer_id = setInterval(function() {
		if(tmp.running) {
			tmp.fadeInOut();
		}
		else {
			clearInterval(timer_id);
		}
	}, tmp.delay);
}

Slideshow.prototype.stop = function()
{
	this.running = false;
}

Slideshow.prototype.restart = function()
{
	this.fadeInOut();
	this.start();
}

Slideshow.prototype.mozTransition = function()
{
	if(this.next_frame > this.end_frame) {
		this.next_frame = this.start_frame;
	}

	$(this.elements[this.current_frame]).fadeOut();
	this.current_frame = this.next_frame;
	$(this.elements[this.current_frame]).fadeIn();

	this.next_frame++;
}

Slideshow.prototype.ieTransition = function()
{
	if(this.next_frame > this.end_frame) {
		this.next_frame = this.start_frame;
	}

	this.elements[this.current_frame].style.display='none';
	this.current_frame = this.next_frame;
	this.elements[this.current_frame].style.display='block';

	this.next_frame++;
}

/*
Slideshow.prototype.fadeInOut = function()
{
	if(this.next_frame > this.end_frame) {
		this.next_frame = this.start_frame;
	}

	$(this.elements[this.current_frame]).fadeOut();
	this.current_frame = this.next_frame;
	$(this.elements[this.current_frame]).fadeIn();

	this.next_frame++;
}
*/

Slideshow.prototype.setSwapAction = function(swap_action) {
	this.swap_action = swap_action;
}

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();
	}
}

