
/**********************************************************************************
FoldoutMenu
*   Copyright (C) 2001 Thomas Brattli
*   This script was released at DHTMLCentral.com
*   Visit for more great scripts!
*   This may be used and changed freely as long as this msg is intact!
*   We will also appreciate any links you could give us.
*
*   Made by Thomas Brattli
*
*   Script date: 09/04/2001 (keep this date to check versions)
*
*   Major changes by AVIMA 28/04/2002 (www.avima.de)
*********************************************************************************/

/*--- variables you can configure ---*/
var FoldNumber  = 1;            /* How many toplinks do you have? */
var stayFolded  = false;        /* Stay open when you click a new toplink? */
var foldImg     = false;        /* Do you want images (if not set to false and remove the images from the body)? */
var mainOffsetY = 10;           /* Vertical space adjustment between the main items, in pixels. */
var Fcolor      = 'blue';       /* color */    


/*--- global vars for foldout ---*/
var px = "";                    /* A unit of measure that will be added when setting the position of a layer. */
var unImg = new Image();        /* This is the default image. */
var exImg = new Image();        /* this is the source of the image that it changes to when the menu expands. */

/*--- global vars for rollover ---*/
var hiSrc = new Image();
var loSrc = new Image();

/*--- global vars for locking ---*/
var check   = "";
var uncheck = "";
var lastNum = "0";
var locked  = "";
var topLayerLocked = "";
var subLayerLocked = "";

/*--- Browsercheck ---*/
function lib_bwcheck()
{ 
  this.ver=navigator.appVersion;
  this.agent=navigator.userAgent;
  this.dom=document.getElementById?1:0;
  this.opera5=(navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?1:0;
  this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
  this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
  this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
  this.ie=this.ie4||this.ie5||this.ie6;
  this.mac=this.agent.indexOf("Mac")>-1;
  this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
  this.ns4=(document.layers && !this.dom)?1:0;
  this.bw=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.opera5);

  
  var px = ( bw.ns4 || window.opera ) ? "" : "px";

  return this;
}


// NOTE: if you change the position of divCont from absolute to relative, you can put the foldoutmenu in a table.
// HOWEVER it will no longer work in netscape 4. If you wish to support netscape 4, you have to use absolute positioning.

/*** There should be no need to change anything beyond this. ***/

/*--- object constructor... ---*/
function makeMenu( obj, nest )
{
  this.el  = bw.ie4 ? document.all[obj] : bw.ns4 ? nest.layers[obj] : document.getElementById(obj);
  this.css = bw.ns4 ? this.el : this.el.style;
  this.ref = bw.ns4 ? this.el.document: document;
  this.x   = (bw.ns4||bw.opera5) ? this.css.left : this.el.offsetLeft;
  this.y   = (bw.ns4||bw.opera5) ? this.css.top  : this.el.offsetTop;
  this.h   = (bw.ie||bw.ns6) ? this.el.offsetHeight : bw.ns4 ? this.ref.height : bw.opera5 ? this.css.pixelHeight : 0;
  this.vis = b_vis;
  this.hideIt = b_hideIt;
  this.showIt = b_showIt;
  this.moveIt = b_moveIt;
  
  return this
}
//object methods...
function b_showIt(){ this.css.visibility = 'visible' }
function b_hideIt(){ this.css.visibility = 'hidden'  }
function b_vis()   { if(this.css.visibility=='hidden' || this.css.visibility=='HIDDEN' || this.css.visibility=='hide') return true;}
function b_moveIt(x,y){this.x=x; this.y=y; this.css.left=this.x+px; this.css.top=this.y+px}

/************************************************************************************
This is the function that changes the sub menus to folded or unfolded state.
************************************************************************************/
function menu(num)
{
  if(bw.bw)
  {
    if ( !stayFolded )
    {
      for (var i=0; i<oSub.length; i++)
      {
        if (i!=num)
        {
          oSub[i].hideIt()
          if (foldImg) oTop[i].ref["imgA"+i].src = unImg.src
        }
      }
      for(var i=1; i<oTop.length; i++)
      {
        oTop[i].moveIt(0, oTop[i-1].y + oTop[i-1].h)
      }
    }
    if (oSub[num].vis())
    {
      oSub[num].showIt()
      if (foldImg)oTop[num].ref["imgA"+num].src = exImg.src
    }
    else
    {
      oSub[num].hideIt()
      if(foldImg)oTop[num].ref["imgA"+num].src = unImg.src
    }
    for(var i=1; i<oTop.length; i++)
    {
      if (!oSub[i-1].vis()) oTop[i].moveIt(0, oTop[i-1].y + oTop[i-1].h + oSub[i-1].h + mainOffsetY)
      else oTop[i].moveIt(0, oTop[i-1].y + oTop[i-1].h + mainOffsetY)
    }
  }
}

/*********************************************************************
The init function... there should be no need to change anything here.
*********************************************************************/
function initFoldout()
{
  /* Fixing the browsercheck for opera... this can be removed if the browsercheck has been updated!! */
  bw.opera5 = (navigator.userAgent.indexOf("Opera")>-1 && document.getElementById)?true:false
  if (bw.opera5) bw.ns6 = 0

  oTop = new Array();
  oSub = new Array();

  /* Making the objects and hiding the subs... */
  for (var i=0; i<FoldNumber; i++)
  {
    oTop[i] = new makeMenu('divTop'+i, ( bw.ns4 ? document : "") );
    oSub[i] = new makeMenu('divSub'+i, ( bw.ns4 ? document.layers[i] : "") );
    oSub[i].hideIt();
  }

  /* Positioning the top objects... */
  oTop[0].moveIt(0,0);
  for (var i=1; i<oTop.length; i++)
  {
    oTop[i].moveIt(0, oTop[i-1].y+oTop[i-1].h+mainOffsetY);
  }

  /* Making the containing menu object and showing it... */
  /*oCont = new makeMenu('divCont');
  oCont.showIt();*/
  /*menu(0);*/
}

/*--- changing the style onclick ---*/
function changeStyle(aNum, lNum) 
{
  if (document.getElementById)
  {
    if (lastNum != "0")
    {
      document.getElementById(lastNum).className=uncheck;
    }

    if( aNum != "-1" )
    {
      document.getElementById(aNum).className=check;
      lastNum=aNum;
    }
  }

  /*--- netscape ---*/
  if (document.layers)
  {
    pic2lock= aNum != "-1" ? "img"+aNum : aNum;
    lockPic(pic2lock,lNum);
  }
}


/*--- locking the pic ---*/
function lockPic(pic,lNum) 
{
  topLayer = "divTop"+lNum;
  subLayer = "divSub"+lNum;

  if (locked != "")
  {
    document.layers[topLayerLocked].document.layers[subLayerLocked].document[locked].src=loSrc.src;
    locked = "";
  }
  if ( pic != "-1" )
  {
    document.layers[topLayer].document.layers[subLayer].document[pic].src=hiSrc.src;
    locked = pic;
    topLayerLocked = topLayer;
    subLayerLocked = subLayer;
  }
}

/*--- image rollover ---*/
function hiLite(imgName,val,lNum)
{
  if (document.layers)
  {
    topLayer="divTop"+lNum;
    subLayer="divSub"+lNum;

    if (val == "true" && locked != imgName)
    {
      document.layers[topLayer].document.layers[subLayer].document[imgName].src=hiSrc.src;
    }
    if (val != "true" && locked != imgName)
    {
      document.layers[topLayer].document.layers[subLayer].document[imgName].src=loSrc.src;
    }
  }
  else
  {
    if (val == "true")
    {
      document.images[imgName].src = hiSrc.src;
    }
    else
    {
      document.images[imgName].src = loSrc.src;
    }
  }
}

/*--- added by AVIMA ---*/
function init_global_vars( fnumber, folded, fimg, mOff, color, id, sec )
{
  if (document.layers)
  {
    cl = (document.layers.length==0) ? "clTop_jsoff" : "clTop";
  }
  else
  {
    cl = document.getElementById("divTop0").className;
  }

  if( cl == "clTop_jsoff" )
  {
    js_state();
  }
  else if( cl == "clTop" )
  {
    FoldNumber  = fnumber;
    stayFolded  = folded;
    foldImg     = fimg;
    mainOffsetY = mOff;
    Fcolor      = color;

    /*--- images for foldoout ---*/
    unImg.src = '/images/navi_pfeil_'+Fcolor+'.gif'
    exImg.src = '/images/navi_pfeil_'+Fcolor+'_c.gif'

    /*--- check style ---*/
    check   = "checked"+Fcolor;
    uncheck = "unchecked"+Fcolor;
    
    /*--- images for rollover ---*/
    hiSrc.src   = "/images/bullet_"+Fcolor+".gif";
    loSrc.src   = "/images/bullet_navig.gif";

    bw = lib_bwcheck();

    /*--- Opera 5 resize fix. ---*/
    if(navigator.userAgent.indexOf('Opera')>-1 && document.getElementById)
    { 
      scrX= innerWidth; scrY= innerHeight;
      document.onmousemove = function()
        {
          if(scrX<innerWidth-10 || scrY<innerHeight-10 || scrX>innerWidth+10 || scrY>innerHeight+10)
          {
            scrX = innerWidth;
            scrY = innerHeight;
            initFoldout();
          }
        };
    }
    
    if( bw.bw )
    {
      initFoldout();
    }

    /*--- fold out menu ---*/
    menu( sec );

    /*--- highlight ---*/
    if( id > -1 ) changeStyle(id,sec);
  }
}

function js_state()
{
  opt = location.search;

  opt = (opt) ? opt+"&" : "?";
  opt = opt+"js=on"

  location.href = location.pathname + opt;
}
