/* <![CDATA[ */
/*
	+++
	
	TMScrollLeiste (DHTML Scroll-Leiste) Version 0.8 
	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
	
	Added:		24.07.2007
				endlich Mousewheel-Unterstuetzung für Mozilla/Opera implementiert
	
	+++
*/
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';
			}
		} 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); });
		this.mausradPos = this.inhaltPos / this.mausradSpeed;
		TMErstelleEvent(this.gesamtBox,'mousewheel',function(e) { obj.mausradscrollen(e); });
		if (isGECKO) {
			TMErstelleEvent(this.gesamtBox,'DOMMouseScroll',function(e) { obj.mausradscrollen(e); },false);
		} else {
			TMErstelleEvent(this.gesamtBox,'mousewheel',function(e) { obj.mausradscrollen(e); });
		}
		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);
	},
	
	mausradscrollen : function(e) {
		e = e ? e : window.event;
		var delta = 0;
		if (e.wheelDelta) {
			delta = e.wheelDelta / 120;
			/*
            if (window.opera) {
				delta = -delta;
			}
			*/
		} else if (e.detail) {
			delta = -e.detail/3;
		}
		if (delta) {
			this.mausradPos += delta;
			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();
			//TMUnterbindeStandard(e)
			e.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]);
		}
	}
};

/*
	TMScrollLeiste-Objekt erstellen: 
	
	var meinScrollObjekt = new TMScrollLeiste( Parameter );
	
	Pflicht-Parameter (in dieser Reihenfolge):
		- Container-ID
		- Inhalt-ID
		- Scrollbar-Box-ID
		- Scrolltrack-ID
		- Greifer-ID
		- Scrollpfeil-ID: oben / links *
		- Scrollpfeil-ID: unten / rechts *
		- Nach-Oben-Springpfeil-ID
		- 'vertikal' / 'horizontal' *
		- Scroll-Timeout **
		- Scroll-Speed **
		- Mausrad-Speed **

	Optionale zusaetzliche Parameter (in dieser Reihenfolge): 
		(Werden benoetigt, falls bei Bedienung der Scrollbar-Elemente die jeweilige Grafik ausgetauscht werden soll.)
		- Greifer-Grafik
		- Greifer-Grafik (mousedown)
		- Pfeil-Grafik: oben / links *
		- Pfeil-Grafik (mousedown): oben / links *
		- Pfeil-Grafik: unten / rechts *
		- Pfeil-Grafik (mousedown): unten / rechts *
		- Nach-Oben-Springpfeil-Grafik
		- Nach-Oben-Springpfeil-Grafik (mousedown)

		*	Die Angabe vor dem Slash gilt bei vertikaler Scrollbar, die Angabe dahinter bei horizontaler Scrollbar
		**	Im Gegensatz zu allen anderen Parametern kein String sondern Zahl.
	
	WICHTIG: TMScrollLeiste-Objekt(e) erst _nach_ dem Laden der Seite erstellen!
*/
TMErstelleEvent(window,'load',function() {
	var scroller1 = new TMScrollLeiste(
		'container',
		'scrollinhalt',
		'scrollbarbox',
		'scrolltrack',
		'scrollgreifer',
		'scrollpfeiloben',
		'scrollpfeilunten',
		'springpfeil',
		'vertikal',
		15,
		5,
		10,
		'/images/scroll/v_greifer.png',
		'/images/scroll/v_greifer_o.png',
		'/images/scroll/v_pfeil_a.png',
		'/images/scroll/v_pfeil_a_o.png',
		'/images/scroll/v_pfeil_b.png',
		'/images/scroll/v_pfeil_b_o.png',
		'/images/scroll/v_top_jump.png',
		'/images/scroll/v_top_jump_o.png'
	);

});