/*
    BeginScroll(13,1,-1); 
    13 = count
    1 = speed
    -1 = direction
*/
var ScrollNo; //set on each page
var ScrollDir = 1;
var ScrollSpeed = 3;
var ScrollTime = 100;
var SCROLLSLOW = 1;
var SCROLLDEFAULT = ScrollSpeed;
var ScrollInt;
var SCROLLMAXVEL = 3;
var Properties;
var iBuffer = 5;
var iWidth = 100;

var BeginScroll = function() {
    ScrollNo = thumbs.length;
    Properties = new Array(ScrollNo-1);
    var cObj = document.getElementById('PropertiesContainer');
    if (cObj == null || cObj == undefined) { return; }
    for (var j=0; j<thumbs.length; j++) {
        var p = document.createElement("div");
        Properties[j] = p;
        p.setAttribute("id","p"+j);
        p.onmouseover = function() { ScrollSpeed = SCROLLSLOW; }
        p.onmouseout = function() { ScrollSpeed = SCROLLDEFAULT; }
        var u = URLs[j];
        p.onclick = function() { MClick(u); }
        p.style.position = 'absolute';
        p.style.top = '0px';
        p.style.left = ((j*100)+(iBuffer*j))+'px';
        var i = document.createElement("img");
        i.setAttribute("src",thumbs[j]);
        p.appendChild(i);
        cObj.appendChild(p);
        
    }
    //Trace(Properties[Properties.length-1].style.left);
    ScrollInt = window.setInterval("UpdateScroll()",ScrollTime);
}

var UpdateScroll = function() {
    for (var i=0; i<ScrollNo; i++) {

        var vel = (ScrollDir*ScrollSpeed);
        if (vel > SCROLLMAXVEL || vel < (-1*SCROLLMAXVEL)) {
            vel = SCROLLDEFAULT;
        }
        
        //var sObj = document.getElementById("p"+i);
        sObj = Properties[i];
        var leftPx = sObj.style.left;
        var left = 1*(leftPx.substr(0,leftPx.length-2));
        
        if (vel < 0) {
            sObj.style.left = ((ScrollDir*ScrollSpeed)+left) + 'px';
            if (left+iWidth < 0) { //
                //remove it
                var lastPx = Properties[Properties.length-1].style.left;
                var lastX = 1*(lastPx.substr(0,lastPx.length-2));
                var newPx = (lastX + iWidth + iBuffer)+'px';
                sObj.style.left = newPx;
                var removed = Properties.shift();
                Properties[Properties.length] = removed;
                i--;
                continue;
            }
        } else if (vel > 0) {
            sObj.style.left = ((ScrollDir*ScrollSpeed)+left) + 'px';
            //move it to the beginning
            if (left > 933) {
                //splice everything to the end
                var removed = Properties.splice(i,(Properties.length-1));
                removed.reverse();   // 10, 11, 12 -> 12, 11, 10
                for (var r = 0; r < removed.length; r++) {
                    var firtPx = Properties[0].style.left;  
                    var firstX = 1*(firtPx.substr(0,firtPx.length-2));
                    var newPx = (firstX - iWidth - iBuffer)+'px';
                    //add to front properties array
                    Properties.unshift(removed[r]);
                    //line 'em up behind existing
                    Properties[0].style.left = newPx;
                }
                break;
            }
        }
        
    }
}

var ScrollDirection = function(dir) {
    ScrollDir = dir
}

var ScrollStop = function() {
    window.clearInterval(ScrollInt);
}

var ChangeHPImage = function() {

}