﻿var currentSlides = null;
function ClassSlides()
{
    // Settings
    this.CurrentImageIndex = 0;
    this.Position = 0;
    this.Steps = 10;
    this.ImageWindowSize = 7;
    this.Timeout = false;
    this.DoubleClickUrl = '';
    this.ImageWidth = 126;

    this.DoStep = function(step)
    {
        if (this.To == this.Position)
            return;

        step++;
        currentSlides = this;
        this.mElement.style.left = '-' + (this.Factor(step / this.Steps) * (this.To - this.Position) + this.Position) + 'px';
        if (this.Timeout)
            clearTimeout(this.Timeout);
        if (step < this.Steps)
            this.Timeout = setTimeout('currentSlides.DoStep(' + step + ')', 25);
        else
            this.Position = this.To;
    }

    this.ToLeft = function()
    {
        this.CurrentImageIndex = this.CurrentImageIndex - 1;
        if (this.CurrentImageIndex < 0) this.CurrentImageIndex = 0;
        this.To = this.CurrentImageIndex * this.ImageWidth;
        this.DoStep(0);
        return false;
    }

    this.ToRight = function()
    {
        this.CurrentImageIndex = this.CurrentImageIndex + 1;
        if (this.CurrentImageIndex > this.Images.length - this.ImageWindowSize)
            this.CurrentImageIndex = this.Images.length - this.ImageWindowSize;

        this.To = this.CurrentImageIndex * this.ImageWidth;
        this.DoStep(0);
        return false;
    }

    this.Factor = function(f)
    {
        return 0.5 - Math.cos(f * Math.PI) * 0.5;
    }

    // Initialize
    this.Initialize = function(element)
    {
        this.mElement = element;
        this.Images = element.getElementsByTagName('A');
        if (this.ImageWindowSize > this.Images.length)
            this.ImageWindowSize = this.Images.length;

        this.mElement.style.width = (this.Images.length * this.ImageWidth + 10) + 'px';
    }
}
