(function($) {
	$.fn.scroller = function(settings) {
		var settings = $.extend({
			slideWidth:300,			// Ширина элемента
			marginLeft:17,			// Отступ слева [кроме первого]
			speed:500,				// Скорость перемещения
			leftButton:'#left',		// Кнопка "влево"
			rightButton:'#right'	// Кнопка "вправо"
		}, settings);
		
		var current = 0,
			$this = $(this),
			l = settings.slideWidth + settings.marginLeft,
			n = $(this).children().size(),
			$line = $('#line');
			
		// var movel = (n > 4) ? 875 / (n - 2) : 875 / (n - 2); // 656
		var movel = 875 / (n - 2);
		$line.css('width', movel);
		//if($.browser.msie) $('#line').attr('width',movel);
		var overallWitdh = settings.slideWidth * n;
		var max = overallWitdh - settings.slideWidth * 3;

		$($this).css('width', overallWitdh + settings.marginLeft * n+'px')
				.css('overflow','hidden')
				.children()
				.not(':first')
				.css('margin-left', settings.marginLeft+'px');
		
		$(settings.leftButton).bind('click', function() {
			if(current > 0) {
				moveLine('-');
				$this.stop(false,true).animate({left:'+='+l+'px'}, settings.speed);
				current -= settings.slideWidth;
			}
			$(settings.rightButton).css('color','white');
			$(settings.leftButton).css('color', (current <= 0) ? 'grey' : 'white');
		});
		
		$(settings.rightButton).bind('click', function() {
			if(current < max) {
				moveLine('+');
				$this.stop(false,true).animate({left:'-='+l+'px'}, settings.speed);
				current += settings.slideWidth;
			}
			$(settings.leftButton).css('color','white');
			$(settings.rightButton).css('color', (current < max) ? 'white' : 'grey');
		});
		
		moveLine = function(z) {
			$('#line').animate({marginLeft:z+'='+movel+'px'},500);
		};
		
		return $this;
	};
})(jQuery);
