var position = 0;
var elementWidth = 164;
var maxNumberElements = 21;
var numberElementsPerPage = 3;
var numberAvailableElements = 3;
var animationDuration = 0.6;
var moveEffect;
var animationInProgress = false;

function initSlider(width, maxElements, elementsPerPage, availableElements, duration) {
    elementWidth = width;
    maxNumberElements = maxElements;
    numberElementsPerPage = elementsPerPage;
    numberAvailableElements = availableElements;
    animationDuration = duration;
    //[modi:]Reset position - we might be in a newly loaded slider
    position=0;
    return false;
}

function moveToPosition(newPosition) {
    distance = (Math.abs(position - newPosition)) / numberElementsPerPage;
    position = newPosition;
    if (animationInProgress) {
        moveEffect.cancel();
    }
    if (distance > 1) {
        moveSlider(position * (-elementWidth), 0, (animationDuration * 2));
    } else {
        moveSlider(position * (-elementWidth), 0, animationDuration);
    }
    return false;
}

function moveSlider(x, y, duration) {
    animationInProgress = true;
    moveEffect = new Effect.Move("sliderPictures", {
        x: x,
        y: y,
        mode: "absolute",
        afterFinish: function() {
            animationInProgress = false;
        },
        duration: duration
    });
    return false;
}

function moveLeft() {
    tempPosition = position + numberElementsPerPage;
    if (tempPosition >= maxNumberElements) {
        tempPosition = 0;
    }
    moveToPosition(tempPosition);
    return false;
}

function moveRight() {
    if (position > 0 && !animationInProgress) {
        tempPosition = position - numberElementsPerPage;
        if (tempPosition < 0) {
            tempPosition = 0;
        }
        moveToPosition(tempPosition);
    }
    return false;
}
var animationInProgress2 = false;
var ids = new Array("inner0", "inner1", "inner2");
var count = 0;

/*function moveSliderDVs() {
    if (animationInProgress2 == false) {
        animationInProgress2 = true;
        count++;
        if (count < 3) {
            moveEffect = new Effect.Move("slider", {
                x: -305,
                y: 0,
                afterFinish: function() {
                    finish();
                },
                duration: 0.4
            });
        } else {
            if (count == 3) {
                count = 0;
                moveEffect = new Effect.Move("slider", {
                    x: 610,
                    y: 0,
                    afterFinish: function() {
                        finish();
                    },
                    duration: 0.5
                });
            }
        }
    }
}
*/
function finish() {
    animationInProgress2 = false;
}

