// Browser constants
var B_OTHER   = 0;
var B_MOZILLA = 1;
var B_MSIE    = 2;
var B_NS4     = 3;

// Platform constants
var P_WIN32   = 0;
var P_MAC     = 1;
var P_LINUX   = 0;
var P_OTHER   = 0;

// Adjustable parameters for configuration
// of the scroller
var LINK_WAIT = 40;
var WIDTH     = 690;

// Internal variables
var linkFeed = new Array();
linkFeed[0] = new Array( '', '' );
var linkFeedLength = 1;
var lineLength;
var dt = 0;
var bIndex = 0;
var browserType = browserCheck();
var linkCounter;
var target = '';
var classid = '';
var path = new Array(90);
var point = false;
var x = WIDTH;
var x2 = WIDTH + WIDTH;
var steps = WIDTH;
var steps2 = WIDTH;
var initCalled = 0;

// Method for adding a text ( + link ) to the scroller.
function addLink( url, title ) {
	if ( initCalled == 0 ) {
        linkFeed[linkFeedLength] = new Array( url, title );
        linkFeedLength++;
    } else {
        // You are not allowed to add a link
        // after that the scroller is initialized
    }
} // addLink


// Initialize needed variables, and start scroller
function init( link ) {
    initCalled = 1;
    lineLength = new Array( linkFeedLength );
    for ( i = 0; i < linkFeedLength; i++ ) {
        lineLength[i] = linkFeed[i][1].length * 10;
    }
    precalcPath();
    linkCounter = link;
    setLink();
    scroller();
} // init


// Precalculate numbers for the 'brake' effect.
function precalcPath() {
    var v = 0;
    for ( i = 0; i < 90; i++ ) {
        v = ( ( i + 180 ) / 180 ) * Math.PI;
        path[i] = Math.sin( v );
    }
} // precalcPath


// Move the two text layers to the new coordinates.
function moveLayers() {
    if (browserType == B_MOZILLA) {
        document.getElementById( "linkscroller" ).style.left=x+'px';
        document.getElementById( "linkscroller2" ).style.left=x2+'px';
    } else if (browserType == B_NS4) {
        document.linkscroller.left = x+'px';
        document.linkscroller2.left = x2+'px';
    } else {
        document.all.linkscroller.style.left = x+'px';
        document.all.linkscroller2.style.left = x2+'px';
    }
} // moveLayers


// Calculate new scroller coordinates, and call the delay
// method.
function scroller() {
    moveLayers();
    if ( point == false ) {
        if ( steps2 > 34 ) {
            x--;
            x2--;
            steps--;
            steps2--;
        } else {
            x = x - 1 - path[bIndex];
            x2= x2 - 1 - path[bIndex];
            steps= steps - 1 - path[bIndex];
            steps2= steps2 - 1 - path[bIndex];
            bIndex++;
            if ( bIndex > 89 ) {
                bIndex = 0;
            }
        }
    }
    if ( steps < 1 ) {
        setLink();
        steps = WIDTH;
    }
    var t = setTimeout( "scroller()", 10 );
    if ( steps2 < 1 ) {
        clearTimeout(t);
        delay();
    }
} // scroller


// Method for stopping the scroller each time a text line
// has reached the start of the scroller window.
function delay() {
    dt++;
    var t2 = setTimeout( "delay()", 10 );
    if(dt > ( LINK_WAIT * 7 ) ) {
        clearTimeout( t2 );
        dt = 0;
        steps2 = WIDTH;
        bIndex = 0;
        scroller();
    }
} // delay


// Insert text into the text layers
function setLink() {
    var output = '<A onMouseOver="javascript:point=true;" '
        + 'onMouseOut="javascript:point=false;" '
        + 'target="_top" '
        + 'href="' + linkFeed[linkCounter][0] + '">' + linkFeed[linkCounter][1] + '</A>';

    var output2 = '<A onMouseOver="javascript:point=true;" '
        + 'onMouseOut="javascript:point=false;" '
        + 'target="_top" '
        + 'href="' + linkFeed[linkCounter+1][0] + '">' + linkFeed[linkCounter+1][1] + '</A>';

    if ( browserType == B_MOZILLA ) {
        document.getElementById( "linkscroller" ).innerHTML=output;
    } else if ( browserType == B_NS4 ) {
        t = setTimeout( "replaceNS4('" + output + "', 'linkscroller')", 0 );
    } else if ( browserType == B_MSIE ) {
        document.all.linkscroller.innerHTML='<NOBR>' + output + '</NOBR>';
    } else {
        document.all.linkscroller.innerHTML = output;
    }

    x = 0;
    x2 = WIDTH;
    moveLayers();

    if ( browserType == B_MOZILLA ) {
        document.getElementById( "linkscroller2" ).innerHTML = output2;
    } else if ( browserType == B_NS4 ) {
        t = setTimeout( "replaceNS4('" + output2 + "', 'linkscroller2')", 0 );
    } else if ( browserType == B_MSIE ) {
        document.all.linkscroller2.innerHTML='<NOBR>' + output2 + '</NOBR>';
    } else {
        document.all.linkscroller2.innerHTML = output2;
    }

    linkCounter++;

    if ( linkCounter == linkFeedLength - 1 ) {
        linkFeed[0][0] = linkFeed[linkFeedLength - 1][0];
        linkFeed[0][1] = linkFeed[linkFeedLength - 1][1];
        linkCounter = 0;
    }
} // setLink


// Special method for dealing with layers in Netscape 4 versions
function replaceNS4( str, layer ) {
   document.layer.document.open();
   document.layer.document.write( str );
   document.layer.document.close();
} // replaceNS4

