(function($) {
	$.fn.jlSlider = function(options) {
		var defaults = {
			speed : 1000,
			pause : 3000,
			transition : 'fade'
		},
		
		options = $.extend(defaults, options);
		
		if(options.pause <= options.speed) options.pause = options.speed + 100;
		
		
		this.each(function() {
			var $this = $(this);
			
			$this.wrap('<div class="slider-wrap" />');

			if(options.transition === 'slide') {
				$this.children().css({
					'float' : 'left',
					'list-style' : 'none'
				});
				
				$('.slider-wrap').css({
					'width' : $this.children().width(),
					'overflow' : 'hidden'
				});
			}
			
			if(options.transition === 'slide') slide();
			

			if(options.transition === 'fade') {
				var cname;
				for(var y=0; y < $this.children().length; y++) {
					if(y==0) {
						cname='first';
					} else if (y==1) {
						cname='second';
					} else {
						cname='bottom';
					}
					$this.children().eq(y).addClass(cname);
				}
				fade();
			}
			function fade() {
				setInterval(function() {
					$this.find('.first').animate({'opacity' : 0 }, options.speed, function() {
						$this.find('.first')
						.css('opacity', 1)
						.removeClass('first')
						.addClass('bottom')
						.appendTo($this);
					$this.find('.second').removeClass('second').addClass('first');
					$this.find('.bottom').eq(0).removeClass('bottom').addClass('second');
					})
				}, options.pause);
			}

			function slide() {
				setInterval(function() {
					$this.animate({'left' : '-' + $this.parent().width() }, options.speed, function() {
						$this
						.css('left',0)
						.children(':first')
						.appendTo($this);
					})
				}, options.pause);
			}

		});
	}				
})(jQuery);

