//function ScrollText(content,btnPrevious,btnNext,autoStart)
function ScrollText(content,linehtight,timeout)
{
    this.Speed = 20;
    this.Timeout = timeout;
    this.LineHeight = linehtight;
//    this.NextButton = this.$(btnNext);
//    this.PreviousButton = this.$(btnPrevious);
    this.ScrollContent = this.$(content);
    this.ScrollContent.innerHTML += this.ScrollContent.innerHTML;
//    this.NextButton.onclick = this.GetFunction(this,"Next");
//    this.PreviousButton.onclick = this.GetFunction(this,"Previous");
    
//    this.NextButton.onmouseover = this.GetFunction(this,"Stop");
//    this.NextButton.onmouseout = this.GetFunction(this,"Start");
    
    this.ScrollContent.onmouseover = this.GetFunction(this,"Stop");
    this.ScrollContent.onmouseout = this.GetFunction(this,"Start");
    
//    this.PreviousButton.onmouseover = this.GetFunction(this,"Stop");
//    this.PreviousButton.onmouseout = this.GetFunction(this,"Start");
//    if(autoStart)
//    {
        this.Start();
//    }
}

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()
{
    this.AutoScrollTimer = setTimeout(this.GetFunction(this,"AutoScroll"), this.Timeout);
}

ScrollText.prototype.Stop = function()
{
    clearTimeout(this.AutoScrollTimer);
}

ScrollText.prototype.AutoScroll = function()
{
    this.ScrollContent.scrollTop++;
    if(parseInt(this.ScrollContent.scrollTop) % this.LineHeight != 0)
    {
        this.ScrollTimer = setTimeout(this.GetFunction(this,"AutoScroll"), this.Speed);
    }
    else
    {
        if(parseInt(this.ScrollContent.scrollTop) >= parseInt(this.ScrollContent.scrollHeight) / 2)
        {
            this.ScrollContent.scrollTop = 0;
        }
        this.AutoScrollTimer = setTimeout(this.GetFunction(this,"AutoScroll"), this.Timeout);
    }
}

ScrollText.prototype.Scroll = function(direction)
{
    if(direction=="up")
    {
        this.ScrollContent.scrollTop--;
    }
    else
    {
        this.ScrollContent.scrollTop++;
    }
    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.Speed);
    }
}

ScrollText.prototype.GetFunction = function(variable,method,param)
{
    return function()
    {
        variable[method](param);
    }
}