//
//	Modulare DHTML Navigation 1.0
//	-----------------------------

//	© 2000

//	norm-4
//	Agentur für Neue Medien GmbH

//	Gutenbergstrasse 63a
//	50823 Köln
//	Tel   +49 (0)221 949 984-0
//	Fax   +49 (0)221 949 984-11

//	info@norm-4.com
//	www.norm-4.com
//
//	_____________________________________________

//	KOMPONENTE "DHTMLnavi.js"

//	beinhaltet notwendige JavaScript-Funktionen, um die
//	Modulare DHTML Navigation auf eine Seite zu
//	integrieren.

//	diese DATEI nicht verändern!!!
//	_____________________________________________


//_________________________________________________________________________________________________________________
//GLOBALE VARIABLEN

var layerList = new Array()
var mouseX = 0
var mouseY = 0
var isloaded=false
var NORMAL=0,ROLLOVER=1,ACTIVATED=2
var NETSCAPE=(document.layers)
var activatedLayer=null
var XWIN=null

var isW3C=false

if (navigator.appName.indexOf("Netscape") != -1 || navigator.appName.indexOf("Opera")!=-1) 
 if (parseInt(navigator.appVersion) >= 5)  isW3C = true  	




	function flug(startX,startY,endX,endY,startT,endT,type,ziel){
		this.startX=startX
		this.startY=startY
		
		this.endX=endX
		this.endY=endY
		this.startT=Date.UTC(startT.getYear(),startT.getMonth(),startT.getDate(),startT.getHours(),startT.getMinutes(),0)
		this.endT=Date.UTC(endT.getYear(),endT.getMonth(),endT.getDate(),endT.getHours(),endT.getMinutes(),0)
		this.gesamt=this.endT-this.startT
		this.getRelPos=getRelPos
		this.moveObject=moveObject
		this.visible=true
		this.type=type
		this.ziel=ziel
		
		if (ziel.zeitzone!=0){
			if (this.type=="A") this.startT=Date.UTC(startT.getYear(),startT.getMonth(),startT.getDate(),startT.getHours()-ziel.zeitzone,startT.getMinutes(),0)
			if (this.type=="D") this.endT=Date.UTC(endT.getYear(),endT.getMonth(),endT.getDate(),endT.getHours()-ziel.zeitzone,endT.getMinutes(),0)
		}

		
		function getRelPos(){
						
			
			
			
			
			var now = new Date();
			now = Date.UTC(now.getYear(),now.getMonth(),now.getDate(),now.getHours(),now.getMinutes(),0)

			
			
			if ( ( now < this.endT ) && ( now > this.startT )) {
			    return (now-this.startT)/this.gesamt
			}else{
			    return 0
			}
		}
		
		
		function moveObject(obj,opx,opy){
			if (this.visible){
				var rp=this.getRelPos()
				if (rp>0){
					var dx=Math.round((this.endX-this.startX)*rp)
					var dy=Math.round((this.endY-this.startY)*rp)
					obj.move(opx+this.startX+dx,opy+this.startY+dy)
				}else {
					obj.hide()
					this.visible=false
					
				}
			}
		}
	
	}


	
	
  

//_________________________________________________________________________________________________________________
//UNIVERSAL LAYER OBJECT
function layerObject(name, id, left, top, width, height, visible, rollover,activatable,standard,mouseenter,mouseexit,mouseclick,resistent,rotext,ebene) {



	//STANDARDVARIABLEN
	this.layer=null
	this.id=id
	this.width=width
	this.height=height
	this.name=name
	this.ebene=ebene
	this.mouseenter=mouseenter
	this.mouseexit=mouseexit
	this.mouseclick=mouseclick
	this.rollover=rollover
	this.standard=standard
	this.activatable=activatable

	//VARIABLEN ZUR ZUSTANDSSPEICHERUNG
	this.visible=visible	
	this.x=left
	this.y=top
	this.clipleft=0
	this.cliptop=0
	this.clipright=width
	this.clipbottom=height
	this.status=NORMAL
	this.resistent=resistent	
	this.ox=left
	this.oy=top
	this.rotext=rotext

	
	//FUNTIONEN
	this.hide=hide
	this.reset=reset
	this.show=show
	this.move=move
	this.clip=clip
	this.getzIndex=getzIndex
	this.setzIndex=setzIndex
	this.bringToFront=bringToFront
	this.sendToBack=sendToBack
	this.mouseOver=mouseOver
	this.swapClip=swapClip
	this.doClick=doClick
	this.inside=inside
	this.normalize=normalize
	this.handle_mouseexit=handle_mouseexit
	this.handle_mouseenter=handle_mouseenter
	this.toggleResistence=toggleResistence
	

	//MOVE ANIMATION
	this.swapped=false





	function execute_cmd(parameter){
		var cmd=parameter.split(";")
		for (var i=0;i<cmd.length;i++){
			var part=cmd[i].split(":")
			switch (part[0]) {

				case "SH":{var idlist=part[1].split(",");for (var j=0;j<idlist.length;j++) getLayerByID(idlist[j]).show();}break
				case "HD":{var idlist=part[1].split(",");for (var j=0;j<idlist.length;j++) getLayerByID(idlist[j]).hide();}break
				case "HDLV":{var idlist=part[1].split(",");for (var j=0;j<idlist.length;j++) hideEbene(idlist[j]);}break
				case "HDBLV":{var idlist=part[1].split(",");for (var j=0;j<idlist.length;j++) hideBiggerEbene(idlist[j]);}break
				
				case "SHBN":{var idlist=part[1].split(",");for (var j=0;j<idlist.length;j++) getLayerByName(idlist[j]).show();}break
				case "HDBN":{var idlist=part[1].split(",");for (var j=0;j<idlist.length;j++) getLayerByName(idlist[j]).hide();}break
				case "TR":{var idlist=part[1].split(",");for (var j=0;j<idlist.length;j++) getLayerByID(idlist[j]).toggleResistence();}break
				case "TRBN":{var idlist=part[1].split(",");for (var j=0;j<idlist.length;j++) getLayerByName(idlist[j]).toggleResistence();}break
				case "HDNR":hideNonResistent();break;
				case "JS":eval(part[1]);break;
				case "MAIL":window.location="mailto:"+part[1];break;
				case "GO":setTimeout("gotoPage('"+part[1]+"')",500);break;
				case "LINK":
					if (XWIN==null) XWIN=window.open("http://"+part[1])
					else {
						if (XWIN.closed) XWIN=window.open("http://"+part[1])
						else{
							XWIN.location="http://"+part[1]
							XWIN.focus()
						}
					}break;
			}
		}
	}

	function handle_mouseenter(){
		if (this.visible)
			if (this.mouseenter!="") 
				execute_cmd(this.mouseenter)
	}
	function handle_mouseexit(){
		if (this.visible)
			if (this.mouseexit!="") 
				execute_cmd(this.mouseexit)
	}
	
	function toggleResistence(){
		if (this.resistent) {
			this.resistent=false
			this.hide()
		}else{
			this.resistent=true
			this.show()
		}
	
	}
	
	function doClick(){
		if (this.activatable){
			if (activatedLayer!=this) {
				if (activatedLayer!=null) activatedLayer.normalize()
				activatedLayer=this
				this.status=ACTIVATED
				if (this.standard) this.swapClip(true)
			}
			
		}
		if ((this.mouseclick!="")&&(this.visible)) execute_cmd(this.mouseclick)
	}
	
	function normalize(){
		this.status=NORMAL
		if (this.standard){
			this.swapClip(false)
		}
	}


	function inside(mx,my){
		var rw=false
		if (this.standard) rw=((this.x<=mx)&&(this.x+this.width/2>mx)&&(this.y<=my)&&(this.y+this.height>my))
		else rw=((this.x<=mx)&&(this.x+this.width>mx)&&(this.y<=my)&&(this.y+this.height>my))
		return rw
	}

	function mouseOver(){
		if (this.inside(mouseX,mouseY)){
			if ((getLayerByPosition(mouseX,mouseY)==this)&&(this.visible)&&(this.status!=ROLLOVER)) {
				this.handle_mouseenter()
				if ((this.rollover)&&(this.standard)&&(activatedLayer!=this))this.swapClip(true)
				if (this.standard) status=this.rotext
				if (DEBUG) status=this.name
				this.status=ROLLOVER
			}
		}
		else{
			if ((this.status!=NORMAL)&&(this.status!=ACTIVATED)){
				if ((this.rollover)&&(this.standard)){
					if (activatedLayer!=this) this.swapClip(false)
				}
				this.status=NORMAL
				this.handle_mouseexit()
			}
		}
		
	}

	function hide() {
		this.visible=false
		if (NETSCAPE) this.layer.visibility = "hide"
		else this.layer.visibility = "hidden"
	}

	function show() {
		this.visible=true
		if (NETSCAPE) this.layer.visibility = "show"
		else this.layer.visibility = "visible"
	}


	function reset(){
		this.move(this.ox+origin_x,this.oy+origin_y)
		if (this.visible) this.show()
	}

  	function move(x,y) {
  		if (this.swapped){
  			if (NETSCAPE) this.layer.moveTo(x-this.width/2,y);
			else {this.layer.left=x-this.width/2;this.layer.top=y}
  		}

		else {
			if (NETSCAPE) this.layer.moveTo(x,y);
			else {this.layer.left=x;this.layer.top=y}
		}
		this.x=x
		this.y=y
	}

	function clip(a1,b1,a2,b2) {

		this.clipleft=a1
		this.cliptop=b1
		this.clipright=a2
		this.clipbottom=b2
		if (NETSCAPE) {
			this.layer.clip.left   = a1
			this.layer.clip.top    = b1
			this.layer.clip.right  = a2
			this.layer.clip.bottom = b2
		}
		else this.layer.clip = 'rect(' + b1 + ' ' +  a2 + ' ' + b2 + ' ' + a1 +')'
	}

	function getzIndex(){return this.layer.zIndex}
	
	function setzIndex(z){this.layer.zIndex=z}

	function  bringToFront(){
		var i, temp
		layerList.sort(sortzIndex)
		i = layerList.length - 1
		temp = layerList[i].getzIndex()
		while (i > 0 && layerList[i] != this.layer) {
			layerList[i].setzIndex(layerList[i-1].getzIndex())
			i--
		}
		this.setzIndex(temp)
		layerList.sort(sortzIndex)
	}

	function sendToBack() {
		var i, temp
		layerList.sort(sortzIndex)
		i = 0
		temp = layerList[i].getzIndex();
		while (i < layerList.length - 2 && layerList[i] != this.layer) {
			layerList[i].setzIndex(layerList[i+1].getzIndex())
			i++
		}
		this.setzIndex(temp)
		layerList.sort(sortzIndex)
	}


	function swapClip(aktiviert){
		this.swapped=aktiviert
		if (aktiviert) {
			this.clip(this.width/2,0,this.width,this.height)
			this.move(this.x,this.y)
			
			}
		else {
			this.clip(0,0,this.width/2,this.height)
			this.move(this.x,this.y)
		}
	}

	//KONSTRUKTOR
	if (NETSCAPE) {
		this.layer=document.layers["L"+this.id+"L"]
		this.layer.width=width
		this.layer.height=height
	}
	else if (isW3C) this.layer=eval('document.getElementById("L'+this.id+'L").style')
	else this.layer=eval('document.all.L' + this.id + 'L.style')
	//if (this.visible) this.show()
	this.setzIndex(layerList.length)

	if (this.standard) this.swapClip(false)
	else this.clip(0,0,this.width,this.height)
	
	

	layerList[layerList.length]=this
}

//_________________________________________________________________________________________________________________
//HILFSROUTINEN

function getLayerByPosition(x,y){
	//alle objekte sammeln
	var tmp=new Array()
	for (var i=0;i<layerList.length;i++) 
		if (layerList[i].inside(x,y))
			tmp[tmp.length]=layerList[i]
	//oberstes zurueck
	var rw=null
	if (tmp.length>0) {
		var i=tmp.length-1
		do {rw=tmp[i];i--}while ((!rw.visible)&&(i>=0))
	}
	return rw
}

function hideNonResistent(){
	for (i=0;i<layerList.length;i++) if (!layerList[i].resistent)  {
		layerList[i].hide()
	}
}
function hideEbene(name){
	for (var i=0;i<layerList.length;i++) if (layerList[i].ebene==name) layerList[i].hide()
}

function hideBiggerEbene(ebene){
	for (var i=0;i<layerList.length;i++) if (layerList[i].ebene>ebene) layerList[i].hide()
}



function getLayerByName(name){
	for (var i=0;i<layerList.length;i++) if (layerList[i].name==name) return layerList[i]
	return null
}



function getLayerByID(ID){
	ID=ID*1
	for (var i=0;i<layerList.length;i++) if (layerList[i].id==ID) return layerList[i]
	alert("Layer "+ID+" not found!")
	return null
}

function sortzIndex(a, b) {return a.getzIndex()-b.getzIndex()}

function fill(tmp,anz) {
	tmp=tmp+""
	while (tmp.length<anz) tmp="0"+tmp
	return tmp
}	


var isStart=true

//_________________________________________________________________________________________________________________
//MAUSEVENTS

function getMouse(e) {
	if (document.layers||isW3C) {
		mouseX=e.screenX
		mouseY=e.pageY
	}
	if (document.all){
		mouseX = event.clientX + document.body.scrollLeft
		mouseY = event.clientY + document.body.scrollTop
	
	}

	
	
	
	if (isloaded) {
		for (i=0;i<layerList.length;i++) layerList[i].mouseOver()
		if (getLayerByPosition(mouseX,mouseY)==null) {if (!isStart)hideNonResistent()}
		else {if (getLayerByPosition(mouseX,mouseY).visible)isStart=false;}
	}
	

	
}


function doClick(){
	if (isloaded) {
		var tmp=getLayerByPosition(mouseX,mouseY)
		if (tmp!=null) tmp.doClick()
	}
}

/*
scrollTimer=null
var theY=0
var stillcounter=0
var hasMoved=false
function checkScroll(){
	var y=browser.getScrollTop()
	if (y!=theY) {
		stillcounter=0
		hasMoved=true
		theY=y
		
	}else {
		if (hasMoved){
			stillcounter++
			if (stillcounter>3) {
				move(0,theY+origin_y)
				hasMoved=false
			}
		}
	}
	scrollTimer=setTimeout("checkScroll()",50)
}

*/

browser.addMouseMoveEvent("getMouse")
browser.addMouseDownEvent("doClick")



//_________________________________________________________________________________________________________________
//LOADER

function DHTMLLoad(constructor){

	if ((document.layers)||(document.all)||isW3C) {
		isloaded=true
		
	}
	else {alert("NO VALID BROWSER, EXECUTION ABORTED!")}
}	





//_________________________________________________________________________________________________________________
//CONNECT COLOGNE





	var origin_x=0
	var origin_y=0

	var mitte_x=0
	var mitte_y=0
	var d_x=0
	var d_y=0
	var karte,raster
	var hor_lat
	var ver_lat
	

	var max_x=0
	var max_y=0


	var DEBUG=false

	var ghTID=null
	var homing=false

	function goHome(){
		var dx=0
		var dy=0
		if (move_dir>0) {
			ghTID=setTimeout("goHome(),20")
			homing=true
		}
		else {
			 if ((oposX!=-500)||(oposY!=-700)){
				dx=((-500)-oposX)/10
				dy=((-700)-oposY)/10
			 }
			 moveAll(dx,dy)
			 dx=((-500)-oposX)
			 dy=((-700)-oposY)
			 
			 d=Math.round(Math.sqrt(dx*dx+dy*dy))
			 if (d<3) {moveAll(dx,dy);homing=false}
			 else {
			 	ghTID=setTimeout("goHome(),20")
			 	homing=true
			 }
		}

	
	}




	function initPos() {
		mitte_x=browser.getInnerWidth()/2
		mitte_y=browser.getInnerHeight()/2

		d_x=browser.getInnerWidth()/20
		d_y=browser.getInnerHeight()/15

		max_x=KARTE_DIM_X-browser.getInnerWidth()
		max_y=KARTE_DIM_Y-browser.getInnerHeight()
		
		hor_lat.move(0,browser.getInnerHeight()-20)
		ver_lat.move(5,0)
		
		if (!nofunc){
			var rechteAbdeckung=getLayerByID(1002)
			rechteAbdeckung.move(browser.getInnerWidth()-511,75)
			rechteAbdeckung.show()
		}
	
	
	
		oposX=-500
		oposY=-700
		
		//objekte auf start
		/*
		for (i=300;i<WEATHER_COUNT;i++){
			obj=getLayerByID(i)
			obj.move(obj.x+oposX,obj.y+oposY)
		}*/

		//objekte auf start
		for (i=20;i<=25;i++){
			obj=getLayerByID(i)
			obj.move(obj.x+oposX,obj.y+oposY)
		}		
		
		
		for (i=10;i<19;i++) {
			obj=getLayerByID(i)
			obj.move(obj.x,obj.y+browser.getInnerHeight()-200)
		}
		
		obj=getLayerByID(19)
		obj.move(obj.x,obj.y+browser.getInnerHeight()-180)
		obj.show()

		//alert(browser.getInnerWidth())
		moveAll(0,0)
		
		//getLayerByID(500).move(browser.getInnerWidth()-165,43)
		//getLayerByID(500).setzIndex(3000)
		//getLayerByID(500).show()

		
		
	
	}


	var languageSelection

	// START FUNKTION
	function lade(){
		for (i=0;i<layerList.length;i++) layerList[i].reset()
		DHTMLLoad(null)
		isloaded=true
		karte=getLayerByID(1)
		raster=getLayerByID(2)
		hor_lat=getLayerByID(200)
		ver_lat=getLayerByID(201)
		
		initPos()
		running()
		
		
		
	}



	var oposX=0
	var oposY=0


	//var fakeDate=new Date()
	//myFlug1=new flug(950,1250,1470,1850,new Date(fakeDate.getYear(),fakeDate.getMonth(),fakeDate.getDate(),fakeDate.getHours(),fakeDate.getMinutes(),0),new Date(fakeDate.getYear(),fakeDate.getMonth(),fakeDate.getDate(),fakeDate.getHours(),fakeDate.getMinutes()+2,0))
	//myFlug2=new flug(1470,1850,950,1250,new Date(fakeDate.getYear(),fakeDate.getMonth(),fakeDate.getDate(),fakeDate.getHours(),fakeDate.getMinutes(),0),new Date(fakeDate.getYear(),fakeDate.getMonth(),fakeDate.getDate(),fakeDate.getHours(),fakeDate.getMinutes()+1,0))

	function moveAll(x,y){
		/*for (i=300;i<WEATHER_COUNT;i++){
			obj=getLayerByID(i)
			obj.move(obj.x+x,obj.y+y)
		}*/
		
		for (i=20;i<=25;i++){
			obj=getLayerByID(i)
			obj.move(obj.x+x,obj.y+y)
		}
		
		oposX+=x
		oposY+=y
		karte.move(oposX,oposY)
		raster.move(oposX,oposY)

		hor_lat.move(oposX,browser.getInnerHeight()-20)				
		ver_lat.move(5,oposY)
		

	}


	function moveIt(d){
		//status=d+" "+(beschleunigt?"beschleunigt":"")+(haelt_an?"haelt_an":"")
		switch(move_dir){
			case 4:if (karte.x>-max_x)moveAll(-d,0);else MovingStatus=0;break; //links
			case 8:if (karte.y>-max_y)moveAll(0,-d);else MovingStatus=0;break; //hoch
			case 1:if (karte.x<0)moveAll(d,0);else MovingStatus=0;break; //rechts
			case 2:if (karte.y<0) moveAll(0,d);else MovingStatus=0;break; //runter

			case 12:	//links hoch
				if (karte.x>-max_x)moveAll(-d,0);
				if (karte.y>-max_y)moveAll(0,-d);
				break;
			case 9:	//rechts hoch
				if (karte.x<0)moveAll(d,0);
				if (karte.y>-max_y)moveAll(0,-d);
				break;

			case 6:	//links runter
				if (karte.x>-max_x)moveAll(-d,0);
				if (karte.y<0) moveAll(0,d);break;
				break;

			case 3:	//rechts runter
				if (karte.x<0)moveAll(d,0);
				if (karte.y<0) moveAll(0,d);break;
				break;


		}

	}



	var  factor = Math.PI/2/800
	function Speed(d,bremsen) {
		
		var newPos
		var delta = (new Date()).getTime() -oldTime
		if (delta>800)delta=800
		if (bremsen) newPos = Math.sin(Math.PI/2-factor * delta) 
		else newPos = Math.sin(factor * delta) 
		return Math.round(newPos*d)
	}

	
	
	//var haelt_an=false
	//var beschleunigt=false
	
	var move_dir=0

	var isOutside
	var MovingStatus=0
	var oldTime=null
	var last_speed=0
	var isRunning=false
	function running(){
		
		//if (karte.visible) karte.hide()
		//else karte.show()
	
		var ok=false
		isOutside=false
		/*
		var md=0
		if (mouseX<d_x) md=md|1
		if (mouseY<d_y) md=md|2
		if (mouseX>browser.getInnerWidth()-d_x) md=md|4
		if (mouseY>browser.getInnerHeight()-d_y) md=md|8
		*/
		var md=0
		switch(MAINmovedir){
			case 1:md=1;break;
			case 2:md=3;break;
			case 3:md=2;break;
			case 4:md=6;break;
			case 5:md=4;break;
			case 6:md=12;break;
			case 7:md=8;break;
			case 8:md=9;break;
		}
	
		
			
		if (md>0) {
			ok=false
			//kann nur neu werden,
			//wenn nicht in bewegung, oder benachbart
			if (MovingStatus==0) {ok=true;oldTime=(new Date()).getTime();}
			
			if ((MovingStatus<=2)&&(!homing)) {
			
				switch(move_dir){
					case 1:if (md==3||md==9)ok=true;break;
					case 2:if (md==3||md==6)ok=true;break;
					case 4:if (md==12||md==6)ok=true;break;
					case 8:if (md==12||md==9)ok=true;break;
					case 9:if (md==8||md==1)ok=true;break;
					case 3:if (md==2||md==1)ok=true;break;
					case 6:if (md==4||md==2)ok=true;break;
					case 12:if (md==4||md==8)ok=true;break;

				}
				/*
				if (move_dir==md) {
					ok=true
					if (ghTID)window.clearTimeout(ghTID);
				}
				*/


				if (ok){
					move_dir=md
					MovingStatus=1	
				}
			} 
		
		}
		else {isOutside=true;isRunning=true}

		

		

		if (isRunning){
		
		
			var speed=0

			if (!isOutside&&MovingStatus==1){
				//beschleunigen
				
				
				last_speed=speed=Speed(10,false)
			}else {
				//status=MovingStatus
				if (MovingStatus>0){
					//abbremsen
					if (MovingStatus==1){
						MovingStatus=2
						oldTime=(new Date()).getTime()
					}
					speed=Speed(last_speed,true)
					if (speed<1) {
						MovingStatus=0
						move_dir=0
					}
				}
			}
			if (MovingStatus>0) moveIt(speed)
			for (i=0;i<fluege.length;i++) fluege[i].moveObject(getLayerByID(i+100),oposX,oposY)

		}


	
		
		setTimeout("running()",20)
	}


	function setFlugsucheSize(size) {
		if (!isNaN(size)) {
			switch(size) {
			case 1:
				menuResizeWindow(2,630, 390);
				break;
			case 2:
				menuResizeWindow(2,630, 540);
				break;
			case 3:
				menuResizeWindow(2, 630, 600);
				break;
			}
		}
	}
