function Slideshow(buffer1_id, buffer2_id, interval) {
	this.slides = new Array();
	this.slide_names = new Array();
	this.num_slides = 0;

	this.timer = new Timer(this);
	this.delay = interval;

	this.buffer1 = buffer1_id
	this.buffer2 = buffer2_id;

	this.active_slide_index = 0;
	this.buffer_index = 0;
}

Slideshow.prototype.set_buffer_identifiers = function(buffer1_id, buffer2_id) {
	this.buffer1 = buffer1_id;
	this.buffer2 = buffer2_id;
}

Slideshow.prototype.set_delay = function(interval) {
	this.delay = interval;
}

Slideshow.prototype.add_slide = function(src) {
	this.slide_names.push(src);
	this.slides.push(new Image());
	this.num_slides++;
}

Slideshow.prototype.play = function() {
	this.slides[0].src = this.slide_names[0];
	this.next_slide();
}

Slideshow.prototype.next_slide = function() {
	this.update_slide(true);
	this.buffer_index++;
	this.increment_active_slide();
	this.slides[this.active_slide_index].src = this.slide_names[this.active_slide_index];
	this.timer.setTimeout('next_slide();', this.delay, function() {});
}

Slideshow.prototype.update_slide = function(fade) {
	if (this.buffer_index % 2) {
		var b1 = this.buffer1;
		var b2 = this.buffer2;
	} else {
		var b1 = this.buffer2;
		var b2 = this.buffer1;
	}

	$(b1).css({'z-index': '1'});
	$(b2).css({'z-index': '2', 'background-image': 'url('+ this.slides[this.active_slide_index].src +')'});
	if (fade) { 
		$(b2).fadeIn(500, function(){$(b1).hide();});
	} else {
		$(b2).show();
		$(b1).hide();
	}
}

Slideshow.prototype.increment_active_slide = function() {
	this.active_slide_index = (this.active_slide_index + 1) % this.num_slides;
}

