//Allgemeine Variablen
var Offset=0;			// Scrollposition ContenLayer
var Dir=0			//nach oben=-1 nach unten=1
var Content
var contentSpeed=new Array(0,1,1,1,1,1,2,3,4,5,6,8,10,15,200,120,80,50,30,10,20,20,20,20,20,20,20,20);			// Inkremente & Zeitintervalle
var speedIndex=0
var maxSpeed=contentSpeed.length/2
var contentHandler
var jumping=false		// Wird während des Sprungs auf true gesetzt (kein Scrollen möglich)
var ns6 = (document.getElementById && !document.all); 		//Netscape & Co Support

// Scroll Variablen
var topColor, bottomColor;
var cursorY=0

// Jump Variablen
var accCount, accInc		// Beschleunigungsweg aufaddieren
var targetPos


function Init() {
	Content=document.getElementById("Content")
	topColor=document.getElementById("TopColor");
	bottomColor=document.getElementById("BottomColor");
	document.getElementById('Panel').onmousemove=setCursor;
	document.getElementById('Panel').onmouseover=doScroll;
	document.getElementById('Panel').onmouseout=endScroll;
	a=window.location.hash
	if (a!="") {
		a=a.substr(1)
	 	Jump(a,false)
	}
}


// Funktion zum Berechnen der scrollbaren Distanz
function Gap() { return(parseInt(Content.offsetHeight)-parseInt(document.getElementById("BottomLayer").style.height)) }
function showPos() { 
	window.status=(Math.floor((-Offset)/Gap()*100)+"%") 
}


// Scroll-Funktionen
function doScroll(e) {
	if (!jumping && Gap()>0) {
		window.clearTimeout(contentHandler)
		setCursor(e);
		moveContent()
	}
}

function endScroll() {
	if (!jumping && Gap()>0) {
		window.clearTimeout(contentHandler)
		topColor.style.top="58px";
		bottomColor.style.top="-58px";
	}
}

function setCursor(e) {
	if (!jumping && Gap()>0) {
		if (ns6) { y=e.clientY;}
		else { y=window.event.y;}
		cursorY=y-140;
		topColor.style.top=58+cursorY+"px";
		bottomColor.style.top=cursorY-58+"px";
		cursorY>=0 ? Dir=1 : Dir=-1;
		speedIndex=Math.floor(Math.abs(cursorY)/58*maxSpeed);
	}
}

function topPos() {
	if (!jumping) {
		Offset=0
		Content.style.top=0+"px"
		showPos()
	}
}

function bottomPos() {
	if (!jumping) {
		Offset=-Gap()
		if (Offset<0) {
			Content.style.top=Offset+"px"
			showPos()
		}
	}
}

function moveContent() {
	Offset-=Dir*contentSpeed[speedIndex]
	if (Offset>0) { Offset=0 }			// Anfang
	else { 									// oder Ende erreicht
		a=-Gap();
		if (Offset<a) { Offset=a }
	}		
	showPos()
	Content.style.top=Offset;
	contentHandler=setTimeout('moveContent()',contentSpeed[speedIndex+maxSpeed])
}


// Jump-Funktionen
function Jump(Marke,jumpMode) {
	var m = document.getElementById(Marke);
	
	if (!m) {alert("Sprungmarke [ "+Marke+" ] nicht gefunden       ")}
	else {
		if (!jumping && Gap()>0) {
			targetPos=parseInt(m.offsetTop)
			a=Gap()
			if (targetPos>a) {targetPos=a}
			d=targetPos+Offset
			if (d!=0) {
				if (jumpMode) {
					accCount=0
					accInc=1
					speedIndex=2
					d>0 ? Dir=-1 : Dir=1
					jumping=true
					doJump()
				}
				else {
					Offset=-targetPos
					Content.style.top=-targetPos+"px"
					showPos()
				}
			}
		}
	}
}

function doJump() {
	a=contentSpeed[Math.floor(speedIndex)]		//Verschiebung auslesen
	Offset+=a*Dir
	Rest=targetPos+Offset
	if (Rest*Dir<0) {			// Ziel noch nicht erreicht
		Content.style.top=Offset+"px"									// Position setzen
		showPos()
		if (accCount*2>=Math.abs(Rest)) { 											// Restweg kleiner als Beschleunigungsweg? --> 
			if (speedIndex>1) {	speedIndex-=.25 }								// Geschwindigkeit verringern, wenn möglich
		}
		else {																					// Restweg grösser als Beschleunigungsweg? --> 
			if (speedIndex<maxSpeed-1) {										//Geschwindigkeit erhöhen, wenn möglich
				accCount+=a																	// Beschleunigungsweg aufaddieren
				speedIndex+=.5
			}				
		}
		contentHandler=window.setTimeout("doJump()", contentSpeed[Math.floor(speedIndex)+maxSpeed])
	}
	else {
		jumping=false
		Offset=-targetPos
		Content.style.top=-targetPos+"px"
		showPos()
		clearTimeout(contentHandler)
	}
}

