        var BS_NEXT = 1;
        var BS_PREV = -1;
        var BS_BY_BUTTONS = 2;
        var BS_BY_TIMER = 3;
        
        /**
         *  constructor
         *  
         *  передаются настройки:
         *      container: dom-контейнер для блоков
         *      blocksCount: количество блоков
         *      blockWidth: ширина одного блока
         *      visibleBlocks: количество видимых блоков
         *      prevButton: объект с кнопкой листания назад (для режима листания кнопками)
         *      nextButton: объект с кнопкой листания вперед (для режима листания кнопками)
         *      speed: скорость скроллинга (по умолчанию slow)
         *      scrollType: тип скроллирования (кнопками или по таймеру, по умолчанию кнопками)
         *      timerSpeed: временной интервал листания (для режима листания по таймеру)                                      
         */
        function BlocksScroller(data)
        {
            if ("undefined" == typeof(data))
            {
                alert("Не заданы данные");
                return;
            }
            this.container = $(data.container);
            this.scrolledObj = $(data.scrolledObj)
            this.scrolledObj[0].obj = this;
            this.pos = 0;
            this.blocksCount = data.blocksCount;
            this.blockWidth = data.blockWidth;
            this.visibleBlocks = data.visibleBlocks;
            this.scrollingStarted = false;
            
            // ширина видимой части
            this._visAreaWidth = this.blockWidth * this.visibleBlocks;
            
            // ширина всего прокручиваемого блока
            this._allAreaWidth = this.blockWidth * this.blocksCount;
            
            if (data.scrollType)
            {
                this.scrollType = data.scrollType;
            } 
            else
            {
                this.scrollType = BS_BY_BUTTONS;
            }
            
            if (BS_BY_BUTTONS == this.scrollType)
            {
                this.prevButton = data.prevButton;
                this.nextButton = data.nextButton;

                this.initButtons();
				
				this.timerSpeed = 7000;
                //this.initTimer();
            }
            else
            {
                this.timerSpeed = data.timerSpeed;
                //this.initTimer();
            }
            
            if (data.speed)
            {
                this.speed = data.speed;
            }
            else
            {
                this.speed = "slow";
            }
    
        }
        
        /**
         *  вешаем обработчики событий на кнопки вперед/назад
         *  
         */                          
        BlocksScroller.prototype.initButtons = function()
        {			
            var _obj = this;

            $(this.prevButton).click(function() {
                if (!_obj.scrollingStarted)
                {
                    _obj.scrollIt(BS_PREV,true);
                }
                return false;
            });

            $(this.nextButton).click(function() {
                if (!_obj.scrollingStarted)
                {
                    _obj.scrollIt(BS_NEXT,true);
                }
                return false;
            });
        }
        
        // стек таймеров
        BlocksScroller.prototype.timers = new Array();
        
        /**
         *  инициализация таймера
         *  
         */                          
        BlocksScroller.prototype.initTimer = function()
        {
            BlocksScroller.prototype.timers.push(this);
            var _currIndex = BlocksScroller.prototype.timers.length - 1;

            this.inter_id = window.setInterval("(BlocksScroller.prototype.timers[" + _currIndex + "]).scrollIt(BS_NEXT,false)", this.timerSpeed);
        }

        /**
         *  прокрутка
         *  
         *  direction: направление
         */   	
        BlocksScroller.prototype.scrollIt = function(direction, but)
        {
			if (but) window.clearInterval(this.inter_id);		 
            if ((direction > 0 && ((Math.abs(this.pos) + this._visAreaWidth) >= this._allAreaWidth))) // листание вперед при достижении правой границы
            {
                this.scrolledObj.css("left", -(this._allAreaWidth - this._visAreaWidth - this.blockWidth) + "px");
                // перемещаем первый элемент в конец
                $("> :first-child", this.container).remove().insertAfter($("> :last-child", this.container));
            }
            else if (direction < 0 && this.pos == 0) // листание назад при достижении левой границы
            {
                this.scrolledObj.css("left", -this.blockWidth + "px");
                // перемещаем последний элемент в начало
                $("> :last-child", this.container).remove().insertBefore($("> :first-child", this.container));
            }
            else
            {
                this.pos -= direction * this.blockWidth;
            }  

			if (this.pos<0)
			{
			    this.scrollingStarted = true;
				var _obj = this;
				this.scrolledObj.animate({ left: -145 }, 400, null, function() { _obj.clearStartedFlag(); });
				this.scrolledObj.animate({ left: -125 }, 250, null, function() { _obj.clearStartedFlag(); });
			}
			
			if (this.pos==0)
			{
			    this.scrollingStarted = true;
				var _obj = this;
				this.scrolledObj.animate({ left: 20 }, 400, null, function() { _obj.clearStartedFlag(); });
				this.scrolledObj.animate({ left: 0 }, 250, null, function() { _obj.clearStartedFlag(); });
			}
			
			//alert(this.pos);
        }
        
        /**
         *  очищаем флаг анимации
         *  
         */                          
        BlocksScroller.prototype.clearStartedFlag = function()
        {
            this.scrollingStarted = false;
        }

