;(function($) {
	/**
	 * Image Rotator plugin
	 * @param {Object} options
	 */
	$.fn.imageRotator = function(options) {
				
		return this.each(function(){
			var $this = $(this),
				images = options.images, // array
				total = images.length, // total images length
				interval = options.interval ? options.interval : 7000, // interval millisecond
				currentIndex = 0; // current index
				
			function rotation(){
				$('<img />').load(function(event){
					var $nextImage = $(this);
					if($this.find('img').length > 1) {
						$this.find('img:last').fadeOut('slow', function(){ $(this).remove(); });
					}
					$this.prepend($nextImage.hide());
					$nextImage.fadeIn('slow', function(){
						if (total > 1) {
							currentIndex = (currentIndex == images.length - 1) ? 0 : currentIndex + 1;
							setTimeout(rotation, interval);
						}
					});
				}).attr('src', images[currentIndex]);
			};
		
			rotation();
		});
	}
})(jQuery);