function ScrollText(content,btnPrevious,btnNext,autoStart)
{
    this.Items = []; 
    this.ItemsLink = []; 
    this.ItemIndex = 0; 
    this.ItemLength = 0; 
    this.IntervalID = 0; 

    this.Delay = 10;
    this.LineHeight = 20;
    this.Amount = 1;//注意:LineHeight一定要能整除Amount.
    this.Direction = "up";
    this.Timeout = 10000;
    this.ScrollContent = this.$(content);
    //this.ScrollContent.innerHTML += this.ScrollContent.innerHTML;
    //this.ScrollContent.scrollTop = 0;
    //this.ScrollContent.style.display = 'none'; 

    this.ScrollText(); 

    if(btnNext)
    {
        this.NextButton = this.$(btnNext);
        this.NextButton.onclick = this.GetFunction(this,"Next");
        this.NextButton.onmouseover = this.GetFunction(this,"Stop");
        this.NextButton.onmouseout = this.GetFunction(this,"Start");
    }
    if(btnPrevious)
    {
        this.PreviousButton = this.$(btnPrevious);
        this.PreviousButton.onclick = this.GetFunction(this,"Previous");
        this.PreviousButton.onmouseover = this.GetFunction(this,"Stop");
        this.PreviousButton.onmouseout = this.GetFunction(this,"Start");
    }
    this.ScrollContent.onmouseover = this.GetFunction(this,"Stop");
    this.ScrollContent.onmouseout = this.GetFunction(this,"Start");
    if(autoStart)
    {
        this.Start();
    }
}

ScrollText.prototype.AddItem = function(text, link)
{
    this.Items[this.Items.length] = text; 
    this.ItemsLink[this.ItemsLink.length] = link; 

    if (this.Items.length == 1) 
        this.ScrollContent.innerHTML = this.getDisplayString(text, link, text.length); 
}

ScrollText.prototype.ScrollText = function()
{
    window.clearInterval(this.IntervalID); 
    this.IntervalID = 0; 

    this.ItemIndex ++; 
    if (this.ItemIndex < 0 || this.ItemIndex >= this.Items.length) 
        this.ItemIndex = 0; 

    this.IntervalID = window.setInterval(this.GetFunction(this,"doScrollText"), 30); 
}

ScrollText.prototype.getDisplayString = function(text, link, len)
{
    var txt = '<A href="' + link + '">' + text.substring(0, len) + '</A>'; 
    return txt; 
}

ScrollText.prototype.doScrollText = function()
{
    var text = this.Items[this.ItemIndex]; 
    var link = this.ItemsLink[this.ItemIndex]; 
    var len = this.ItemLength; 
    if (len < text.length) {
        this.ItemLength = len + 1; 
        this.ScrollContent.innerHTML = this.getDisplayString(text, link, len+1);
    }
    else {
        window.clearInterval(this.IntervalID); 
        this.IntervalID = 0; 
        this.ItemLength = 0; 
    }
}

ScrollText.prototype.$ = function(element)
{
    return document.getElementById(element);
}

ScrollText.prototype.Previous = function()
{
    clearTimeout(this.AutoScrollTimer);
    clearTimeout(this.ScrollTimer);
    this.Scroll("up");
}

ScrollText.prototype.Next = function()
{
    clearTimeout(this.AutoScrollTimer);
    clearTimeout(this.ScrollTimer);
    this.Scroll("down");
}

ScrollText.prototype.Start = function()
{
    clearTimeout(this.AutoScrollTimer);
    this.AutoScrollTimer = setTimeout(this.GetFunction(this,"AutoScroll"), this.Timeout);
}

ScrollText.prototype.Stop = function()
{
    clearTimeout(this.ScrollTimer);
    clearTimeout(this.AutoScrollTimer);
}

ScrollText.prototype.AutoScroll = function()
{
    if(this.Direction == "up")
    {
        if(parseInt(this.ScrollContent.scrollTop) >= parseInt(this.ScrollContent.scrollHeight) / 2)
        {
            this.ScrollContent.scrollTop = 0;
        }
        this.ScrollContent.scrollTop += this.Amount;
    }
    else
    {
        if(parseInt(this.ScrollContent.scrollTop) <= 0)
        {
            this.ScrollContent.scrollTop = parseInt(this.ScrollContent.scrollHeight) / 2;
        }
        this.ScrollContent.scrollTop -= this.Amount;
    }
    if(parseInt(this.ScrollContent.scrollTop) % this.LineHeight != 0)
    {
        this.ScrollTimer = setTimeout(this.GetFunction(this,"AutoScroll"), this.Delay);
    }
    else
    {
        this.AutoScrollTimer = setTimeout(this.GetFunction(this,"AutoScroll"), this.Timeout);
    }

    this.ScrollText();
}

ScrollText.prototype.Scroll = function(direction)
{
    if(direction=="up")
    {
        if(this.ScrollContent.scrollTop == 0)
        {
            this.ScrollContent.scrollTop = parseInt(this.ScrollContent.scrollHeight) / 2;
        }
        this.ScrollContent.scrollTop -= this.Amount;
    }
    else
    {
        this.ScrollContent.scrollTop += this.Amount;
    }
    if(parseInt(this.ScrollContent.scrollTop) >= parseInt(this.ScrollContent.scrollHeight) / 2)
        {
            this.ScrollContent.scrollTop = 0;
        }
    if(parseInt(this.ScrollContent.scrollTop) % this.LineHeight != 0)
    {
        this.ScrollTimer = setTimeout(this.GetFunction(this,"Scroll",direction), this.Delay);
    }
}

ScrollText.prototype.GetFunction = function(variable,method,param)
{
    return function()
    {
        variable[method](param);
    }
}


//var items = []; 
//items[items.length] = '<font color=#eeeeee>2009-03-20 - </font><a href="http://javenstudio.org/blog/hawk-project"><font color=#eeeeee>Hawk-0.6.22最新版搜索引擎平台发布（提供下载）</font></a>';
//items[items.length] = '<font color=#eeeeee>2009-03-19 - </font><a href="http://docs.javenstudio.org/"><font color=#eeeeee>拥有百万文档的开发文档库搜索</font></a>';

document.write('<span id="listcontent" style="color:#cccccc;"></span>');

var scrollup = new ScrollText("listcontent");
scrollup.AddItem('2009-03-20 - Hawk-0.6.22最新版搜索引擎平台发布免费下载', 'http://javenstudio.org/blog/hawk-project'); 
scrollup.AddItem('2009-03-19 - 拥有超过百万篇各种平台和软件的开发文档库搜索', 'http://docs.javenstudio.org/'); 
scrollup.AddItem('2008-08-22 - 收录有四十部超过800万词汇的常用英语和汉语词典搜索', 'http://dict.javenstudio.org/'); 
scrollup.AddItem('2006-08-10 - 仿照java framework设计的C++框架简单实用高效', 'http://javenstudio.org/blog/javenlib-project'); 
scrollup.AddItem('2008-08-20 - Annotated Lucene 源码剖析系列原创文章', 'http://javenstudio.org/blog/annotated-lucene'); 
scrollup.AddItem('2007-12-29 - Annotated Hadoop 源码剖析系列原创文章', 'http://www.cppblog.com/javenstudio/archive/2008/02/22/43076.html'); 
scrollup.Start(); 

