(function ($) {
	
	var Slider = function (container, options) {
		if (!options) options = {};
		if (options.timeout) this.timeout = options.timeout;
		
		//Set container
		this.container = container;
		
		//Get images
		this.images = $('IMG', this.container);
		
		//Reset vars
		this.activeImage = 0;
		
		//Create timer
		var self = this;
		setTimeout(function () {
			self.next();
			setTimeout(arguments.callee, self.timeout);
		}, this.timeout);
	};
	
	Slider.prototype.next = function () {
		var p = this.activeImage;
		this.activeImage = (this.activeImage + 1 == this.images.length ? 0 : this.activeImage + 1);
		
		this.images.eq(p).css('zIndex', 5);
		this.images.eq(this.activeImage)
			.removeClass('hidden')
			.css({zIndex: 4, opacity: 1, display: 'block'});
			
		this.images.eq(p).animate({opacity: 0}, 'fast');
	};
	
	Slider.prototype.timeout = 5000;
	
	Slider.activeImage = 0;
	
	Slider.prototype.container = null;
	
	Slider.prototype.images = [];
	
	$.fn.slider = function (o) {
		new Slider(this, o);
	};
	
})(jQuery);
