(function ($) {
	$.fn.rotator = function () {
		return this.each( function () {
			var $this = $(this),
				$items = $this.find('li'),
				$current = $items.filter('.item-1');
				
			var amount = $items.length - 1,
				i = 0,
				interval;
				
			var rotateTime = 10000;
			
			var startRotate = function () {
				i = i >= amount ? 0 : i + 1;
				var $next = $items.eq(i);
				$current.fadeOut(600);
				setTimeout( function () {
					$this.trigger('sliding', $next);
					$next.fadeIn('slow', function () {
						$current = $(this);
					});	
				}, 500);
			};
			
			// Custom binds
			$this.bind({
				'stop.rotate' : function () {
					clearInterval(interval)
				},
				'start.rotate' : function () {
					interval = setInterval(startRotate, rotateTime);
				}
			});

			$this.trigger('start');
		});
	}
})(jQuery);