function Slideshow() {};
Slideshow.prototype = {
	i: 0,
	c: 0,
	p: 0,
	jqo: undefined,
	paused: false,
	delay: 3000,
	timer: undefined,
	
	init: function(jqo) {
		var cls = this;
		
		this.c = $("li",jqo).length;
		
		$("li",jqo).hide();
		$("li",jqo).eq(this.i).show();
		this.jqo = jqo;
	},
	
	next: function() {
		this.direct(this.i+1);
	},
	
	previous: function() {
		this.direct(this.i-1);
	},
	
	direct: function(i) {
		if(this.i == i) {
			return; 
		} else if(i < 0) {
			i = this.c-1;
		} else if(i >= this.c) {
			i = 0;
		}

		this.p = this.i;
		this.i = i;
		
		clearTimeout(this.timer);
		$("li",this.jqo).eq(this.i).fadeIn(1000);
		$("li",this.jqo).eq(this.p).fadeOut(1000,this.start());
	},
	
	start: function() {
		this.paused = false;
		
		var cls = this;
		this.timer = setTimeout(function() {
			if(!cls.paused) {
				cls.next();
			}
		},this.delay);
	},
	
	stop: function() {
		clearTimeout(this.timer);
		this.paused = true;
	}
};


$(document).ready(function() {
	$(".slideshow").each(function() {
		var slideshow = new Slideshow();
		slideshow.init($(this));
		slideshow.start();
	});
});
