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/130059---hsv-veh-nennt-angebot-fuer-petric-aberwitzig.html" target="_blank">HSV: Veh nennt Angebot f&uuml;r Petric &quot;aberwitzig&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/130055---frankreich-blanc-verteilt-hymnen-text.html" target="_blank">Frankreich: Blanc verteilt Hymnen-Text</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/130004---ll-nr-1-expertentipp-dirk-toennies.html" target="_blank">LL NR 1: Expertentipp von Dirk T&ouml;nnies</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/130053---rwo-blog-interview-medienbeauftragten.html" target="_blank">RWO-Blog: Interview mit dem Medienbeauftragten</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/129992---bvb-spieler-sind-aller-welt-verstreut.html" target="_blank">BVB: Spieler sind in aller Welt verstreut</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/130050---aachen-herzig-muss-unters-messer.html" target="_blank">Aachen: Herzig muss unters Messer</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/129999---bl-nr-4-expertentipp-guenter-neuhaus.html" target="_blank">BL NR 4: Expertentipp von G&uuml;nter Neuhaus</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/130045---schalke-fan-anleihen-fuer-sechs-millionen-euro.html" target="_blank">Schalke: Fan-Anleihen f&uuml;r sechs Millionen Euro </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/130046---brambauer-zwei-wochen-sperre-fuer-joldic.html" target="_blank">Brambauer: Zwei Wochen Sperre f&uuml;r Joldic</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/129996---vfl-unterdeckung-einer-millionen-euro.html" target="_blank">VfL: Unterdeckung von einer Millionen Euro</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/130005---westfalia-herne-fans-schiessen-gegen-haneke.html" target="_blank">Westfalia Herne: Fans schie&szlig;en gegen Haneke</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/130043---hombruch-el-hossaini-kommt-aus-bvb-u19.html" target="_blank">Hombruch: El-Hossaini kommt aus der BVB-U19</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/129794---leverkusen-u19-brackes-aufstieg.html" target="_blank">Leverkusen U19: von der Brackes Aufstieg</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/130038---etb-ii-vier-punkte-abzug-am-gruenen-tisch.html" target="_blank">ETB II: Vier Punkte Abzug am Gr&uuml;nen Tisch</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/130012---vfl-rhede-verletzungspech-bei-daniel-beine.html" target="_blank">VfL Rhede: Verletzungspech bei Daniel Beine</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);