/*
*	This code was found by Sourceforge.net
*
*
*/
var propaganda_WIDTH = 810; //px of first relative div
var propaganda_GOTONEXTMSG_RANGOFTOLERANCEINPX = 80; 
var propagandaMSG_LWIDTH = 0; //the length of the msg in px
var propagandaMSG_CURLWIDTH = propaganda_WIDTH; //the current width of second div
var propaganda_SCROLL_TOWIDTH = 810; //max. left scroll value
var P_PAUSE = false;
var P_STOP = false; 
var propaganda_PLANTS_LEN = 0;
var propaganda_PLANTS_TAG = '';
var propaganda_MSG_CTR = new Array(); // 2D Array [n][0] -> msg string [n][1] -> length of msg in html 
var propaganda_MSG_NUM = 0;
var propaganda_MSG_STR = ""; 

function propa_load()
{
    if( PROPSHOW )prop_start();
}

function prop_start()
{
    if( document.getElementById( "tempprop" ).innerHTML == "" )return ;
    propaganda_PLANTS_TAG = ' <img style="vertical-align: middle;" src="'+ gfx_pfad + 'ball.gif" width="20px" height="20px" /> ';
    propaganda_MSG_TMPCTR = document.getElementById( "tempprop" ).innerHTML.split( "|" );

    // get length of the messages
    propaganda_MSG_NUM = propaganda_MSG_TMPCTR.length;

    for( i = 0; i < propaganda_MSG_NUM; i ++ )
    {
        propaganda_MSG_CTR[i] = new Array();
        propaganda_MSG_CTR[i][0] = document.getElementById( "tempprop" ).innerHTML = propaganda_MSG_TMPCTR[i];
        propaganda_MSG_CTR[i][1] = parseInt( document.getElementById( "tempprop" ).offsetWidth ); 
        propaganda_MSG_STR += propaganda_PLANTS_TAG + propaganda_MSG_CTR[i][0];   

        propagandaMSG_LWIDTH += propaganda_MSG_CTR[i][1];
    }

    propaganda_MSG_STR += propaganda_PLANTS_TAG;
    
    //get length of plants
    document.getElementById( "tempprop" ).innerHTML = propaganda_PLANTS_TAG;
    propaganda_PLANTS_LEN = parseInt( document.getElementById( "tempprop" ).offsetWidth );
    document.getElementById( "tempprop" ).innerHTML = '';

    propagandaMSG_LWIDTH += ( ( propaganda_MSG_NUM + 1 ) * propaganda_PLANTS_LEN ); 
    
    //set to default runtime values
    document.getElementById( "tempprop" ).style.left = "0px";
    document.getElementById( "tempprop" ).style.top = "0px";

    document.getElementById( "letterbox" ).style.left = propaganda_WIDTH + "px";
    //set courier ctr
    document.getElementById( "letterbox" ).innerHTML = "<nobr>" + propaganda_MSG_STR + "</nobr>";

    propaganda_SCROLL_TOWIDTH = ( propagandaMSG_LWIDTH * - 1 );
    document.getElementById( "letterbox" ).style.visibility = "visible";

    pst();
}

function pst()
{
    if( P_STOP )return ;
    if( !P_PAUSE )
    {
        if( propagandaMSG_CURLWIDTH <= propaganda_SCROLL_TOWIDTH )
        {
            document.getElementById( "letterbox" ).style.left = propaganda_WIDTH + "px";
            propagandaMSG_CURLWIDTH = propaganda_WIDTH;
        }
        document.getElementById( "letterbox" ).style.left = propagandaMSG_CURLWIDTH + "px";
        propagandaMSG_CURLWIDTH -= SCROLLPX;
    }
    setTimeout( "pst()", 40 );   
}

function next_msg()
{
    /* get the current range of showed len in box of msgstr. */
    curlenpx = propagandaMSG_CURLWIDTH - propaganda_WIDTH;
    
    if( curlenpx < 0 )curlenpx *= -1;
    
    /* get not showed msg now */
    lenpx = 0;

    for( i = 0; i < propaganda_MSG_NUM; i ++ )
    {
        len = propaganda_PLANTS_LEN + propaganda_MSG_CTR[i][1];
        if( lenpx + len >= curlenpx )
        {
            if( curlenpx - lenpx <= propaganda_GOTONEXTMSG_RANGOFTOLERANCEINPX )
            {
                break;
            }
            /* taller or equal -> next msg is the msg we want to jump to */
            lenpx += len;
            i ++; 
            break;
        }
         lenpx += len;
    }

    if( i == propaganda_MSG_NUM )
    {
        /* we reached the end, so goto first msg */
        propagandaMSG_CURLWIDTH = 0;
        document.getElementById( "letterbox" ).style.left = "0px";
    }else
    {
        lenpx *= -1;
        propagandaMSG_CURLWIDTH = lenpx;
        document.getElementById( "letterbox" ).style.left = lenpx + "px";
    }
}


