/*************************************************************************/
/*首页滚动
/*2008.9.23
/*************************************************************************/
function ScrollObj(obj,objName,msgScrollDelay,msgScreenDelay,lines,cTagName)
{
    this.target = $P(obj);
    this.objStr = objName; 
    //子元素标签名
    this.cTagName = cTagName;
    this.target.style.overflow = "hidden";   
    
    this.msgMinIndex = 0;
    this.msgCnt = this.target.getElementsByTagName(this.cTagName).length; 
    this.lines = lines;
    this.msgMaxIndex = Math.floor(this.msgCnt/this.lines) - 1;
    this.msgIndex = this.msgMinIndex - 1; 
    //计算单条记录的高度
    var odl = this.target.getElementsByTagName(this.cTagName)[0];   
    var oStyle = null;
    if(odl)
    {
    if(window.getComputedStyle) {  oStyle = window.getComputedStyle(odl,"");   }
    else {  oStyle = odl.currentStyle;  }   
    this.msgItemHeight = odl.offsetHeight+ (isNaN(parseInt(oStyle.marginTop))?0:parseInt(oStyle.marginTop))+ (isNaN(parseInt(oStyle.marginBottom))?0:parseInt(oStyle.marginBottom));
    }
    else{this.msgItemHeight=0;}  
    this.msgScrollDelay = msgScrollDelay; //滚动延迟时间
    this.msgScreenDelay = msgScreenDelay; //一屏延迟时间
    var inst = this;
    inst.CloneMsgData();  
    this.target.onmouseover = function(){inst.Suspended();};
    this.target.onmouseout = function(){inst.Resume();};   
    this.timer = null;  
}

ScrollObj.prototype.CloneMsgData = function()
{   
    if(this.msgCnt*this.msgItemHeight<parseInt(this.target.style.height)) return; 
    var msgData = this.target.getElementsByTagName(this.cTagName);
    for(i=0;i<this.msgCnt;i++)
    {
        this.target.appendChild(msgData[i].cloneNode(true));
    }    
}

ScrollObj.prototype.ShowContentUp=function()
{   
     if (this.msgIndex > this.msgMaxIndex)
    {       
        //一个周期已经滚完，从头再开始
        this.msgIndex = 0;
        this.target.scrollTop = 0;
    }

    if (this.target.scrollTop < (this.msgIndex+1)*this.msgItemHeight*this.lines)
    {
        //一屏(滚动条数为单位)还没有滚到头
        this.target.scrollTop++;       
        this.timer = setTimeout(this.objStr+".ShowContentUp();", this.msgScrollDelay);
    }
    else
    {
        //一屏(滚动条数为单位)已经滚完，继续下一屏
        this.msgIndex++;
        this.timer = setTimeout(this.objStr+".ShowContentUp();", this.msgScreenDelay);
    }
}

ScrollObj.prototype.Suspended=function()
{   
    clearTimeout(this.timer);
}

ScrollObj.prototype.Resume=function()
{  
    this.ShowContentUp();
}
