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


function Daiwai_Newsticker_Vertical(configObj, divNum)
{
    var tickerDiv = null;
    var contentDivOne = null;
    var contentDivTwo = null;
    
    var width = 400;
    var height = 24;
    var background = '#fff';
    var textColor = '#000';
    var textSize = 12;
    
    var speed = 40000; //Delay between msg change, in miliseconds.
    var isPaused = 0;
    var currentIndex = 1; //index of message array for hidden div
    var contentOffset = 0;
    
    this.init = init;
    this.pause = pause;
    this.resume = resume;
    this.scroll = scroll;
    this.setMessage = setMessage;
    
    config();
    
    var content = new Array();content[0] = '<a style="text-decoration: none; color: ' + textColor + ';font-weight: bold;font-size: ' + textSize + 'px;" 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>';content[1] = '<a style="text-decoration: none; color: ' + textColor + ';font-weight: bold;font-size: ' + textSize + 'px;" href="http://www.reviersport.de/130053---rwo-blog-interview-medienbeauftragten.html" target="_blank">RWO-Blog: Interview mit dem Medienbeauftragten</a>';content[2] = '<a style="text-decoration: none; color: ' + textColor + ';font-weight: bold;font-size: ' + textSize + 'px;" href="http://www.reviersport.de/129992---bvb-spieler-sind-aller-welt-verstreut.html" target="_blank">BVB: Spieler sind in aller Welt verstreut</a>';content[3] = '<a style="text-decoration: none; color: ' + textColor + ';font-weight: bold;font-size: ' + textSize + 'px;" 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>';content[4] = '<a style="text-decoration: none; color: ' + textColor + ';font-weight: bold;font-size: ' + textSize + 'px;" 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>';content[5] = '<a style="text-decoration: none; color: ' + textColor + ';font-weight: bold;font-size: ' + textSize + 'px;" href="http://www.reviersport.de/130046---brambauer-zwei-wochen-sperre-fuer-joldic.html" target="_blank">Brambauer: Zwei Wochen Sperre f&uuml;r Joldic</a>';content[6] = '<a style="text-decoration: none; color: ' + textColor + ';font-weight: bold;font-size: ' + textSize + 'px;" href="http://www.reviersport.de/129996---vfl-unterdeckung-einer-millionen-euro.html" target="_blank">VfL: Unterdeckung von einer Millionen Euro</a>';content[7] = '<a style="text-decoration: none; color: ' + textColor + ';font-weight: bold;font-size: ' + textSize + 'px;" href="http://www.reviersport.de/130005---westfalia-herne-fans-schiessen-gegen-haneke.html" target="_blank">Westfalia Herne: Fans schie&szlig;en gegen Haneke</a>';content[8] = '<a style="text-decoration: none; color: ' + textColor + ';font-weight: bold;font-size: ' + textSize + 'px;" 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>';content[9] = '<a style="text-decoration: none; color: ' + textColor + ';font-weight: bold;font-size: ' + textSize + 'px;" 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>';content[10] = '<a style="text-decoration: none; color: ' + textColor + ';font-weight: bold;font-size: ' + textSize + 'px;" href="http://www.reviersport.de/130012---vfl-rhede-verletzungspech-bei-daniel-beine.html" target="_blank">VfL Rhede: Verletzungspech bei Daniel Beine</a>';content[11] = '<a style="text-decoration: none; color: ' + textColor + ';font-weight: bold;font-size: ' + textSize + 'px;" href="http://www.reviersport.de/130026---dfb-u19-laenderspiel-gegen-daenemark.html" target="_blank">DFB-U19: L&auml;nderspiel gegen D&auml;nemark</a>';content[12] = '<a style="text-decoration: none; color: ' + textColor + ';font-weight: bold;font-size: ' + textSize + 'px;" href="http://www.reviersport.de/130036---vfl-goosen-demnaechst-aufsichtsrat.html" target="_blank">VfL: Goosen demn&auml;chst im Aufsichtsrat?</a>';content[13] = '<a style="text-decoration: none; color: ' + textColor + ';font-weight: bold;font-size: ' + textSize + 'px;" href="http://www.reviersport.de/130023---rot-weiss-essen-ii-4-3-testspielsieg.html" target="_blank">Rot-Weiss Essen II: 4:3 Testspielsieg </a>';content[14] = '<a style="text-decoration: none; color: ' + textColor + ';font-weight: bold;font-size: ' + textSize + 'px;" href="http://www.reviersport.de/130011---sasic-wichtigste-waffe-liga-verstaerken.html" target="_blank">Sasic: &bdquo;Wichtigste Waffe in der Liga&ldquo; verst&auml;rken</a>';if(window.rs_inst_load && rs_inst_load == true)
    {
        init();
    }
    else
    {
        Daiwai_AddEventListener(window, 'load', init);
    }

    function init()
    {
        tickerDiv = document.createElement('div');
        tickerDiv.style.marginBottom = 0;
        tickerDiv.style.marginTop = 0;
        tickerDiv.style.background = background;
        tickerDiv.style.position = 'relative';
        tickerDiv.style.overflow = 'hidden';
        tickerDiv.style.width = width + 'px';
        tickerDiv.style.height = height + 'px';
        
        contentDivOne = document.createElement('div');
        contentDivOne.style.position = 'absolute';
        contentDivOne.width = '400px';
        contentDivOne.style.whiteSpace = 'nowrap';
        
        contentDivTwo = contentDivOne.cloneNode(false);
        contentDivTwo.style.visibility = 'hidden';
        
        contentDivOne.innerHTML = content[0];
        contentDivTwo.innerHTML = content[1];
        
        tickerDiv.appendChild(contentDivOne);
        tickerDiv.appendChild(contentDivTwo);
        
        tmpDiv = document.getElementById('rs_vertical_ticker_' + divNum);
        tmpDiv.parentNode.insertBefore(tickerDiv, tmpDiv);

        contentOffset = parseInt(getCSSpadding(tickerDiv));
        //set width of inner DIVs to outer DIV's width minus padding (padding assumed to be top padding x 2)
        contentDivOne.style.width = contentDivTwo.style.width = tickerDiv.offsetWidth - (contentOffset * 2) + 'px';
        
        getInline(contentDivOne, contentDivTwo);
        contentDivTwo.style.visibility = 'visible';

        Daiwai_AddEventListener(tickerDiv, 'mouseover', pause);
        Daiwai_AddEventListener(tickerDiv, 'mouseout', resume);
        
        setTimeout(scroll, speed);
    }

    function scroll()
    {
        if(parseInt(contentDivTwo.style.top) >(contentOffset + 5))
        {
            contentDivOne.style.top = parseInt(contentDivOne.style.top) - 5 + 'px';
            contentDivTwo.style.top = parseInt(contentDivTwo.style.top) - 5 + 'px';
            setTimeout(scroll, 50)
        }
        else
        {
            getInline(contentDivTwo, contentDivOne);
            swapDivs();
            setTimeout(function(){setMessage()}, speed);
        }
    }
    
    function pause()
    {
        isPaused = 1;
    }
    
    function resume()
    {
        isPaused = 0;
    }
    
    function swapDivs()
    {
        var tmpDiv = contentDivOne;
        contentDivOne = contentDivTwo;
        contentDivTwo = tmpDiv;
    }
    
    function getInline(div1, div2)
    {
        div1.style.top = contentOffset + 'px';
        div2.style.top = Math.max(div1.parentNode.offsetHeight, div1.offsetHeight) + 'px';
    }

    function setMessage()
    {
        if(isPaused==1)
        {
            //if mouse is currently over scoller, do nothing (pause it)
            setTimeout(setMessage, 100)
        }
        else
        {
            var i = currentIndex;
            var ceiling = content.length;
            currentIndex = (i + 1 > ceiling - 1) ? 0 : i + 1;
            contentDivTwo.innerHTML = content[currentIndex];
            scroll();
        }
    }


    function getCSSpadding(tickerobj)
    {
        if(tickerobj.currentStyle)
        {
            return tickerobj.currentStyle['paddingTop'];
        }
        else if(window.getComputedStyle) //if DOM2
        {
            return window.getComputedStyle(tickerobj, '').getPropertyValue('padding-top');
        }
        else
        {
            return 0;
        }
    }
    
    function config()
    {
        width = configObj.width || 400;
        height = configObj.height || 25;
        background = configObj.backgroundColor || '#fff';
        textColor = configObj.textColor || '#000';
        textSize = configObj.textSize || 14;
        
        speed = parseInt(configObj.speed) || 2;
        if(speed < 0)
        {
            speed = 1;
        }
        else if(speed > 10)
        {
            speed = 10;
        }
        speed = Math.round((10 / speed) * 1000);
    }
}


//new Daiwai_Newsticker_Vertical(name_of_message_array, CSS_ID, CSS_classname, pause_in_miliseconds)
function makeVerticalNewsticker(config, i)
{
    if(i == null)
    {
        var i = 0;
        while(document.getElementById('rs_vertical_ticker_' + i) != null)
        {
            i++;
        }
        div = '<div id="rs_vertical_ticker_'+ i + '"></div>';
        document.write(div);
    }
    rs_vertical_tickers[i] = new Daiwai_Newsticker_Vertical(config, i);
}

if(!document.rs_vertical_tickers)
{
    var rs_vertical_tickers = new Array;
}
if(!window.tNum)
{
    tNum = null;
}

if(!window.tickerConfig)
{
    var tickerConfig = {key: 'val'}; 
}


makeVerticalNewsticker(tickerConfig, tNum);