﻿var maxa = 5; 	// Total number of cells (excluding repeating cells)
var sdur = 1000; // Scrolling animation duration
var dirc = true; // true: Normal Direction - false: Reverse Direction

var scrid = 1;
var scriv;

function scrollme() {
    var scroll = new Fx.Scroll('hasten-wrapper', {
        wait: false,
        duration: sdur,
        transition: Fx.Transitions.Quad.easeInOut
    });

    if (dirc) {
        scrid++;
        if (scrid > maxa + 1) {
            scrid = 1;
            // Setting duration to 0 for last element to first element animation, to start animation without delay while repeating //
            scroll = new Fx.Scroll('hasten-wrapper', {
                wait: false,
                duration: 0,
                transition: Fx.Transitions.Quad.easeInOut
            });
            setTimeout(scrollme, 100);
        }
        scroll.toElement('content' + scrid);
    } else {
        scrid--;
        if (scrid < 1) {
            scrid = maxa + 1;
            // Setting duration to 0 for first element to last element animation, to start animation without delay while repeating //
            scroll = new Fx.Scroll('hasten-wrapper', {
                wait: false,
                duration: 0,
                transition: Fx.Transitions.Quad.easeInOut
            });
            setTimeout(scrollme, 100);
        }
        scroll.toElement('content' + scrid);
    }
}

function frwd() {
    dirc = true;
}

function bkwd() {
    dirc = false;
}

function stp() {
    clearInterval(scriv);
}

function srt() {
    stp();
    scrollInit();
}

function scrollInit() {
    scriv = setInterval(scrollme, 4000);
}

