	// Scroller
	var m_nScrollY = 0;		// Y-Scrollwert
	var m_nTargetY = 0;		// Zielwert des Scrollers
	var m_nVeloLineY = 8;	// Linien-Offset
	var m_nVeloPageY = 24;	// Page-Offset	
	
	// Layout
	var m_nWinH = 0;		// Höhe des Frames
	var m_nContentH = -1;	// Höhe des Textes
	var m_nThumbY = 0;		// Y-Position des Thumbs
	var m_nBotY = 0;		// Y-Position des Bottom-Peils
	var m_nCellX = 0;		// X-Pos der Tabellenzelle des Scrollers
	var m_nCellY = 0;		// Y-Pos der Tabellenzelle des Scrollers
	var m_nFixedHeight = -1 // Feste Höhe oder -1 für flexible Höhe
	var m_bVisible = false; // Wird der Scroller gerade dargestellt?

	// Mouse
	var m_nMouseX = 0;
	var m_nMouseY = 0;
	var m_nMouseStartY = 0;
	var m_bClick = false;
	var m_bClickThumb = false;

	// Timer
	var m_pScrollTimer = 0;

	// Pfade
	var m_sPicPath = "/pics/";


function DoScroller()
{	return (ie && !opera && isWin);
}

function InitScroller(sAname, nFixedHeight)
{	if (!DoScroller()) return;
	
	m_nFixedHeight = nFixedHeight;

	if (m_nFixedHeight == -1)
			document.body.scroll = 'no';
	else	document.body.scroll = 'auto';
	
	// Events einrichten
	window.onresize = Layout;
	document.onmousedown = OnLDown;
	document.onmousemove = OnMove;
	document.onmouseup = OnLUp;
	document.ondblclick = OnLDown;
	document.onkeydown = OnKeyDown;
	document.onmousewheel = OnWheel;
	
	document.all["sccontainer"].onscroll=OnScrollContainer;
	
	// Layouten und anzeigen
	m_nContentH = GetHeight("sccontainer");
	obj = GetObjStyle("sccontainer");
	obj.overflow = "hidden";

	Layout();
	Show("sccontainer");
	
	// Evtl. zu Anker-Position scollen
	if (sAname == "" || sAname == "undefined")
	{	sAname = document.location.hash;
	}
	
	if (sAname != "" && sAname != "undefined")
	{	document.location.href = sAname;
	}
}

function OnScrollContainer()
{	m_nScrollY = document.all["sccontainer"].scrollTop;
	UpdateScroller();
}

function Layout()
{	if (!DoScroller()) return;
		
	// Aktuelle Höhe des Fensters
	if (m_nFixedHeight == -1)
			m_nWinH = GetWindowHeight();
	else	m_nWinH = m_nFixedHeight;
	
	SetHeight("sccontainer", m_nWinH);

	// Position Text
	textX = GetAbsX("ScrollCell");
	textY = GetAbsY("ScrollCell");
	SetX("sccontainer", textX);
	SetY("sccontainer", textY);

	if (m_nWinH >= m_nContentH-8)
	{	if (m_bVisible)
		{	Hide("scback");
			Hide("sctop");
			Hide("scbot");
			Hide("scthumb");
			m_bVisible = false;
		}
	}
	else
	{	if (!m_bVisible)
		{	Show("sctop");
			Show("scbot");
			Show("scthumb");
			Show("scback");
			m_bVisible = true;
		}
		
		m_nCellX = GetAbsX("ScrollerCell");
		m_nCellY = GetAbsY("ScrollerCell");

		// Position + Größe Hintergrund
		SetX("scback", m_nCellX+2);
		SetY("scback", m_nCellY);
		SetHeight("scback", m_nWinH-18);

		// Position Top;
		SetX("sctop", m_nCellX);
		SetY("sctop", m_nCellY);

		// Y-Position Bottom
		SetX("scbot", m_nCellX);
		m_nBotY = m_nWinH - 18;
		SetY("scbot", m_nBotY+m_nCellY);

		// X-Position Thumb
		SetX("scthumb", m_nCellX);
		UpdateScroller();
	}
}

function Scroller()
{	if (!DoScroller()) return;
	
	document.write('<div id="sctop" style="position:absolute;top:0px;left:0px;visibility:hidden;z-index:2">')
	document.write('<img src="'+m_sPicPath+'scroller_top.gif" BORDER=0 width=21 height=18>')
	document.write('</div>')
	
	document.write('<div id="scthumb" style="position:absolute;top:0px;left:0px;visibility:hidden;z-index:3">')
	document.write('<img src="'+m_sPicPath+'scroller_thumb.gif" BORDER=0 width=21 height=13>')
	document.write('</div>')
	
	document.write('<div id="scbot" style="position:absolute;top:0px;left:0px;visibility:hidden;z-index:2">')
	document.write('<img src="'+m_sPicPath+'scroller_bot.gif" BORDER=0 width=21 height=18>')
	document.write('</div>')

	document.write('<div id="scback" style="position:absolute;top:0px;left:2px;width=17px;background:#FBF4F3;visibility:hidden;z-index:1">')
	document.write('</div>')
}

function StartScrollLayer()
{	StartScrollLayer(false)
}

function StartScrollLayer(bUseFixedHeight)
{	if (!DoScroller()) return;

	if (bUseFixedHeight)
			document.body.scroll = 'auto';
	else	document.body.scroll = 'no';	
	
	document.writeln('<div id="sccontainer" style="position:absolute;top:0px;left:0px;visibility:hidden;border:0px solid black">')
}

function EndScrollLayer()
{	if (!DoScroller()) return;
	document.writeln('</div>');
}

function StartLoop(nVelo, nTarget, bLoop)
{	m_bClick = true;
	m_nTargetY = nTarget;
	ScrollLoop(nVelo, bLoop, true);
	return false;
}

function ScrollLoop(nOffset, bLoop, bFirst)
{	ClearTimer();
	if (m_nScrollY == m_nTargetY) return;

	nVor = 1;
	nOffset = Math.abs(nOffset);
	if (m_nTargetY < m_nScrollY) nVor = -1;

	if (m_nTargetY != m_nScrollY) 
	{	if ((nVor == 1 && m_nScrollY+nOffset > m_nTargetY) ||
			(nVor == -1 && m_nScrollY-nOffset < m_nTargetY))
					m_nScrollY = m_nTargetY;			
			else	m_nScrollY += nOffset*nVor;		
	}

	UpdateScroller();

	if (bLoop && m_bClick && nOffset > 0)
	{	var nTime = 25;
		if (bFirst) nTime = 200;
		m_pScrollTimer = setTimeout("ScrollLoop("+nOffset+", true, false);", nTime);
	}
}

function UpdateScroller()
{	if (!DoScroller()) return;
	
	if (m_nScrollY < 0) m_nScrollY = 0;
	if (m_nScrollY > m_nContentH-m_nWinH) m_nScrollY = m_nContentH-m_nWinH;

	// Content
	if (document.getElementById)
	{	document.getElementById("sccontainer").scrollTop = m_nScrollY;
	}
	else if (document.all)
		document.all["sccontainer"].scrollTop = m_nScrollY;
	
	// Y-Position Thumb
	m_nThumbY = ScrollToThumb(m_nScrollY);	
	SetY("scthumb", m_nThumbY+m_nCellY+18);
}

// Events
function UpdateMousePos(evt)
{	if (ie)
	{	m_nMouseY = event.clientY + document.body.scrollTop;
		m_nMouseX = event.clientX + document.body.scrollLeft;
	}
	else if(ns4 || dom)
		{	m_nMouseY = evt.pageY;
			m_nMouseX = evt.pageX;
		}
	m_nMouseX -= m_nCellX+4;
	m_nMouseY -= m_nCellY;
}

function OnLDown(evt)
{	if((ns4 && e.which!=1) || (ie && event.button == 2)) return true; // Enables the right mousebutton

	var bLoop = true;
	if (ie && event.button == 0) // Doppelclick
		bLoop = false;
	
	UpdateMousePos(evt);
			
	// Scrollbar?
	if (m_nMouseX >= 0 && m_nMouseX <= 21)
	{	// Line Up?
		if (m_nMouseY >= 0 && m_nMouseY <= 18)
			return StartLoop(m_nVeloLineY, 0, bLoop);

		// Line Down?
		if (m_nMouseY >= m_nBotY+18+13 && m_nMouseY <= m_nBotY+18+13+18)
			return StartLoop(m_nVeloLineY, m_nContentH-m_nWinH, bLoop);

		// Thumb?
		if (m_nMouseY >= m_nThumbY+18 && m_nMouseY <= m_nThumbY+18+13)
		{	m_nMouseStartY = m_nMouseY - m_nThumbY;
			m_bClickThumb = true;
			return false;
		}

		// Page Up?
		if (m_nMouseY >= 18 && m_nMouseY <= m_nThumbY)
		{	m_bClickThumb = true;
			return StartLoop(m_nVeloPageY, ThumbToScroll(m_nMouseY-18-13/2), bLoop);
		}

		// Page Down?
		if (m_nMouseY >= m_nThumbY+13 && m_nMouseY <= m_nBotY+18+13)
		{	m_bClickThumb = true;
			return StartLoop(m_nVeloPageY, ThumbToScroll(m_nMouseY-18-13/2), bLoop);		
		}
	}

	return true;
}

function OnLUp(evt)
{	m_bClick = false;
	m_bClickThumb = false;
	bDragPage = false;
}

function OnMove(evt)
{	if (!m_bClickThumb) return;
	
	UpdateMousePos(evt);

	if (m_bClick)
	{	// Page-Mode
		m_nTargetY = ThumbToScroll(m_nMouseY-18-13/2);
		if (m_pScrollTimer == 0)
			m_pScrollTimer = setTimeout("ScrollLoop("+m_nVeloPageY+", true, false);", 100);
	}
	else
	{	// Drag-Mode
		m_nThumbY = m_nMouseY-m_nMouseStartY;
		m_nScrollY = ThumbToScroll(m_nThumbY);
		UpdateScroller();
	}
	if (ie) return false; // Selektion abstellen
}

function OnWheel()
{	var delta = event.wheelDelta;
	var v = m_nVeloPageY * delta/120;
	if (delta >= 120) StartLoop(v, 0, false);
	if (delta <= -120) StartLoop(v, m_nContentH-m_nWinH, false);
}

function OnKeyDown(evt)
{	if (!DoScroller()) return;
	
	if (ie) key = event.keyCode;
		else if (dom) key = evt.keyCode;
			else if (ns4) key = evt.which;	

	if (key == 38) StartLoop(m_nVeloLineY, 0, false);
	if (key == 40) StartLoop(m_nVeloLineY, m_nContentH-m_nWinH, false);
	if (key == 33) StartLoop(m_nVeloPageY, 0, false);
	if (key == 34) StartLoop(m_nVeloPageY, m_nContentH-m_nWinH, false);	
}

function ScrollToThumb(lm_nScrollY)
{	var scrollH = m_nWinH-18-13-18;
	lm_nThumbY = lm_nScrollY * (scrollH) / (m_nContentH-m_nWinH);
	if (lm_nThumbY < 0) lm_nThumbY = 0;
	if (lm_nThumbY > scrollH) lm_nThumbY = scrollH;
	return lm_nThumbY;
}

function ThumbToScroll(lm_nThumbY)
{	lm_nScrollY = lm_nThumbY * (m_nContentH-m_nWinH) / (m_nWinH-18-13-18);
	return lm_nScrollY;
}

function ClearTimer()
{	if (m_pScrollTimer)
	{	clearTimeout(m_pScrollTimer);
		m_pScrollTimer = 0;
	}
}

