//
// Modulare DHTML Navigation 2.0
// -----------------------------
// © 2002
// 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
if ((navigator.appName == 'Netscape') && (navigator.appVersion.charAt(0) == '4')) NETSCAPE = true
//var NETSCAPE=(document.layers)

var activatedLayer=null
var XWIN=null
var isMac=(navigator.userAgent.toLowerCase().indexOf("mac")>-1)
var maxBrowserWidth = 1020
var maxBrowserHeight = 620
var minBrowserWidth = 800
var minBrowserHeight = 450
var origin_x=0
var origin_y=0
var DEBUG=false
var NAVI

function lineFlagObject(nr,x,y){
 this.LINE=new stretchLayerObj("LINE"+nr, 0, y, 1033, 1,false)
 this.layer=null
 this.x=x
 this.y=y
 this.id=nr+2000
 this.move=move
 this.stretchXFull=stretchXFull
 this.visible=true
 this.hide=hide
 this.show=show
 this.reset=reset
 this.active=false
 
 // ANIMATION
 this.action_sx=0
 this.action_sy=0
 this.action_step=0
 this.RunAction=RunAction
 this.doRunAction=doRunAction
 
 function RunAction(x2,y2,steps){
  this.action_sx=(x2-this.x)/steps
  this.action_sy=(y2-this.y)/steps
  this.action_step=steps
  this.doRunAction()
 }

 function doRunAction(){
  if (this.action_step>0){
   this.action_step--
   this.move(this.x+this.action_sx,this.y+this.action_sy)   
   setTimeout("LINE"+(this.id-2000)+".doRunAction()",20)
  }
 }
 
 
 function stretchXFull(){this.LINE.stretchXFull()}
 
 function move(x,y){
  this.LINE.move(y+14)
  if (NETSCAPE) this.layer.moveTo(x,y)
  else {this.layer.left=x;this.layer.top=y}
  this.x=x
  this.y=y
 }
 function hide() {
  this.LINE.hide()
  this.visible=false
  if (NETSCAPE) this.layer.visibility = "hide"
  else this.layer.visibility = "hidden"
 }
 function show() {
  this.LINE.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()
 }

 //KONSTRUKTOR
 if (NETSCAPE) {
  this.layer=document.layers["L"+this.id+"L"]
  this.layer.width=1033
  this.layer.height=1
 }
 else if (document.all) this.layer=eval('document.all.L' + this.id + 'L.style')
 else if (document.getElementsByName) this.layer=document.getElementById("L" + this.id + "L").style
 this.move(x,y)
}

function navigationOBJ(startPOS,opos){
 this.y=opos
 this.startPOS=startPOS
 this.naviTop=startPOS
 this.movenavi=0 

 this.chaseInit=chaseInit
 this.chase=chase
 this.chaseRate=20
 this.chaser=null
 this.moveTime = 1200
 this.distance=0
 this.factor=0
 this.currPos=0
 this.target=0
 this.oldTime=null
 this.offSet=0
 this.start=start
 
 this.moveDecelerating=moveDecelerating
 this.move=move
 this.NAVIBOX=null

 function moveDecelerating( ) {
  var now = new Date()
  var newPos = this.distance * Math.sin( this.factor * ( now.getTime() - this.oldTime )) + this.offSet
  newPos = Math.round( newPos )
  if( this.distance > 0 && newPos > this.currPos || this.distance < 0 && newPos < this.currPos )
  this.move(this.y+(newPos-this.currPos) )
  return false
 }
 function move(y){
  this.y=y
  if ( browser.isNav4 )  this.NAVIBOX.moveTo( 0, y)
  else if( browser.isIE ) {this.NAVIBOX.pixelTop = y}
  else if( browser.isW3C )  {this.NAVIBOX.top = y}

 }

 function start(){
  if ( browser.isNav4 ) this.NAVIBOX = document.layers["NAVIBOX"]
  else if( browser.isIE ) this.NAVIBOX = eval('document.all.NAVIBOX.style')
  else if( browser.isW3C ) this.NAVIBOX = document.getElementById("NAVIBOX").style
  this.chaser=window.setInterval("navigation.chase()", this.chaseRate)
 }
 function chaseInit() {
  var now = new Date()
  this.distance = this.target - this.currPos
  this.factor = Math.PI / ( 2 * this.moveTime )
  this.oldTime = now.getTime( )
  var maxDiff = browser.getInnerHeight()
  this.offSet = this.currPos
 }
 function chase() {
  this.currPos = this.y
  this.naviTop=this.startPOS-browser.getScrollTop()
  if (this.naviTop<10)this.naviTop=10
  if (this.naviTop>this.startPOS)this.naviTop=this.startPOS
  //var newTarget = browser.getScrollTop()+this.naviTop
  var newTarget = this.naviTop
  if( this.currPos != newTarget) {
   if( newTarget != this.target ) {
    this.target = newTarget
    this.chaseInit()
   }
   this.moveDecelerating()
  }
  //Line0 und Line1 bei Scrolling ausblenden
  if (SHOWLINES=="PORTAL")
  {
    if ((browser.getScrollTop()>0)&&(LINE0.visible||LINE1.visible)){LINE0.hide();LINE1.hide()}
    if ((browser.getScrollTop()==0)&&(!LINE0.visible||!LINE1.visible)){LINE0.show();LINE1.show()}
  }
 this.movenavi=1
 }

}

function stretchLayerObj( id, left, top, width, height,navibox ) {
 this.visible=true
 this.navibox=navibox
 this.id = id
 this.left = left
 this.top = top
 this.width = width
 this.height = height
 this.layer = null
 this.nummer = null
 this.y=0
 this.changeWidth = changeWidth
 this.stretchX = stretchX
 this.stretchXFull = stretchXFull
 this.move = move
 this.hide = hide
 this.show = show
 this.reset = reset
 

 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.y)
  if (this.visible) this.show()
 }

 function changeWidth() {
  if( browser.isNav4 )this.layer.clip.width = this.width
  else this.layer.width = this.width
  return false
 }
 function stretchX() {
  var innerWidth = browser.getInnerWidth()
  if( innerWidth  > maxBrowserWidth ) innerWidth = maxBrowserWidth
  else if( innerWidth  < minBrowserWidth ) innerWidth = minBrowserWidth
  this.width = innerWidth - this.left
  this.changeWidth()
 }
 function stretchXFull() {
  this.width = browser.getInnerWidth() - this.left-(isMac?15:0)
  this.changeWidth()
 }
 function move(y) {
  this.y=y
  if ( browser.isNav4 ) this.layer.moveTo( this.left, y)
  else if( browser.isIE ) {this.layer.pixelTop = y}
  else if( browser.isW3C )  {this.layer.top = y}
  return false
 }
 
  if ( browser.isNav4 ) {
  if (this.navibox) this.layer = document.layers["NAVIBOX"].document.layers[this.id]
  else this.layer = document.layers[this.id]
 }
 else if( browser.isIE ) this.layer = eval('document.all.' + this.id + '.style')
 else if( browser.isW3C ) this.layer = document.getElementById(this.id).style
}

//_________________________________________________________________________________________________________________
//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 "GO":setTimeout("gotoPage('"+part[1]+"')",500);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["NAVIBOX"].document.layers["L"+this.id+"L"]
  this.layer.width=width
  this.layer.height=height
 }
 else if (document.all) this.layer=eval('document.all.L' + this.id + 'L.style')
 else if (document.getElementsByName) this.layer=document.getElementById("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
} 


//_________________________________________________________________________________________________________________
//MAUSEVENTS
function getMouse(e) {
 if (document.all){
  mouseX = event.clientX + document.body.scrollLeft
  mouseY = event.clientY + document.body.scrollTop
 }
 
 else if ((document.layers)||(document.getElementsByName)) {mouseX=e.pageX;mouseY=e.pageY}
 mouseY-=navigation.y
 if (isloaded) {
  for (i=0;i<layerList.length;i++) layerList[i].mouseOver()
  if (getLayerByPosition(mouseX,mouseY)==null) {
   status="";hideNonResistent()
   if (NETSCAPE) document.layers["NAVIBOX"].visibility="hide"
  }else {
   if (NETSCAPE) document.layers["NAVIBOX"].visibility="show"
  }
 }
 
}

function doClick(){
 if (isloaded) {
  var tmp=getLayerByPosition(mouseX,mouseY)
  if (tmp!=null) tmp.doClick()
 }
 //if (LINE0.active)LINE0.RunAction(mouseX,mouseY+navigation.y,20)
 //if (LINE1.active)LINE1.RunAction(mouseX,mouseY+navigation.y,20)
}




//_________________________________________________________________________________________________________________
//LOADER
function DHTMLLoad(constructor){
 if ((document.layers)||(document.all)||(document.getElementsByName)) {
  isloaded=true
  
 }
 else {alert("NO VALID BROWSER, EXECUTION ABORTED!")}
} 

// START FUNKTION
function lade(){
 for (i=0;i<layerList.length;i++) layerList[i].reset()
 DHTMLLoad(null)
 isloaded=true
 
 if (NETSCAPE) {
  
  /*for (i=0;i<layerList.length;i++) layerList[i].hide()
  for (i=0;i<layerList.length;i++) layerList[i].show()
  hideNonResistent()
  */
 
 }
 
 NAVI.stretchXFull()
 if (SHOWLINES=="PORTAL")
 {
   LINE0.stretchXFull()
   LINE1.stretchXFull()
 }
 startAni()
 
}
function doResize(){
 for (i=0;i<layerList.length;i++) layerList[i].reset()
 theY=0
 NAVI.stretchXFull()
 
 if (SHOWLINES=="PORTAL")
 {
   LINE0.stretchXFull()
   LINE1.stretchXFull()
 }
 if (NETSCAPE) top.location=top.location+""
 
 
 
}

function showPlane(nr){
 if (NETSCAPE) {
  var l=getLayerByName(nr).layer
  if ((nr>=93)&&(nr<=96)){
      eval("l.document.images.PLANE"+nr+".src="+SHOWPLANE_RED)
  }
  else {
      eval("l.document.images.PLANE"+nr+".src="+SHOWPLANE)
  }
 }else{
  if ((nr>=93)&&(nr<=96)){
   if (document.all) eval("document.all.ELE"+nr+".style.color='#660000'")
   eval("document.images.PLANE"+nr+".src="+SHOWPLANE_RED)
  }
  else{
   eval("document.images.PLANE"+nr+".src="+SHOWPLANE)
   if (document.all) eval("document.all.ELE"+nr+".style.color='#CC0000'")
  }
   
  
 }
 }
function hidePlane(nr){
 if (NETSCAPE) {
  var l=getLayerByName(nr).layer
  if ((nr>=93)&&(nr<=96)){
      eval("l.document.images.PLANE"+nr+".src="+HIDEPLANE_RED)
  }
  else{
      eval("l.document.images.PLANE"+nr+".src="+HIDEPLANE)
  }
 }else{
  if ((nr>=93)&&(nr<=96)){
    eval("document.images.PLANE"+nr+".src="+HIDEPLANE_RED)
    if (document.all) eval("document.all.ELE"+nr+".style.color='#FFFFFF'")
   }
  else{
   eval("document.images.PLANE"+nr+".src="+HIDEPLANE)
   if (document.all) eval("document.all.ELE"+nr+".style.color='#999999'")
  }
 }
 }