function InitScrollbar()
{
    scroller = new ScrollBox();
    scroller.Init('scroller', 'scrollBox', 'scrollboxContent', 'scrollbar', 'scrollbarIndicator', 'scrollbarUp', 'scrollbarDown');
}
		
function ScrollBox()
{
    var objName = '';
    var top = 0;
    var next_top = 0;
    var Stop = false;
    var Step = 0;
    var time = 0;

    var el = null; //document.getElementById("scrollboxContent");
    var elIndicator = null; //document.getElementById("scrollbarIndicator");
    var elScrollbar = null; //document.getElementById("scrollbar");
    var elScrollUp = null;
    var elScrollDown = null;
    var maxScrollRange = 0;
    
    var strScrollBoxId = '';
    var strContentId = '';
    var strScrollbarId = '';
    var strIndicatorId = '';
    var strScrollUpId = '';
    var strScrollDownId = '';
}
		
ScrollBox.prototype.Init = function(ownName, scrollboxId, contentId, scrollbarId, indicatorId, upId, downId)
{
    this.objName = ownName;
    this.strScrollBoxId = scrollboxId;
    this.strContentId = contentId;
    this.strScrollbarId = scrollbarId;
    this.strIndicatorId = indicatorId;
    this.strScrollUpId = upId;
    this.strScrollDownId = downId;
    
    this.top = 0;
    this.next_top = 0;
    this.Stop = false;
    this.Step = 1;
    if(this.strContentId == '') this.el = document.getElementById("scrollboxContent");
    else  this.el = document.getElementById(this.strContentId);
    this.time = 15;

    if(this.strScrollbarId == '') this.elScrollbar = document.getElementById("scrollbar");
    else this.elScrollbar = document.getElementById(this.strScrollbarId);
    
    if(this.strIndicatorId == '') this.elIndicator = document.getElementById("scrollbarIndicator");
    else this.elIndicator = document.getElementById(this.strIndicatorId);
    
    if(this.strScrollUpId == '') this.elScrollUp = document.getElementById("scrollbarUp");
    else this.elScrollUp = document.getElementById(this.strScrollUpId);
    
    if(this.strScrollDownId == '') this.elScrollDown = document.getElementById("scrollbarDown");
    else this.elScrollDown = document.getElementById(this.strScrollDownId);
    
    this.maxScrollRange = this.el.offsetHeight;
}

ScrollBox.prototype.MoveTo = function(newpos)
{
    if((this.el = document.getElementById(this.strContentId)))
    {
	pos = -newpos;
	this.el.style.top = pos+"px";
	oldpos = pos;
				
	// global aktualisieren
	this.top = pos;
	this.UpdateIndicator();
    }

}

ScrollBox.prototype.Start = function(dir)
{
    this.Stop = false;
    this.Step = 2;

    if(dir == 0)			// scroll up
    {
	if(this.el.offsetHeight > this.elScrollbar.offsetHeight)
    	    this.Move(this.top, -(this.el.offsetHeight - this.elScrollbar.offsetHeight));
    }
    else				// scroll down
	this.Move(this.top, 0);
}
		
ScrollBox.prototype.StopIt = function()
{
    this.Stop = true;
}
		
ScrollBox.prototype.Faster = function()
{
    this.Step = 8;
}
		
ScrollBox.prototype.Slower = function()
{
    this.Step = 2;
}
		
ScrollBox.prototype.Move = function(oldpos, newpos)
{
    setTimeout(this.objName + ".timerProc("+oldpos+","+newpos+")", this.time);
}
		
ScrollBox.prototype.timerProc = function(oldpos, newpos)
{
    pos = 0;
			
    if((this.el = document.getElementById(this.strContentId)))
    {
	if(newpos > oldpos)	// scroll down
	{
	    if(newpos - oldpos >= this.Step) pos = oldpos + this.Step;
	    else pos = newpos;
	}
	else	// scroll up
	{			    
	    if(oldpos - newpos >= this.Step) pos = oldpos - this.Step;
	    else pos = newpos;
	}			

	this.el.style.top = pos+"px";
	oldpos = pos;
				
	// global aktualisieren
	this.top = pos;
				
	// schon fertig
	if(this.top != newpos && !this.Stop) setTimeout(this.objName + ".timerProc("+oldpos+","+newpos+")", this.time);
	
	this.UpdateIndicator();
    }
}

ScrollBox.prototype.UpdateIndicator = function()
{
// Hoehe des inneren Bereichs des Scrollbars ermitteln
    sbHeight = this.elScrollbar.offsetHeight;
    sbHeight -= this.elScrollUp.offsetHeight;
    sbHeight -= this.elScrollDown.offsetHeight;
    sbHeight -= this.elIndicator.offsetHeight;
    sbHeight -= 2;	// ??? Border ???
    
// Verhaeltnis zwischen ScrollHeight und ScollbarHeight ermitteln
    ratio = (this.el.offsetHeight - this.elScrollbar.offsetHeight) / sbHeight;
    
    if(ratio > 0)
    {
	// aktuelle Pos. umrechnen
	y = Math.round(-this.top / ratio);
	y += this.elScrollUp.offsetHeight;	// Offset oben beachten
    }
    else y = this.elScrollUp.offsetHeight;
    
    this.elIndicator.style.top = y + "px";
}

ScrollBox.prototype.StartDrag = function()
{
    var ie = document.all?true:false;
    
    if(!ie) document.captureEvents(Event.MOUSEMOVE);
    this.elScrollbar.onmousemove = this.MoveDrag;
}

ScrollBox.prototype.StopDrag = function()
{
    this.elScrollbar.onmousemove = null;
}

ScrollBox.prototype.MoveDrag = function(e)
{
    var ie = document.all?true:false;
    
    // top aus IndicatorPosition berechnen
// Hoehe des inneren Bereichs des Scrollbars ermitteln
    sbHeight = sbCountry.elScrollbar.offsetHeight;
    sbHeight -= sbCountry.elScrollUp.offsetHeight;
    sbHeight -= sbCountry.elScrollDown.offsetHeight;
    sbHeight -= sbCountry.elIndicator.offsetHeight;
    sbHeight -= 2;	// ??? Border ???
    
// Verhaeltnis zwischen ScrollHeight und ScollbarHeight ermitteln
    ratio = (sbCountry.el.offsetHeight - sbCountry.elScrollbar.offsetHeight) / sbHeight;

    if(ie)
	myTop = (230 - event.clientY + document.body.scrollTop) * ratio;
    else
	myTop = (230 - e.pageY) * ratio;

    if(-myTop >= 0 && -myTop <= sbCountry.el.offsetHeight - sbCountry.elScrollbar.offsetHeight)
    {
	sbCountry.top = myTop;
	sbCountry.Move(sbCountry.top, sbCountry.top);
	sbCountry.UpdateIndicator();
    }
    return true;
}
