        // Cool sliding by ABTOMAT 2010 Version 1.0
        //
        // Version 1.0:
        // Initial release

function Slider()
{
    this.tape = null;
    this.backButton = null;
    this.nextButton = null;
    this.limit = 4;
    this.mode = 1; // Mode:
    // 0 - Horisontal
    // 1 - Vertical
    this.movePeriod = 10;
    this.speed = 0.15;
    this.step=100; // length of one frame

    this.position = 0;
    this.targetPosition = 0;

    this.triggerMode = 1;
    // 0 - discrete
    // 1 - continuous

    this.moving = 0;

    this.direction = 0;
    this.movePeriod = 5;
    this.acceleration = 0.2;
    this.resist = 0.975;
    this.moveSpeed = 0;
    this.maxSpeed = 10;
}

Slider.prototype.setMode = function (value)
{
    this.mode = value;
}

Slider.prototype.setTriggerMode = function (value)
{
    this.triggerMode = value;
}

Slider.prototype.setLimit = function (value)
{
    this.limit = value-2;
}

Slider.prototype.setStep = function (value)
{
    this.step = value;
}

Slider.prototype.setTape = function (node)
{
    if(node !=null)
    {
        this.tape = node;
        this.setCoord(0);
        this.tape.style.width = (this.limit+2)*(this.step)+"px";
    }
    else
    {
        alert("Tape you are trying to set is null!");
    }
}

Slider.prototype.move = function()
{
    if(this.moving == 1)
    {

        //if(this.acceleration*this.direction < 0) alert(0);

        this.speed -= this.acceleration*this.direction;
        if(this.speed <= -this.maxSpeed)
        {
            this.speed = -this.maxSpeed;
        }
        else
        {
            if(this.speed >= this.maxSpeed)
            {
                this.speed = this.maxSpeed;
            }
        }
        
        this.speed *= this.resist;

        this.setCoord(this.getCoord() +this.speed);
        var sli = this;
        if(this.getCoord() < -this.getCoordLimit())
        {
            this.setCoord(-this.getCoordLimit());
            this.moving = 0;
            this.speed = 0;
        }
        else
        {
            if(this.getCoord() > 0)
            {
                this.setCoord(0);
                this.moving = 0;
                this.speed = 0;
            }
            else
            {
                setTimeout(function(){sli.move()}, this.movePeriod);
            }
        }
    }
}

Slider.prototype.setTapeById = function (id)
{
    var node = document.getElementById(id);
    if(node !=null)
    {
        this.setTape(node);
    }
    else
    {
        alert("Tape with id \""+id+"\" you are trying to set is null!");
    }
}

Slider.prototype.setBackButton = function (node)
{
    if(node !=null)
    {
        this.backButton = node;
        var slider = this;
        if(this.triggerMode)
        {
            this.backButton.onmouseover = function()
            {
                slider.direction = -1;
                if(slider.moving != 1)
                {
                    slider.moving = 1;
                    slider.move();
                }

            }
            this.backButton.onmouseout = function()
            {
                slider.direction = 0;
                if(slider.moving != 1)
                {
                    slider.moving = 1;
                    slider.move();
                }

            }
        }
        else
        {
            var bb = this.backButton;
            this.backButton.onclick = function()
            {
                slider.backSlide();
            }
            this.backButton.onmouseover = function()
            {
                bb.className = "bover";
            }
            this.backButton.onmousedown = function()
            {
                bb.className = "bpress";
            }
            this.backButton.onmouseup = function()
            {
                bb.className = "bover";
            }
            this.backButton.onmouseout = function()
            {
                bb.className = "breg";
            }
        }
    }
    else
    {
        alert("Back button you are trying to set is null!");
    }
}

Slider.prototype.setBackButtonById = function (id)
{
    node = document.getElementById(id);
    if(node !=null)
    {
        this.setBackButton(node);
    }
    else
    {
        alert("Back button with id \""+id+"\" you are trying to set is null!");
    }
}

Slider.prototype.setNextButton = function (node)
{
    if(node !=null)
    {
        this.nextButton = node;
        var slider = this;
        if(this.triggerMode)
        {
            this.nextButton.onmouseover = function()
            {
                slider.direction = 1;
                if(slider.moving != 1)
                {
                    slider.moving = 1;
                    slider.move();
                }

            }
            this.nextButton.onmouseout = function()
            {
                slider.direction = 0;
                if(slider.moving != 1)
                {
                    slider.moving = 1;
                    slider.move();
                }
                
            }
        }
        else
        {
            var nb = this.nextButton;
            this.nextButton.onclick = function()
            {
                slider.nextSlide();
            }
            this.nextButton.onmouseover = function()
            {
                nb.className = "nover";
            }
            this.nextButton.onmousedown = function()
            {
                nb.className = "npress";
            }
            this.nextButton.onmouseup = function()
            {
                nb.className = "nover";
            }
            this.nextButton.onmouseout = function()
            {
                nb.className = "nreg";
            }
        }
    }
    else
    {
        alert("Next button you are trying to set is null!");
    }
}

Slider.prototype.setNextButtonById = function (id)
{
    var node = document.getElementById(id);
    if(node !=null)
    {
        this.setNextButton(node);
    }
    else
    {
        alert("Next button with id \""+id+"\" you are trying to set is null!");
    }
}

Slider.prototype.setCoord = function(coord)
{
    if (this.tape!=null)
    {
        if (this.mode == 0)
        {
            this.tape.style.left = coord+"px";
        }
        else
        {
            this.tape.style.top = coord+"px";
        }

    }
    else
    {
        alert("Tape is null! You must set it before trying to move it!");
    }
}

Slider.prototype.getCoord = function()
{
    if (this.tape!=null)
    {
        if (this.mode == 0)
        {
            return (parseInt(this.tape.style.left));
        }
        else
        {
            return (parseInt(this.tape.style.top));
        }

    }
    else
    {
        alert("Tape is null! You must set it before trying to get it's coordinate!");
        return (null);
    }
}

Slider.prototype.getCoordLimit = function()
{
    return (this.limit*this.step);
}

Slider.prototype.nextSlide = function()
{
    if(this.targetPosition<=this.limit)
    {
        this.targetPosition++;
        this.goToSlide(this.targetPosition);
    }
    else
    {
        this.targetPosition = 0;
        this.goToSlide(this.targetPosition);
    }
}

Slider.prototype.backSlide = function()
{
    if(this.targetPosition>0)
    {
        this.targetPosition--;
        this.goToSlide(this.targetPosition);
    }
    else
    {
        this.targetPosition = this.limit+1;
        this.goToSlide(this.targetPosition);
    }
}

Slider.prototype.goToSlide = function(number)
{
    var slider = this;
    this.targetPosition = number;
    setTimeout(function(){slider.sliding()}, this.movePeriod);
}

Slider.prototype.sliding = function()
{
    direction = -this.targetPosition*this.step - this.getCoord();
    if(Math.abs(direction)<10)
    {
        this.setCoord(-this.targetPosition*this.step);
    }
    else
    {
        var slider = this;
        this.setCoord(this.getCoord() + direction*this.speed);
        setTimeout(function(){slider.sliding()}, this.movePeriod);
    }
}
