/***************************
* scroll.js
* scrolls blocked text to the left
* Styles to be set in block (ex): position: absolute; left: 170px
* Example: see daily/misc/hegnar_ticker.jsp
***************************/

var scroll;

function scrollit(scrollId,nudge,delay,lSize) {
// scollId - id of block to be scrolled
// nudge - the number of pixels to move per iteration (optional)
// delay - the number of miliseconds to delay each iteration (optional)
// lSize - number of pixels per letter (optional)

    scroll=true;
    str = document.getElementById(scrollId).innerText;
    try {   //calculates the number of letters in block
        str = str.replace(/\n/g,"");
        str = str.replace(/\t/g,"");
        str = str.replace(/\s+/g," ");
        len = str.length;
    }
    catch(e) {  // workaround for Firefox who can't read innerText
        len=250;
    }
    if(nudge == null)
        nudge = 1;
    if(delay == null)
        delay = 40;
    if(lSize == null)
        lSize = 7;
    strWidth = len * lSize;  // calculates block width
    block = document.getElementById(scrollId).style;
    if ((document.layers) ? 1 : 0) {
        block = document.getElementById(scrollId);
    }
    initLeft = parseInt(block.left);  // starting left position of block
    block.width = parseInt(strWidth);
    block.lpos = parseInt(block.left);
    slideLeft(nudge,delay);
}


function slideLeft(nudge,delay) {
    if (scroll){
        if (block.lpos > -strWidth){
            block.lpos -= nudge;
            block.left = block.lpos;
            setTimeout("slideLeft("+nudge+","+delay+")", delay);
        }else{
            block.lpos = initLeft;
            block.left = block.lpos;
            setTimeout("slideLeft("+nudge+","+delay+")", delay);
        }
    }
}

function stopScroll(){
    scroll=false;
}

function startScroll(nudge,delay){
    scroll=true;
    setTimeout("slideLeft("+nudge+","+delay+")", delay);
}

