﻿var currentBox = 0;
var moving = false;
var clickRightCommand;
var clickLeftCommand;

function movingOn() {
    moving = true;
}

function movingOff() {
    moving = false;
    clearTimeout(globalSliderMoverTimer);
    globalSliderMoverTimer = setTimeout("scrollBy(ClientIDs.sliderItemsWindow, -sliderIncrement)", 10000);

}

function scrollBy(object, amount) {

    if (!moving) {
        new Effect.Move($(object), { x: amount, mode: 'relative', beforeStart: function()
        { movingOn(); }, afterFinish: function()
        { movingOff(); 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;
    }

    $(object).setStyle({ left: "-" + (itemWidth * currentBox - sliderLeftOffset) + "px" });
}


function loadImageAsync(imgSrc, imgId) {
    $(imgId).src = imgSrc;
}

// setup timer
var globalSliderMoverTimer = 0;
if (typeof (allowSlide) != 'undefined' && allowSlide) {
    Event.observe(window, "load", function() {
        globalSliderMoverTimer = setTimeout("scrollBy(ClientIDs.sliderItemsWindow, -sliderIncrement)", 10000);
    });
}
else if ($(ClientIDs.sliderItemsWindow) != null) {
    Event.observe(window, "load", function() { setToBasic(); }); 
}

function setToBasic() {
    $(ClientIDs.sliderItemsWindow).setStyle({ left: "-" + ((sliderIncrement * boxesShown) - sliderLeftOffset) + "px" });
    currentBox = boxesShown;
}
