﻿Core.MarqueeBar=function(config){
    this.dom=Core.$(config.id);
    this.speed=config.speed?config.speed:30;
    this.direct=config.direct;
    this.step=config.step?config.step:1;
    var thread=null;
    this.offset=null;
    var threadFun=function(){
           if(this.direct=='v'){
                if(this.offset-this.dom.scrollTop<=0){
                    this.dom.scrollTop=0;
                }
                else
                    this.dom.scrollTop+=this.step;
           }
           else if(this.direct=='h'){
                if(this.offset-this.dom.scrollLeft<=0){
                    this.dom.scrollLeft=0;
                }
                else
                    this.dom.scrollLeft+=this.step;
           }
    }.bind(this);
    
    var onmouseover=function(){
        if(thread!=null){
            clearInterval(thread);
        }
    }.bind();
    
    var onmouseout=function(){
        thread=setInterval(threadFun,this.speed);
    }.bind(this);
    
    with(Core){
        domEventManager.addEvent(this.dom,"mouseover",onmouseover);
        domEventManager.addEvent(this.dom,"mouseout",onmouseout);
    };
    
    this.start=function(){
        if(this.direct=='v'){
            this.offset=this.dom.getElementsByTagName("table")[0].offsetHeight;
            var html="<table><tr><td>"+this.dom.innerHTML+"</td></tr><tr><td>"+this.dom.innerHTML+"</td></tr></table>";
            this.dom.innerHTML=html;
        }
        else if(this.direct=='h'){
            this.offset=this.dom.getElementsByTagName("table")[0].offsetWidth;
            var html="<table><tr><td>"+this.dom.innerHTML+"</td><td>"+this.dom.innerHTML+"</td></tr></table>";
            this.dom.innerHTML=html;
        }
        thread=setInterval(threadFun,30);
    };
};