
var slideshow;

/* SlideShow */
function SlideShow (target) {
	//fac.log("SlideShow(" + [target] + ")");
	
	this.target = 
		$(target);
	
	this.list = 
		$("> ol", this.target)
		.css({display:"none"});
	
	this.list_item = 
		$("> li", this.list);
		
	$("> img", this.list_item)
		.css({opacity:0.0});
}

SlideShow.prototype = {
	
	target        : null, 
	list          : null, 
	list_item     : null, 
	
	selected      : null, 
	min           : null, 
	max           : null, 
	
	start : function () {
		//fac.log("SlideShow.start(" + [] + ")");
		
		this.selected = -1;
		this.min = 0;
		this.max = this.list_item.length - 1;
		
		this.list
			.css({display:"block"});
		
		this.select(0, 0.0);
	}, 
	
	next : function () {
		//fac.log("SlideShow.next ()");
		
		this.select(this.selected + 1);
	}, 
	
	previous : function () {
		//fac.log("SlideShow.previous ()");
		
		this.select(this.selected - 1);
	}, 
	
	select : function (value, time) {
		//fac.log("SlideShow.select (" + [value, time] + ")");
		
		time = time != undefined ? time : 1500;
		
		value = this.getSelected(value);
		if (value == this.selected) return;
		
		if (this.selected != -1) {
			$("> img", this.list_item)
				.css({zIndex:1})
				.stop()
				.animate({opacity:0.0}, {duration:time, easing:"easeInOutCubic"});
		}
		
		$("> img", this.list_item[value])
			.css({zIndex:2})
			.stop()
			.animate({opacity:1.0}, {duration:time, easing:"easeInOutCubic"});
		
		this.selected = parseInt(value);
		
		$(this.target)
			.stop()
			.animate({left:0}, {duration:5 * 1000, complete:fac.delegate(this, this.next)});
	}, 
	
	getSelected : function (value) {
		//fac.log("SlideShow.getSelected (" + [time] + ")");
		
		if (value < this.min) value = value + this.max + 1;
		if (value > this.max) value = value - this.max - 1;
		
		return value;
	}
	
}



