jQuery.fn.imgal = function(options) {

	var settings = jQuery.extend({
		timeout: 2000,
		animDuration: 500,
	}, options); 
	
	var $this = $(this);
	var images = Array();
	var currentImage = 0;
	init();
	
	function init() {
		var $elems = $this.children("img");
		
		var i = 0;
		$elems.each(function() {
			images[i] = $(this)
			i++;
		});
		$this.html("");
		$this.append(images[0]);
	};

	function animate() {
		currentImage ++;
		if (currentImage >= images.length) {
			currentImage=0;
		}
		$img = images[currentImage];
		$img.css('opacity', 0);
		
		$this.append(images[currentImage]);

		$img.animate({opacity: 1}, settings.animDuration, function(){
			$("img:first", $this).remove();
		});
		setTimeout(animate,settings.timeout);
	};

	setTimeout(animate, settings.timeout);
};

