/*
	SLIDESHOW CLASS
	-
	a div of imgs
	an interval
	on interval:
		hide all imgs
		show old, new (old above new)
		fade old
*/

Slideshow$Class =
{
	constructor: function(options)
	{
		jQuery.extend(this, Slideshow$Class);
		jQuery.extend(true, this, options);
	},
	
	DURATION:4000,
	interval:null,
	div:null,
	id:0,
	total:0,
	
	init: function(div)
	{
		this.div = div;
		this.total = div.find('img').length;
	},
	
	stop: function()
	{
		clearInterval(this.interval);
	},
	
	start: function()
	{
		// show first image
		this.div.find('img:eq(0)').show();
		
		this.interval = setInterval( $.bind(this,this.change) , this.DURATION );
	},
	
	change: function()
	{
		var old_img_id = this.id
			new_img_id = this.id = (this.id+1>=this.total)? 0 : this.id+1;
		
		this.div.find('img').each(function(i){
			$(this)
				.hide()
				.css({zIndex:0});
		});
			
		var n = this.div.find('img:eq('+new_img_id+')')
			.show()
			.css({zIndex:1});
			
		//log( 'new', n.css("z-index") );
			
		var o = this.div.find('img:eq('+old_img_id+')')
			.css({zIndex:2})
			.show()
			.fadeOut("slow");
		
		//log( 'old', o.css("z-index") );
	}
	
};
Slideshow = Slideshow$Class.constructor;