function next(elem){        
        do{        
            elem=elem.nextSibling;        
        }while(elem&&elem.nodeType!=1);        
        return elem;        
    }        
    //---查找第一个子元素的函数---//        
    function first(elem){        
        elem=elem.firstChild;        
        return elem && elem.nodeType!=1?next(elem):elem;        
    }    
        
    var Marquee = {    
        init: function(id, toFollow, speed){    
            this.speed = speed || 50;   //速度快慢通过修改speed的数值控制，数值越大速度越慢! 
            this.boxID = id;    
            this.toFollow = toFollow;    
            this.scrollBox = document.getElementById(id);    
                
                
            if (this.toFollow == "top" || this.toFollow == "bottom") {    
                this.appendBox = first(this.scrollBox).cloneNode(true);    
                this.scrollBox.appendChild(this.appendBox);    
            }    
            else {    
                var templateLeft = "<table cellspacing='0' cellpadding='0' style='border-collapse:collapse;display:inline;'><tr><td noWrap=true style='white-space: nowrap;word-break:keep-all;'>" + this.scrollBox.innerHTML + "</td><td noWrap=true style='white-space: nowrap;word-break:keep-all;'>" + this.scrollBox.innerHTML + "</td></tr></table>";    
                this.scrollBox.innerHTML = templateLeft;    
                this.appendBox = first(first(first(first(this.scrollBox))));    
                    
            }    
            this.objs = {    
                scrollBox: this.scrollBox,    
                appendBox: this.appendBox,    
                toFollow: this.toFollow,    
                speed: this.speed,    
                id: this.boxID    
            };    
            return this;    
        },    
            
        scroll: function(){    
            var self = this.objs;    
            self.begin = function(){    
                
                switch (self['toFollow']) {    
                    case "top":    
                        self.doScr = setInterval(function(){    
                            if (self['appendBox'].offsetHeight <= self['scrollBox'].scrollTop) {    
                                self['scrollBox'].scrollTop -= first(self['scrollBox']).offsetHeight;    
                            }    
                            else {    
                                self['scrollBox'].scrollTop++;    
                            }    
                        }, self.speed);    
                        break; 
					}       
                }    
                self.begin();    
                self.scrollBox.onmouseover = function(){    
                    clearInterval(self.doScr);    
                }    
                    
                self.scrollBox.onmouseout = function(){    
                    self.begin();    
                }    
            }    
                
        }    
        
    