function Daiwai_AddEventListener(node, event, handler)
{
    if (!node.addEventListener)
    {
        node.attachEvent('on' + event, handler);
    }
    else
    {
        node.addEventListener(event, handler, false);
    }
}


function Daiwai_Newsticker_Horizontal(configObj, divNum)
{
    var tickerDiv = null;
    var innerDiv = null;
    var contentDivOne = null;
    var contentDivTwo = null;
    
    this.init = init;
    this.pause = pause;
    this.resume = resume;
    this.scroll = scroll;
    
    var width = 400;
    var height = 24;
    var textSize = 10;
    var textColor = '#000';
    var background = '#fff';
    var padding = 8;

    var pauseOnHover = true;
    var initFilled = true;
    var initPause = 1;

    var speed = 1;
    var copySpeed = 1;
    var pauseSpeed = pauseOnHover ? 0 : copySpeed;

    var contentWidth = null;
    var threshold = 0;
    
    config();
    
    var content = '<a style="white-space: nowrap; text-decoration: none; color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;" href="http://www.reviersport.de/108191---rb-salzburg-stevens-verlaengert.html" target="_blank">RB Salzburg: Stevens verl&auml;ngert</a><span  style="color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;white-space: nowrap;">&nbsp;&nbsp;+ + +&nbsp;&nbsp;</span><a style="white-space: nowrap; text-decoration: none; color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;" href="http://www.reviersport.de/108185---fcb-ribery-bekommt-drittes-tor-geschenkt.html" target="_blank">FCB: Ribery bekommt drittes Tor &quot;geschenkt&quot;</a><span  style="color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;white-space: nowrap;">&nbsp;&nbsp;+ + +&nbsp;&nbsp;</span><a style="white-space: nowrap; text-decoration: none; color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;" href="http://www.reviersport.de/108188---fck-stadt-entlastet-weniger-erhofft.html" target="_blank">FCK: Stadt entlastet weniger als erhofft</a><span  style="color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;white-space: nowrap;">&nbsp;&nbsp;+ + +&nbsp;&nbsp;</span><a style="white-space: nowrap; text-decoration: none; color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;" href="http://www.reviersport.de/108189---rw-ahlen-lebenszeichen-abstiegskampf.html" target="_blank">RW Ahlen: Lebenszeichen im Abstiegskampf</a><span  style="color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;white-space: nowrap;">&nbsp;&nbsp;+ + +&nbsp;&nbsp;</span><a style="white-space: nowrap; text-decoration: none; color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;" href="http://www.reviersport.de/108177---em-quali-oesterreich-will-platz-zwei.html" target="_blank">EM-Quali: &Ouml;sterreich will Platz zwei</a><span  style="color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;white-space: nowrap;">&nbsp;&nbsp;+ + +&nbsp;&nbsp;</span><a style="white-space: nowrap; text-decoration: none; color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;" href="http://www.reviersport.de/108091---msv-starke-schiebt-sonderschicht.html" target="_blank">MSV: Starke schiebt eine Sonderschicht</a><span  style="color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;white-space: nowrap;">&nbsp;&nbsp;+ + +&nbsp;&nbsp;</span><a style="white-space: nowrap; text-decoration: none; color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;" href="http://www.reviersport.de/108175---bvb-fanblog-bender-verletzt-disziplin-futsch.html" target="_blank">BVB-Fanblog: Bender verletzt, Disziplin futsch</a><span  style="color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;white-space: nowrap;">&nbsp;&nbsp;+ + +&nbsp;&nbsp;</span><a style="white-space: nowrap; text-decoration: none; color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;" href="http://www.reviersport.de/108106---bochum-holtby-fuehlt-wunderland.html" target="_blank">Bochum: Holtby f&uuml;hlt sich wie im Wunderland</a><span  style="color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;white-space: nowrap;">&nbsp;&nbsp;+ + +&nbsp;&nbsp;</span><a style="white-space: nowrap; text-decoration: none; color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;" href="http://www.reviersport.de/108169---cottbus-5000-euro-geldstrafe-fuer-energie.html" target="_blank">Cottbus: 5000 Euro Geldstrafe f&uuml;r Energie</a><span  style="color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;white-space: nowrap;">&nbsp;&nbsp;+ + +&nbsp;&nbsp;</span><a style="white-space: nowrap; text-decoration: none; color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;" href="http://www.reviersport.de/108167---regionnalliga-vfl-trennt-1-1-goslar.html" target="_blank">Regionnalliga: VfL trennt sich 1:1 von Goslar</a><span  style="color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;white-space: nowrap;">&nbsp;&nbsp;+ + +&nbsp;&nbsp;</span><a style="white-space: nowrap; text-decoration: none; color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;" href="http://www.reviersport.de/108164---fortuna-jovanovic-muss-pausieren.html" target="_blank">Fortuna: Jovanovic muss pausieren</a><span  style="color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;white-space: nowrap;">&nbsp;&nbsp;+ + +&nbsp;&nbsp;</span><a style="white-space: nowrap; text-decoration: none; color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;" href="http://www.reviersport.de/108161---polizisten-tod-lange-haftstrafe-gefordert.html" target="_blank">Polizisten-Tod: Lange Haftstrafe gefordert</a><span  style="color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;white-space: nowrap;">&nbsp;&nbsp;+ + +&nbsp;&nbsp;</span><a style="white-space: nowrap; text-decoration: none; color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;" href="http://www.reviersport.de/108149---em-quali-pressestimmen-zur-auslosung.html" target="_blank">EM-Quali: Pressestimmen zur Auslosung</a><span  style="color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;white-space: nowrap;">&nbsp;&nbsp;+ + +&nbsp;&nbsp;</span><a style="white-space: nowrap; text-decoration: none; color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;" href="http://www.reviersport.de/108153---offenbach-trainer-menze-muss-gehen.html" target="_blank">Offenbach: Trainer Menze muss gehen</a><span  style="color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;white-space: nowrap;">&nbsp;&nbsp;+ + +&nbsp;&nbsp;</span><a style="white-space: nowrap; text-decoration: none; color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;" href="http://www.reviersport.de/108099---f95-ii-zahlreiche-probleme-vor-start.html" target="_blank">F95 II: Zahlreiche Probleme vor dem Start</a><span  style="color: ' + textColor + '; font-size:' + textSize + 'px; font-weight: bold;white-space: nowrap;">&nbsp;&nbsp;+ + +&nbsp;&nbsp;</span>';
    
    if(window.rs_inst_load && rs_inst_load == true)
    {
        init();
    }
    else
    {
        Daiwai_AddEventListener(window, 'load', init);
    }

    function init()
    {
        tickerDiv = document.createElement('div');
        tickerDiv.style.position = 'relative';
        tickerDiv.style.background = background;
        tickerDiv.style.padding = '0px';
        tickerDiv.style.width = width + 'px';
        tickerDiv.style.height = height + 'px';
        tickerDiv.style.overflow = 'hidden';
        
        var itop = Math.floor((height / 2) - (textSize * 0.6)) - 1;

        innerDiv = document.createElement('div');
        innerDiv.style.position = 'absolute';
        innerDiv.style.width = width + 'px';
        //innerDiv.style.height = height + 'px';
        innerDiv.style.top = itop + 'px';
        

        contentDivOne = document.createElement('div');
        contentDivOne.style.position = 'absolute';
        contentDivOne.style.whiteSpace = 'nowrap';
        contentDivOne.style.left = '0px';
        contentDivOne.style.top = '0px';
        contentDivOne.style.display = 'inline';
        contentDivTwo = contentDivOne.cloneNode(false);
        
        var initOffset = (initFilled == 1) ? '8px' : parseInt(width) + 8 + 'px';
        contentDivOne.style.left = initOffset;
        contentDivOne.innerHTML = contentDivTwo.innerHTML = content;

        
        innerDiv.appendChild(contentDivOne);
        innerDiv.appendChild(contentDivTwo);
        tickerDiv.appendChild(innerDiv);
        
        Daiwai_AddEventListener(innerDiv, 'mouseover', pause);
        Daiwai_AddEventListener(innerDiv, 'mouseout', resume);
        
        tmpDiv = document.getElementById('rs_horizontal_ticker_' + divNum);
        tmpDiv.parentNode.insertBefore(tickerDiv, tmpDiv);
        
        contentWidth = contentDivOne.offsetWidth;
        contentHeight = contentDivOne.offsetHeight;
        //alert(contentHeight);
        threshold = (contentWidth * -1) + 8;
        contentDivTwo.style.left = (parseInt(contentDivOne.style.left) + contentWidth + 8) + 'px';

        //setInterval(scroll, 30);//, rs_ticker_init_pause * 1000);
        setTimeout(scrollHelper, initPause * 1000);
    }
    
    function scrollHelper()
    {
        setInterval(scroll, 100);        
    }

    function config()
    {
        //var cfg = baseElement.innerHTML.split('|');
        textColor = configObj.textColor || '#000';
        background = configObj.backgroundColor || '#fff';
        width = parseInt(configObj.width || 400);
        height = parseInt(configObj.height || 25);
        textSize = parseInt(configObj.textSize || 12);
        speed = parseInt(configObj.speed || 1);
        
        if(speed > 10)
        {
            speed = 10;
        }
        else if(speed < 1)
        {
            speed = 1;
        }
        copySpeed = speed;
        pauseSpeed = pauseOnHover ? 0 : copySpeed;
    }
    
    function pause()
    {
        copySpeed = pauseSpeed;
    }
    
    function resume()
    {
        copySpeed = speed;
    }
    
    function scroll()
    {
        if(parseInt(contentDivOne.style.left) < threshold)
        {
            contentDivOne.style.left = (parseInt(contentDivTwo.style.left) + contentWidth + 8) + 'px';
        }
        if(parseInt(contentDivTwo.style.left) < threshold)
        {
            contentDivTwo.style.left = (parseInt(contentDivOne.style.left) + contentWidth + 8) + 'px';
        }
        contentDivTwo.style.left = parseInt(contentDivTwo.style.left) - copySpeed + 'px';
        contentDivOne.style.left = parseInt(contentDivOne.style.left) - copySpeed + 'px';
    }    
}

function makeHorizontalNewsticker(config, i)
{
    if(i == null)
    {
        var i = 0;
        while(document.getElementById('rs_horizontal_ticker_' + i) != null)
        {
            i++;
        }
        div = '<div id="rs_horizontal_ticker_'+ i + '"></div>';
        document.write(div);
    }

    rs_horizontal_tickers[i] = new Daiwai_Newsticker_Horizontal(config, i);
}

if(!document.rs_horizontal_tickers)
{
    var rs_horizontal_tickers = new Array;
}
if(!window.tNum)
{
    tNum = null;
}
if(!window.tickerConfig)
{
    var tickerConfig = {key: 'val'}; 
}

makeHorizontalNewsticker(tickerConfig, tNum);