        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 = jQuery(data.container);
            this.scrolledObj = jQuery(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();
            }
            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;

            jQuery(this.prevButton).click(function() {
                if (!_obj.scrollingStarted)
                {
                    _obj.scrollIt(BS_PREV);
                }
                return false;
            });

            jQuery(this.nextButton).click(function() {
                if (!_obj.scrollingStarted)
                {
                    _obj.scrollIt(BS_NEXT);
                }
                return false;
            });
        }

        // стек таймеров
        BlocksScroller.prototype.timers = new Array();

        /**
         *  инициализация таймера
         *
         */
        BlocksScroller.prototype.initTimer = function()
        {
            BlocksScroller.prototype.timers.push(this);
            var _currIndex = BlocksScroller.prototype.timers.length - 1;

            window.setInterval("(BlocksScroller.prototype.timers[" + _currIndex + "]).scrollIt(BS_NEXT)", this.timerSpeed);
        }

        /**
         *  прокрутка
         *
         *  direction: направление
         */
        BlocksScroller.prototype.scrollIt = function(direction)
        {
            if ((direction > 0 && ((Math.abs(this.pos) + this._visAreaWidth) >= this._allAreaWidth))) // листание вперед при достижении правой границы
            {
                this.scrolledObj.css("left", -(this._allAreaWidth - this._visAreaWidth - this.blockWidth) + "px");
                // перемещаем первый элемент в конец
                jQuery("> :first-child", this.container).remove().insertAfter(jQuery("> :last-child", this.container));
            }
            else if (direction < 0 && this.pos == 0) // листание назад при достижении левой границы
            {
                this.scrolledObj.css("left", -this.blockWidth + "px");
                // перемещаем последний элемент в начало
                jQuery("> :last-child", this.container).remove().insertBefore(jQuery("> :first-child", this.container));
            }
            else
            {
                this.pos -= direction * this.blockWidth;
            }

            this.scrollingStarted = true;
            var _obj = this;
            this.scrolledObj.animate({ left: this.pos }, this.speed, null, function() { _obj.clearStartedFlag(); });
        }

        /**
         *  очищаем флаг анимации
         *
         */
        BlocksScroller.prototype.clearStartedFlag = function()
        {
            this.scrollingStarted = false;
        }

