
//CHANGE THIS TO CHANGE BEHAVIOUR
var firstScrollTime = 3500; //milliseconds from page load to first autoscroll
var autoScrollTime = 3500; //between scrolls (excluding animation time)
var animationTime = 1000; //how slow the animation is




var scrollTimer;
var animating = false;
var numPics = 0;
var currInd = 0;

function scroller_scroll(offset) {

    if (!animating) {

        clearTimeout(scrollTimer);
        
        var nextInd = currInd + offset;
        var wrapToFirst = false;
        var wrapToLast = false;

        if (nextInd > numPics - 1) {
            wrapToFirst = true;
            nextInd = 0;
        }

        if (nextInd < 0) {
            wrapToLast = true;
            nextInd = numPics-1;
        }

        $("#scroller_img_" + currInd).css("z-index", 10).animate({ "left": (-1000 * offset) }, animationTime + 100);
        $("#scroller_img_" + (nextInd)).css("left", (1000 * offset) + "px").css("z-index", 20).animate({ "left": 0 }, animationTime);

        currInd += offset;

        if (wrapToFirst) {
            currInd = 0;
        }

        if (wrapToLast) {
            currInd = numPics-1;
        }

        animating = true;
        setTimeout(function() { animating = false; }, animationTime);

        scrollTimer = setTimeout(function() { scroller_scroll(1); }, autoScrollTime + animationTime);
        
        
    }
}

$("document").ready(function() {
    scrollTimer = setTimeout(function() { scroller_scroll(1); }, firstScrollTime);
});
