﻿//var currentBox = 0;
var moving = false;
var clickRightCommand;
var clickLeftCommand;

function movingOn(buttonRight, buttonLeft) 
{
    moving = true;
    clickRightCommand = $(buttonRight).onClick;
    $(buttonRight).onClick = "";
    clickLeftCommand = $(buttonLeft).onClick;
    $(buttonLeft).onClick = "";
}

function movingOff(buttonRight, buttonLeft) 
{
    moving = false;
    $(buttonRight).onClick = clickRightCommand;
    $(buttonLeft).onClick = clickLeftCommand;

}

function scrollBy(object, amount, buttonRight, buttonLeft) 
{

    if (!moving) 
    {
        new Effect.Move($(object), { x: amount, mode: 'relative', beforeStart: function()
        { movingOn(buttonRight, buttonLeft); }, afterFinish: function()
        { movingOff(buttonRight, buttonLeft); adjustBox(object, amount); }, queue: { position: 'end', scope: 'sliders', limit: 1}
        });
    }
}

function adjustBox(object, amount) {
    currentBox += (amount < 0) ? +1 : -1;
    if (currentBox == 0) {
        currentBox = items;
    }
    if (currentBox == (items + 1)) {
        currentBox = 1;
    }
    
    //    currentBox %= items;    // forces range: 0 to (items-1)
    $(object).setStyle({ left: "-" + (itemWidth * (/*items + */currentBox)) + "px" });
}


function loadImageAsync(imgSrc, imgId) {
    $(imgId).src = imgSrc;
}
