
/* SlideShow */
function SlideShow (slide) {
	//alert("SlideShow (" + [slide] + ")");
	
	var p = this;
	this.slide = slide;
	this.entries = this.slide + " li";
	
	this.entries_length = $(this.entries).length;
	this.selected = -1;
	this.min = 0;
	this.max = this.entries_length - 1;
	this.interval_id;
	
	$(slide).css({position:"relative"});
	$(this.entries).css({float:"none", position:"absolute", left:"-715px", top:"0px"});
	$($(this.entries)[0]).css({left:"0px"});
	
	this.select(0, 0);
	
	return this;
}

SlideShow.prototype.next = function () {
	//alert("SlideShow.next ()");
	
	this.select(this.selected + 1);
}

SlideShow.prototype.previous = function () {
	//alert("SlideShow.previous ()");
	
	this.select(this.selected - 1);
}

SlideShow.prototype.select = function (value, time) {
	//alert("SlideShow.select (" + [value, time] + ")");
	
	value = this.getSelected(value);
	
	if (value == this.selected) return;
	
	time = time != undefined ? time : 700;
	
	var last_entry = $(this.entries)[this.selected];
	if (last_entry) {
		$(last_entry)
			.css({left:"0px"})
			.stop().animate({left:"715px"}, time);
	}
	
	var selected_entry = $(this.entries)[value];
	$(selected_entry)
		.css({left:"-715px"})
		.stop().animate({left:"0px"}, time);
	
	this.selected = value;
	
	clearInterval(this.interval_id);
	this.interval_id = setInterval(delegate(this, this.next), 4000);
}

SlideShow.prototype.getSelected = function (value) {
	
	if (value < this.min) value = this.max + (value - this.min) + 1;
	if (value > this.max) value = this.min + (value - this.max) - 1;
	
	return value;
}

function delegate (this_object, method, args) {
	
	return function () { return method.call(this_object, args); }
}





