var marquee = {
    bindClass : 'marquee',
    count : 0,
    iedom : document.all || document.getElementById,
    
    
    install : function(){
        //marquee.addEvent(window, 'load', jscolor.init);
        if(window.addEventListener) {
            window.addEventListener('load', marquee.bind, false);
        } else if(window.attachEvent) {
            window.attachEvent('onload', 'bind');
        }
    },

    bind : function(){
        var matchClass = new RegExp('(^|\\s)('+marquee.bindClass+')\\s*(\\{[^}]*\\})?', 'i');
        var e = document.getElementsByTagName('div');
        
        for(var i=0; i<e.length; i++) {
            var m;
            if(!e[i].color && e[i].className && (m = e[i].className.match(matchClass))) {
                var prop = {};
                if(m[3]) {
                    try {
                        eval('prop='+m[3]);
                    } catch(eInvalidProp) {}
                }
                e[i].propertiesEle = new marquee.setup(e[i], prop);
            }
        }
    },

    setup : function(target, prop){
        this.target = target;
        this.speed = 2;
        this.onmouse = true;
        this.content = this.target.childNodes[0].nodeValue;
        //marquee.marqueewidth = marquee.iedom ? marquee.target.offsetWidth : ;
        for(var p in prop) {
            if(prop.hasOwnProperty(p)) {
                this[p] = prop[p];
            }
        }
        if(typeof(this.speed) == 'number') this.speed = (document.all) ? this.speed : Math.max(1, this.speed-1);
        else this.speed = 2;
        this.copySpeed = this.speed;
        this.pauseSpeed = this.onmouse == false ? this.speed : 0;

        
  
        this.dis = "iemarquee" + marquee.count;
        this.disT = 'temp' + marquee.count;
        
        if(marquee.iedom) this.target.innerHTML = '<span id="' + this.disT + '" style="visibility:hidden;position:absolute;top:-100px;left:-9000px">' + this.content + '</span>';
        if(this.hasOwnProperty("width")) this.target.style.width = this.width;
        if(this.hasOwnProperty("height")) this.target.style.height = this.height;
        this.target.style.overflow = 'hidden';

        this.target.innerHTML += '<div id="' + this.dis + '" style="position:relative;left:' + (parseInt(this.target.offsetWidth) + 8) +'px;">' + this.content + '</div>';

        this.marqueeA = document.getElementById(this.dis).style.left;
        this.actualwidth = document.getElementById(this.disT).offsetWidth;
        this.marW = parseInt(this.target.offsetWidth) + 8;

        
        lefttime=setInterval("marquee.scrollmarquee('" + this.dis + "'," + this.actualwidth + "," + this.speed +"," + this.marW + ")", 20);
    },

    scrollmarquee : function(cross_marqueea, actualwidth, speed, marqueewidth){
        //alert(cross_marquee);
        cross_marquee = document.getElementById(cross_marqueea);
        //alert(parseInt(cross_marquee.style.left)- speed);
        if (parseInt(cross_marquee.style.left)>(actualwidth*(-1)+8))
            cross_marquee.style.left = (parseInt(cross_marquee.style.left) - speed) + "px"
        else
            cross_marquee.style.left = parseInt(marqueewidth)+"px"
    }
}

marquee.install();
