(function($) {
	
	$.fn.jsbSlider = function(options) {
	
		var defaults = {
			speed:1000,
			pause:2000,
			transition:'slide'
		}
		
		options = $.extend(defaults,options);
		
		this.each(function() {
			
			$this = $(this);
			
			$this.wrap("<div class='content-wrap' />");
			$wrapper = $this.parent('div');
		
			if(options.transition === 'slide'){
                                console.log('start')
				$this.css({
					'width':'99999px',
					'position':'relative',
					'padding':0
				})
				
				$this.children().css({
					'float':'left',
					'list-style':'none'
				});

				$wrapper.css({
					'width' : $this.parent().width(),
					'overflow' : 'hidden'
					
				});
				
			}
			
			if(options.transition === 'fade'){
				
				var $top = $this.children("li:first-child");
					$top.css({'z-index':'2'});
			
				$this.children().css({
					'width':$this.children().width(),
					'position':'absolute',
					'left':0,
					'list-style':'none'
					
				})
				
				$wrapper.css({
					'width' : $this.children().width(),
					'overflow' : 'hidden'
					
				});
			
				jdfwarrior_fade();
				
			}
			
			if(options.transition === 'slide') slide();	
			
			
			function slide() {
				setInterval(function() {
					// Animate to the left the width of the image/div
					$this.animate({'left' : '-' + $this.parent().width()}, options.speed, function() {
						// Return the "left" CSS back to 0, and append the first child to the very end of the list.
						$this
						   .css('left', 0)
						   .children(':first')
						   .appendTo($this); // move it to the end of the line.
					})
				}, options.pause);
			} // end slide

			function fade() {
				setInterval(function() {
					$this.children(':first').animate({'opacity' : 0}, options.speed, function() {	
						$this
						   .children(':first')
						   .css('opacity', 1) // Return opacity back to 1 for next time.
						   .css('zIndex', $this.children(':last').css('zIndex') - 1) // Reduces zIndex by 1 so that it's no longer on top.					
						   .appendTo($this); // move it to the end of the line.
					})
				}, options.pause);
			} // end fade
			
			function jdfwarrior_fade()
			{
				var timer = window.setInterval(function(){
					var $next = $top.next('li');
					$next.css({
						'z-index':'1'
					})
					$top.fadeTo(options.speed,0, function() {
						$top.css({'z-index':'0'}).remove().appendTo($this).fadeTo(0,1);
						$next.css({
							'z-index':'2'
						})
						$top = $next;
					});
				}, options.pause)
			}
		});
	};
	
})(jQuery)
