(function($) {
$.fn.imagerotation = function(images, options) {
	options = $.extend({
		speed: 6000,
		fadeInSpeed: 750,
		fadeOutSpeed: 250
	}, options);
	
	// only allow div layer
	if(!$(this).is('div')) return false;
	
	
	$(this).empty();
	
	// image preload / add images
	for(i in images) {
		var image = $('<img>');
		image.attr('src', images[i]);
		image.hide();
		
		$(this).append(image);
	}
	
	var imgs = $(this).children('img');
	
	imgs.eq(0).fadeIn(options.fadeInSpeed);
	rotateImage(imgs, 0, options);
	
	
	return $(this);
}

function rotateImage(images, current, options) {
	var next = current + 1;
	if(current >= images.length-1)
		next = 0;
	
	setTimeout(function() {
		images.eq(current).fadeOut(options.fadeOutSpeed, function() {
			images.eq(next).fadeIn(options.fadeInSpeed);
			
			rotateImage(images, next, options);
		});
	}, options.speed);
}

})(jQuery);
