(function($) {

	$.fn.slider = function(options) {

		$.fn.slider.defaults = {
			display_time: 5000,
			transition_speed: 2000
		};
				
		var opts = $.extend({}, $.fn.slider.defaults, options);
		
		return this.each(function() {
			
			/* VARIABLES */
			var $this = $(this),
				$parent = $this.parent(),
				timer = false,
				$partner = $this.children(),
				count = $partner.size();
			
			/* SETUP THE IMAGES */
			setup();			
			
			/* SETS UP THE IMAGE DISPLAYS */
			function setup() {
				$partner.css({float: 'left'});
				$this.css({width: count*180 + 'px', height: 'auto'});
				
				if (count > 1) {
					initiateInterval();
					$parent.hover(function() {
						clearInterval(timer);
					},function() {
						initiateInterval();
					});
				}
			}
			
			/* CONSTRUCTOR */
			function rotate() {
				var $current = $this.children(':visible:first') == 'undefined' ? $this.children(':first') : $this.children(':visible:first'),
					$next = $current.next() == 'undefined' || $current.next().html() == null ? $this.children(':first') : $current.next(),
					$last = $this.children(':visible:last') == 'undefined' ? $this.children(':last') : $this.children(':visible:last');
				
				if (count > 1) {
					$current.stop().animate({'width': 'toggle'}, opts.transition_speed, function() {
						$last.after($current.clone().css({'width': 'auto', 'float': 'left'}).show());
						$current.remove();
					});
				}
				
			}

			/* INITIATES THE INTERVAL TIMER */
			function initiateInterval() {
				timer = setInterval(function() {
					rotate();
				}, opts.display_time);
			}
			
		});	
	};

})(jQuery);
