﻿var iIndex = 0;
            
function changeTTB(direction) {
    var iNext = iIndex + direction;
    if ( iNext < 0 )
        iNext = iCount - 1;
    else if ( iNext >= iCount )
        iNext = 0;
    
    if ( iNext > iIndex )
        scrollRight( document.getElementById("dvTTBox").scrollLeft, iNext * 199, 1000 );
    else
        scrollRight( document.getElementById("dvTTBox").scrollLeft, iNext * 199, 1000 );
        
    iIndex = iNext;
}

function scrollRight( startLoc, endLoc, duration ) {
    var diff = endLoc - startLoc;
    
    duration = duration / 100;
    
    scroll(endLoc, Math.round(diff/duration));
}

function scrollLeft( startLoc, endLoc, duration ) {
    var diff = endLoc - startLoc;
    
    duration = duration / 100;
    
    scroll(endLoc, Math.round(diff/duration) * -1);
}

function scroll( endLoc, movement ) {
    document.getElementById("dvTTBox").scrollLeft += movement; 
    
    if ( movement > 0 ) {
        if ( document.getElementById("dvTTBox").scrollLeft + movement < endLoc ) {
            setTimeout("scroll(" + endLoc + "," + movement + ");",20);
        } else {
            document.getElementById("dvTTBox").scrollLeft = endLoc;
        }
    } else {
        if ( document.getElementById("dvTTBox").scrollLeft + movement > endLoc ) {
            setTimeout("scroll(" + endLoc + "," + movement + ");",20);
        } else {
            document.getElementById("dvTTBox").scrollLeft = endLoc;
        }
    }
}