/*
	+++
	
	TMScrollLeiste (DHTML Scroll-Leiste) Version 0.7 
	DHTML-Scroll-Leiste
	
	Benoetigt tmdomlib.js v0.6.1
	
	Kompatible Browser (Liste u.U. unvollstaendig):
	-	Gecko-basierte Browser (Mozilla, Firefox/Firebird/Phoenix, Netscape 6+ etc.)
	-	Internet Explorer 5+
	-	Opera 6+
	-	Safari/KHTML
	
	Dieses Script darf fuer non-kommerzielle Zwecke frei und kostenlos verwendet werden, sofern
	-	die einzelnen Funktionen unveraendert bleiben.
	-	die einzelnen Funktions-Bezeichnungen unveraendert bleiben.
	-	diese Informationen, insbesodere auch der Hinweis auf den Urheber, unveraendert bleiben.
	
	Fuer kommerzielle Nutzung oder bei Unklarheiten bezueglich der Nutzungsbedingungen wende dich an den Urheber.
	
	Urheber:	Tobias Mueller 2004
	Internet:	www.adepto.de
	E-Mail:		mail@adepto.de
	
	+++
*/

function gup(name){
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

TMScrollLeiste = function() {
	if (isDOM) {
		var a = arguments;
		this.objekt = a[0] + 'objekt';
		eval(this.objekt + '= this');
		this.gesamtBox = TMSucheElem(a[0]);
		this.inhalt = TMSucheElem(a[1]);
		this.leistenBox = TMSucheElem(a[2]);
		this.leiste = TMSucheElem(a[3]);
		this.greifer = TMSucheElem(a[4]);
		this.pfeil01 = TMSucheElem(a[5]);
		this.pfeil02 = TMSucheElem(a[6]);
		this.springPfeil = TMSucheElem(a[7]);
		this.scrollVertikal = (a[8] == 'vertikal') ? true : false;
		this.scrollTimeout = a[9];
		this.scrollSpeed = a[10];
		this.mausradSpeed = a[11];
		if (a.length == 20) {
			this.bildwechsel = true;
			this.greiferBild_n = a[12];
			this.greiferBild_o = a[13];
			this.pfeil01Bild_n = a[14];
			this.pfeil01Bild_o = a[15];
			this.pfeil02Bild_n = a[16];
			this.pfeil02Bild_o = a[17];
			this.springPfeilBild_n = a[18];
			this.springPfeilBild_o = a[19];
		} else {
			this.bildwechsel = false;
		}
		this.scrollSchleife = null;
		this.inhaltMaxPos = 0;
		this.greiferMinPos = 0;
		if (this.scrollVertikal) {
			this.inhaltPos = parseInt(this.inhalt.style.top) ? parseInt(this.inhalt.style.top) : 0;
			this.greiferPos = parseInt(this.greifer.style.top) ? parseInt(this.greifer.style.top) : 0;
			this.inhaltHoehe = this.inhalt.offsetHeight;
			this.gesamtBoxHoehe = this.gesamtBox.offsetHeight;
			this.inhaltMinPos = -this.inhaltHoehe + this.gesamtBoxHoehe;
			this.leistenHoehe = this.leiste.offsetHeight;
			this.greiferHoehe = this.greifer.offsetHeight;
			this.greiferMaxPos = this.leistenHoehe - this.greiferHoehe;
			this.scrollBereich = this.greiferMaxPos / (this.inhaltHoehe - this.gesamtBoxHoehe);
			if (this.inhaltHoehe > this.gesamtBoxHoehe) {
				this.leistenBox.style.visibility = 'visible';
				var goto = gup('goto');
				if(goto.length > 0){
					anchorPosition = document.getElementById(goto) ? parseInt(document.getElementById(goto).offsetTop) : 0;
					if(isGECKO){
						anchorPosition -= 20;
					}
					this.zuAnkerSpringen(anchorPosition);
				}
			}
		} else {
			this.inhaltPos = parseInt(this.inhalt.style.left) ? parseInt(this.inhalt.style.left) : 0;
			this.greiferPos = parseInt(this.greifer.style.left) ? parseInt(this.greifer.style.left) : 0;
			this.inhaltBreite = this.inhalt.offsetWidth;
			this.gesamtBoxBreite = this.gesamtBox.offsetWidth;
			this.inhaltMinPos = -this.inhaltBreite + this.gesamtBoxBreite;
			this.leistenBreite = this.leiste.offsetWidth;
			this.greiferBreite = this.greifer.offsetWidth;
			this.greiferMaxPos = this.leistenBreite - this.greiferBreite;
			this.scrollBereich = this.greiferMaxPos / (this.inhaltBreite - this.gesamtBoxBreite);
			if (this.inhaltBreite > this.gesamtBoxBreite) {
				this.leistenBox.style.visibility = 'visible';
			}
		}
		var obj = this;
		TMErstelleEvent(this.pfeil01,'mousedown',function(e) { obj.scrollenbeginnen(obj.scrollSpeed,e); });
		TMErstelleEvent(this.pfeil01,'mouseup',function() { obj.scrollenbeenden(); });
		TMErstelleEvent(this.pfeil01,'mouseout',function() { obj.scrollenbeenden(); });
		TMErstelleEvent(this.pfeil02,'mousedown',function(e) { obj.scrollenbeginnen(-obj.scrollSpeed,e); });
		TMErstelleEvent(this.pfeil02,'mouseup',function() { obj.scrollenbeenden(); });
		TMErstelleEvent(this.pfeil02,'mouseout',function() { obj.scrollenbeenden(); });
		TMErstelleEvent(this.greifer,'mousedown',function(e) { obj.ziehenbeginnen(e); });
		TMErstelleEvent(this.springPfeil,'mousedown',function(e) { obj.hochspringen(e); });
		if (isIE6) {
			this.mausradPos = this.inhaltPos / this.mausradSpeed;
			TMErstelleEvent(this.inhalt,'mousewheel',function() { obj.mausradscrollen(); });
		}
		if (this.bildwechsel) {
			this.bilderladen();
		}
	}
};

TMScrollLeiste.prototype = {

	positionieren : function() {
		if (this.scrollVertikal) {
			this.inhaltPosX = 0;
			this.inhaltPosY = this.inhaltPos;
			this.greiferPosX = 0;
			this.greiferPosY = this.greiferPos;
		} else {
			this.inhaltPosX = this.inhaltPos;
			this.inhaltPosY = 0;
			this.greiferPosX = this.greiferPos;
			this.greiferPosY = 0;
		}
		TMCSSPosition(this.inhalt,this.inhaltPosX,this.inhaltPosY);
		TMCSSPosition(this.greifer,this.greiferPosX,this.greiferPosY);
	},
	
	scrollenbeginnen : function(speed,e) {
		if (this.bildwechsel) {
			if (speed > 0) {
				this.pfeil = this.pfeil01;
				this.pfeilBild = this.pfeil01Bild_o
			} else {
				this.pfeil = this.pfeil02;
				this.pfeilBild = this.pfeil02Bild_o;
			}
			this.bilderwechseln(this.pfeil,this.pfeilBild);
		}
		this.scrollSchleife = window.setInterval(this.objekt + '.scrollen(' + speed + ')',this.scrollTimeout);
		TMUnterbindeStandard(e);
	},
	
	scrollen : function(speed) {
		this.inhaltPos += speed;
		if (this.inhaltPos < this.inhaltMinPos) {
			this.inhaltPos = this.inhaltMinPos;
			this.greiferPos = this.greiferMaxPos;
			window.clearInterval(this.scrollSchleife);
			this.scrollSchleife = null;
		} else if (this.inhaltPos > this.inhaltMaxPos) {
			this.inhaltPos = this.inhaltMaxPos;
			this.greiferPos = this.greiferMinPos;
			window.clearInterval(this.scrollSchleife);
			this.scrollSchleife = null;
		} else {
			this.greiferPos = Math.round(-this.inhaltPos * this.scrollBereich);
		}
		if (isIE6) {
			this.mausradPos = this.inhaltPos / this.mausradSpeed;
		}
		this.positionieren();
	},
	
	scrollenbeenden : function() {
		if (this.bildwechsel) {
			this.bilderwechseln(this.pfeil01,this.pfeil01Bild_n,this.pfeil02,this.pfeil02Bild_n);
		}
		if (this.scrollSchleife) {
			window.clearInterval(this.scrollSchleife);
			this.scrollSchleife = null;
		}
	},
	
	ziehenbeginnen : function(e) {
		if (this.bildwechsel) {
			this.bilderwechseln(this.greifer,this.greiferBild_o);
		}
		this.mausPos = this.scrollVertikal ? TMSucheMaus(e).yo : TMSucheMaus(e).xo;
		this.ziehenPos = this.mausPos - this.greiferPos;
		var obj = this;
		TMErstelleEvent(document,'mousemove',function(e) { obj.ziehen(e); });
		TMErstelleEvent(document,'mouseup',function() { obj.ziehenbeenden(); });
		TMUnterbindeStandard(e);
	},
	
	ziehen : function(e) {
		this.mausPos = this.scrollVertikal ? TMSucheMaus(e).yo : TMSucheMaus(e).xo;
		this.greiferPos = this.mausPos - this.ziehenPos;				
		if (this.greiferPos > this.greiferMaxPos) { 
			this.greiferPos = this.greiferMaxPos;
			this.inhaltPos = this.inhaltMinPos;
		} else if (this.greiferPos < this.greiferMinPos) { 
			this.greiferPos = this.greiferMinPos;
			this.inhaltPos = this.inhaltMaxPos;
		} else {
			this.inhaltPos = Math.round(-this.greiferPos * (1 / this.scrollBereich));
		}
		if (isIE6) {
			this.mausradPos = this.inhaltPos / this.mausradSpeed;
		}
		this.positionieren();
		TMUnterbindeStandard(e);
	},
	
	ziehenbeenden : function() {
		if (this.bildwechsel) {
			this.bilderwechseln(this.greifer,this.greiferBild_n);
		}
		TMEntferneEvent(document,'mousemove');
		TMEntferneEvent(document,'mouseup');
	},
	
	hochspringen : function(e) {
		if (this.bildwechsel) {
			this.bilderwechseln(this.springPfeil,this.springPfeilBild_o);
			var obj = this;
			TMErstelleEvent(this.springPfeil,'mouseup',function() { obj.bilderwechseln(obj.springPfeil,obj.springPfeilBild_n); });
			TMErstelleEvent(this.springPfeil,'mouseout',function() { obj.bilderwechseln(obj.springPfeil,obj.springPfeilBild_n); });
		}
		this.greiferPos = this.greiferMinPos;
		this.inhaltPos = this.inhaltMaxPos;
		if (isIE6) {
			this.mausradPos = this.inhaltPos / this.mausradSpeed;
		}
		this.positionieren();
		TMUnterbindeStandard(e);
	},
	
	zuAnkerSpringen : function(pos) {
		this.inhaltPos = this.inhaltPos - pos;
		if (this.inhaltPos < this.inhaltMinPos){
			this.inhaltPos = this.inhaltMinPos;
		}
		else if(this.inhaltPos > this.inhaltMaxPos){
			this.inhaltPos = this.inhaltMaxPos;
		}
		this.greiferPos = this.greiferPos = Math.round(-this.inhaltPos * this.scrollBereich);;
		this.positionieren();
	},
	
	mausradscrollen : function() {
		if (event.wheelDelta) {
			this.mausradPos += event.wheelDelta / 120;
			this.inhaltPos = Math.round(this.mausradPos * this.mausradSpeed);
			if (this.inhaltPos < this.inhaltMinPos) {
				this.inhaltPos = this.inhaltMinPos;
				this.greiferPos = this.greiferMaxPos;
				this.mausradPos = this.inhaltPos / this.mausradSpeed;
			} else if (this.inhaltPos > this.inhaltMaxPos) {
				this.inhaltPos = this.inhaltMaxPos;
				this.greiferPos = this.greiferMinPos;
				this.mausradPos = this.inhaltPos / this.mausradSpeed;
			} else {
				this.greiferPos = Math.round(-this.inhaltPos * this.scrollBereich);
			}
			this.positionieren();
			event.returnValue = false;
		}
	},
	
	bilderladen : function() {
		this.bilder = new Array(this.greiferBild_o,this.pfeil01Bild_o,this.pfeil02Bild_o,this.springPfeilBild_o);
		this.bild = new Array();
		for (var i = 0; i < this.bilder.length; i++) {
			this.bild[i] = new Image();
			this.bild[i].src = this.bilder[i];
		}
	},
	
	bilderwechseln : function() {
		var a = arguments;
		for (var i = 0; i < a.length-1; i+=2) {
			a[i].setAttribute('src',a[i+1]);
		}
	}
};
