	
	(function($){
		
		function nqs_animate ( obj, dir, len, step ) {
			
			if (obj.queue().length > 0 ) return;
			if (obj.attr('class').match(/stop/)) return;
			
			l = parseInt(obj.css('left'));
			if (len == 0) len = obj.find('.slide').length-1;
			if (step == 0) {
				step = parseInt( obj.children('div:eq(0)').css('width') );
				if (obj.attr('class').indexOf('nqsvideoslider') != -1) step+=10; 
			}
			
			if ( dir == 'left' ) {
				
				if (l == 0) { obj.css('left', -1*len*step+'px'); }
				obj.animate({ left: '+='+step }, 1500, function() {
					if (step+l == 0) obj.css('left', -1*len*step+'px');
				});
			}
			else {
				
				if (len*step+l<=0) { obj.css('left', '0px'); }
				obj.animate({ left: '-='+step }, 1500, function() {
					
					setTimeout(function() { nqs_animate(obj, 'right', len, step); }, 5000);
				});
			}
		}
		
		$.fn.nqsSlider = function(options) {
			
			$('.move_right').click(function(){
				var $obj = $(this).parent().find('div:eq(1)').removeClass('stop'); nqs_animate( $obj, 'right', 0, 0 ); $obj.addClass('stop');
			})
			$('.move_left').click(function(){
				var $obj = $(this).parent().find('div:eq(1)').removeClass('stop'); nqs_animate( $obj, 'left', 0, 0 ); $obj.addClass('stop');
			})
			
			return this.each(function(){
				
				var $step = $(this).width();
				$(this).css({'width': $step+'px', overflow: 'hidden', position: 'relative'});
				
				var $slides = $(this).find('.slide').css('width', $step+'px');
				var $slider = $(this).children('div:eq(0)');
				if ( $slider.attr('class').indexOf('stop') != -1 ) $step+=10;
				
				if ( $slides.length > 1 ) {
					
					var $w = $slides.length*$step;
					var $last = $slider.children('div:last');
					
					$slider.css({width: $w+$step+'px', position:'relative', left: '0px', top: 0});
					$( $slides[0] ).clone().insertBefore( $last );
					setTimeout(function() { var obj = $slider; nqs_animate(obj, 'right', $slides.length, $step); }, 2000);
				}
			});
		};
	})(jQuery);
	
	jQuery(document).ready(function($) {
		$('.slider-container').nqsSlider();
	})
	
