/***********************************************
* Memory Scroller script- Â© Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var Scroller = function (content) {
    //propertys
    var memorywidth = "300px"
    //scroller width
    var memoryheight = "28px"
    //scroller height
    var memorybgcolor = "transparent"
    //scroller background
    var memorypadding = "2px"
    //padding applied to the scroller. 0 for non.
    var borderCSS = "none;"
    //Border CSS, applied to scroller to give border.
    var memorycolor="white";

    var memoryspeed = 2
    //Scroller speed (larger is faster 1-10)
    var pauseit = 1
    //Pause scroller onMousever (0=no. 1=yes)?

    var persistlastviewedmsg = 1
    //should scroller's position persist after users navigate away (1=yes, 0=no)?
    var persistmsgbehavior = "onload"
    //set to "onload" or "onclick".

    //Specify the scroller's content (don't delete <nobr> tag)
    //Keep all content on ONE line, and backslash any single quotations (ie: that\'s great):

    memorycontent = 'Inhalt';
    var divonclick = (persistlastviewedmsg && persistmsgbehavior == "onclick") ? 'onClick="savelastmsg()" ' : ''
    memoryspeed = (document.all) ? memoryspeed : Math.max(1, memoryspeed - 1)//slow speed down by 1 for NS
    var copyspeed = memoryspeed
    var pausespeed = (pauseit == 0) ? copyspeed : 0
    var iedom = document.all || document.getElementById
    var actualwidth = '';
    var memoryscroller;
    //geter und setter
    this.setContent = function (content) { memorycontent = content; }
    this.setWidth = function (width) { memorywidth = width; }
    this.setHeight = function (height) { memoryheight = height; }
    this.setBG=function(bg){memorybgcolor=bg;}
    this.setColor=function(color){memorycolor=color;}
    this.srcollMemory = function (width, height, bgColor, padding, border, speed, pause, persistlast, persistmsg) {
        memorycontent = '<span style="font: bold 13px Verdana">' + memorycontent + '</span>';
        if (width != null) {
            memorywidth = width;
        }
        if (height != null) {
            memoryheight = height;
        }
        if (bgColor != null) {
            memorybgcolor = bgColor;
        }
        if (padding != null) {
            memorypadding = padding;
        }
        if (border != null) {
            borderCSS = border;
        }
        if (speed != null) {
            memoryspeed = speed;
        }
        if (pause != null) {
            pauseit = pause;
        }
        if (persistlast != null) {
            persistlastviewedmsg = persistlast;
        }
        if (persistmsg != null) {
            persistmsgbehavior = persistmsg;
        }
        if (iedom)
            document.write('<span id="temp" style="visibility:hidden;position:absolute;top:-100px;left:-10000px">' + memorycontent + '</span>')
        ////NO NEED TO EDIT BELOW THIS LINE////////////
        combinedcssTable = "width:" + (parseInt(memorywidth) + 6) + "px;background-color:" + memorybgcolor + ";color:" + memorycolor + ";padding:" + memorypadding + ";" + borderCSS + ";"
        combinedcss = "width:" + memorywidth + ";height:" + memoryheight + ";"

        if (window.addEventListener)
            window.addEventListener("load", populatescroller, false)
        else if (window.attachEvent)
            window.attachEvent("onload", populatescroller)
        else if (document.all || document.getElementById)
            window.onload = populatescroller
        if (persistlastviewedmsg && persistmsgbehavior == "onload")
            window.onunload = savelastmsg
        if (iedom) {
            with (document) {
                document.write('<table border="0" cellspacing="0" cellpadding="0" style="' + combinedcssTable + '"><td>')
                write('<div style="position:relative;overflow:hidden;' + combinedcss + '" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=memoryspeed">')
                write('<div id="memoryscroller" style="position:absolute;left:0px;top:0px;" ' + divonclick + '></div>')
                write('</div>')
                document.write('</td></table>')
            }
        }
    }

    function populatescroller() {
        memoryscroller = document.getElementById ? document.getElementById("memoryscroller") : document.all.memoryscroller
        memoryscroller.style.left = parseInt(memorywidth) + 8 + "px";
        if (persistlastviewedmsg && get_cookie("lastscrollerpos") != "")
            revivelastmsg();
        memoryscroller.innerHTML = memorycontent;
        actualwidth = document.all ? temp.offsetWidth : document.getElementById("temp").offsetWidth;
    }

    function get_cookie(Name) {
        var search = Name + "="
        var returnvalue = ""
        if (document.cookie.length > 0) {
            offset = document.cookie.indexOf(search)
            if (offset != -1) {
                offset += search.length
                end = document.cookie.indexOf(";", offset)
                if (end == -1)
                    end = document.cookie.length;
                returnvalue = unescape(document.cookie.substring(offset, end))
            }
        }
        return returnvalue;
    }

    function savelastmsg() {
        document.cookie = "lastscrollerpos=" + memoryscroller.style.left
    }

    function revivelastmsg() {
        lastscrollerpos = parseInt(get_cookie("lastscrollerpos"))
        memoryscroller.style.left = parseInt(lastscrollerpos) + "px"
    }

    this.scrollmarquee = function () {
        // alert("scroller2");
       if(memoryscroller!=null)
        if (parseInt(memoryscroller.style.left) > (actualwidth * (-1) + 8))
            memoryscroller.style.left = parseInt(memoryscroller.style.left) - copyspeed + "px"
        else
            memoryscroller.style.left = parseInt(memorywidth) + 8 + "px"
    }
}
