﻿ScrollMenue.Registrierung = []
ScrollMenue.AnimationLaenge = 400
ScrollMenue.VersteckenDauer = 1000
ScrollMenue.Prozessor = 10


//////////////////WICHTIG///////////////////////////
//  Die Funktion write CSS muss eingebaut werden, //
//  da sont die Styles aus dem										//
//  JS nicht überommen werden											//
//////////////////WICHTIG///////////////////////////


function ScrollMenue(id, Richtung, Links, Oben, Breite, Hoehe) {
		this.ie = document.all ? 1 : 0
		this.ns4 = document.layers ? 1 : 0
		this.dom = document.getElementById ? 1 : 0
		if (this.ie || this.ns4 || this.dom) {
				this.id = id
				this.Richtung = Richtung
				this.Orientierung = Richtung == "Links" || Richtung == "Rechts" ? "h" : "v"
				this.RichtungTyp = Richtung == "Rechts" || Richtung == "NachUnten" ? "-" : "+"
				this.Dimension = this.Orientierung == "h" ? Breite : Hoehe
				this.VersteckeTimer = false
				this.AnimationsTimer = false
				this.oeffne = false
				this.ueber = false
				this.StartZeit = 0
				this.Referenz = "ScrollMenue_" + id
				eval(this.Referenz + "=this")
				ScrollMenue.Registrierung[id] = this
				var d = document
				var CSSText = "";
				CSSText += '#' + this.id + 'Container { visibility:hidden; '
				CSSText += 'top:' + Oben + 'px; '
				CSSText += 'overflow:hidden; z-index:10000; }'
				CSSText += '#' + this.id + 'Container, #' + this.id + 'Content { position:absolute; '
				CSSText += 'width:' + Breite + 'px; '
				CSSText += 'height:' + Hoehe + 'px; '
				CSSText += 'clip:rect(0 ' + Breite + ' ' + Hoehe + ' 0); '
				CSSText += '}'
				//CM wg. Rahmen und versch. Hoehen in NN
				CSSText += '#' + this.id + 'Container { '
				CSSText += 'height:' + eval(Hoehe + 15) + 'px; '
				CSSText += 'width:' + eval(Breite + 2) + 'px;} '

				CSSText += '#' + this.id + 'Content { '
				CSSText += 'height:' + eval(Hoehe + 13) + 'px;} '



				this.css = CSSText;
				this.load()
		}
}
ScrollMenue.schreibeCSS = function() {
		document.writeln('<style type="text/css">');
		for (var id in ScrollMenue.Registrierung) {
				document.writeln(ScrollMenue.Registrierung[id].css);
		}
		document.writeln('</style>');
}
ScrollMenue.prototype.load = function() {
		var d = document
		var EbeneID1 = this.id + "Container"
		var EbeneID2 = this.id + "Content"
		var obj1 = this.dom ? d.getElementById(EbeneID1) : this.ie ? d.all[EbeneID1] : d.layers[EbeneID1]
		if (obj1) var obj2 = this.ns4 ? obj1.layers[EbeneID2] : this.ie ? d.all[EbeneID2] : d.getElementById(EbeneID2)
		var temp
		if (!obj1 || !obj2) window.setTimeout(this.Referenz + ".load()", 100)
		else {
				this.container = obj1
				this.menu = obj2
				this.Stil = this.ns4 ? this.menu : this.menu.style
				this.AusgangsPosition = eval("0" + this.RichtungTyp + this.Dimension)
				this.AussenPosition = 0
				this.Beschleunigung = (this.AussenPosition - this.AusgangsPosition) / ScrollMenue.AnimationLaenge / ScrollMenue.AnimationLaenge
				// set event handlers.
				if (this.ns4) this.menu.captureEvents(Event.MOUSEOVER | Event.MOUSEOUT);
				this.menu.onmouseover = new Function("ScrollMenue.ZeigeMenue('" + this.id + "')")
				this.menu.onmouseout = new Function("ScrollMenue.VersteckeMenue('" + this.id + "')")
				//set initial state
				this.BeendeBewegung()
		}
}
ScrollMenue.ZeigeMenue = function(id) {
		var reg = ScrollMenue.Registrierung
		var obj = ScrollMenue.Registrierung[id]
		if (obj.container) {
				obj.ueber = true
				for (menu in reg) if (id != menu) ScrollMenue.Verstecke(menu)
				if (obj.VersteckeTimer) { reg[id].VersteckeTimer = window.clearTimeout(reg[id].VersteckeTimer) }
				if (!obj.oeffne && !obj.AnimationsTimer) reg[id].StarteBewegung(true)
		}
}
ScrollMenue.VersteckeMenue = function(id) {
		var obj = ScrollMenue.Registrierung[id]
		if (obj.container) {
				if (obj.VersteckeTimer) window.clearTimeout(obj.VersteckeTimer)
				obj.VersteckeTimer = window.setTimeout("ScrollMenue.Verstecke('" + id + "')", ScrollMenue.VersteckenDauer);
		}
}
ScrollMenue.VersteckeAlle = function() {
		var reg = ScrollMenue.Registrierung
		for (menu in reg) {
				ScrollMenue.Verstecke(menu);
				if (menu.VersteckeTimer) window.clearTimeout(menu.VersteckeTimer);
		}
}
ScrollMenue.Verstecke = function(id) {
		var obj = ScrollMenue.Registrierung[id]
		obj.ueber = false
		if (obj.VersteckeTimer) { window.clearTimeout(obj.VersteckeTimer); RestoreOrg(); }
		obj.VersteckeTimer = 0
		if (obj.oeffne && !obj.AnimationsTimer) obj.StarteBewegung(false)
}
ScrollMenue.prototype.StarteBewegung = function(oeffne) {
		this[oeffne ? "onactivate" : "ondeactivate"]()
		this.oeffne = oeffne
		if (oeffne) this.Sichtbarkeit(true)
		this.StartZeit = (new Date()).getTime()
		this.AnimationsTimer = window.setInterval(this.Referenz + ".Bewegung()", ScrollMenue.Prozessor)
}
ScrollMenue.prototype.Bewegung = function() {
		var elapsed = (new Date()).getTime() - this.StartZeit
		if (elapsed > ScrollMenue.AnimationLaenge) this.BeendeBewegung()
		else {
				var d = Math.round(Math.pow(ScrollMenue.AnimationLaenge - elapsed, 2) * this.Beschleunigung)
				if (this.oeffne && this.RichtungTyp == "-") d = -d
				else if (this.oeffne && this.RichtungTyp == "+") d = -d
				else if (!this.oeffne && this.RichtungTyp == "-") d = -this.Dimension + d
				else d = this.Dimension + d
				this.BewegeNach(d)
		}
}
ScrollMenue.prototype.BeendeBewegung = function() {
		this.AnimationsTimer = window.clearTimeout(this.AnimationsTimer)
		this.BewegeNach(this.oeffne ? this.AussenPosition : this.AusgangsPosition)
		if (!this.oeffne) this.Sichtbarkeit(false)
		if ((this.oeffne && !this.ueber) || (!this.oeffne && this.ueber)) {
				this.StarteBewegung(this.ueber)
		}
}
ScrollMenue.prototype.Sichtbarkeit = function(bShow) {
		var s = this.ns4 ? this.container : this.container.style
		s.visibility = bShow ? "visible" : "hidden"
}
ScrollMenue.prototype.BewegeNach = function(p) {
		this.Stil[this.Orientierung == "h" ? "Links" : "top"] = this.ns4 ? p : p + "px"
}
ScrollMenue.prototype.HolePosition = function(c) {
		return parseInt(this.Stil[c])
}
ScrollMenue.prototype.onactivate = function() { }
ScrollMenue.prototype.ondeactivate = function() { }

function RestoreOrg() {
		var i, x, a = document.MM_sr; for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++) x.src = x.oSrc;
}

