/*


// spezial Fall:  bei veränderung der Anzahl Elemente hier (***) iITerationszähler ändern


xbCollapsibleLists.js 2001-11-13

Contributor(s): Michael Bostock, Netscape Communications, Copyright 1997
                Bob Clary, Netscape Communications, Copyright 2001
                Seth Dillingham, Macrobyte Resources, Copyright 2001

Netscape grants you a royalty free license to use or modify this
software provided that this copyright notice appears on all copies.
This software is provided "AS IS," without a warranty of any kind.

See xbCollapsibleLists.js.changelog.txt for details of changes.

2002-01-25 gb@BoCo.ch
Angepasst fuer GAW website 2002
MouseOver/Out und expandeble nur jeweils ein Submenu sichtbar


SUCHE NACH  "BoCo Hier Index nachführen" Dort index auf neue Anzahl Menüpunkte einstellen!!!!!

*/
var MenuTxt = new Array();
MenuTxt[1]= "Profil";
MenuTxt[2]= "F&ouml;rderung";
MenuTxt[3]= "Dienstleistungen";
MenuTxt[4]= "Links";
MenuTxt[5]= "Kontakt";
MenuTxt[6]= "Offene Stellen";

var Axxessa = new Array();
Axxessa[1]= " Click f&uuml;r Submen&uuml;: "+ MenuTxt[1];
Axxessa[2]= " Click f&uuml;r Submen&uuml;: "+ MenuTxt[2];
Axxessa[3]= " Click f&uuml;r Submen&uuml;: "+ MenuTxt[3];
Axxessa[4]= " Click f&uuml;r Submen&uuml;: "+ MenuTxt[4];
Axxessa[5]= " Click f&uuml;r Submen&uuml;: "+ MenuTxt[5];
Axxessa[6]= " Click f&uuml;r Submen&uuml;: "+ MenuTxt[6];

 /* BoCo 20100424 

    Anstelle der HauptMenuKapitelBilder auch nur Text! 

  */


var xbcl__id = 0;
var xbcl_item_id = 0;
var xbcl_mLists = new Array();
var xbcl_parentElement = null;

document.lists = xbcl_mLists;

function List(visible, width, height, bgColor, collapsedImageURL, expandedImageURL) 

{
  this.lists   = new Array();  // sublists
  this.items   = new Array();  // layers
  this.types   = new Array();  // type
  this.strs    = new Array();  // content
  this.visible = visible;
  this.id      = xbcl__id;
  this.width   = width || 350;
  this.height  = height || 22; 

/* START */
/* Hier habe ich einiges geaendert */

/*
original Code
  this.collapsedImageURL = (collapsedImageURL || 'false.gif');
  this.expandedImageURL  = (expandedImageURL || 'true.gif');
*/

  this.collapsedImageURL = "images/menu/m_" ;
  this.expandedImageURL  = "images/menu/m_" ;

/* 
  var indx = this.id;
  //indx = 3 ;
  this.expandedImageURL  = "images/menu/m_" + indx + "0_t.gif"
  this.collapsedImageURL = "images/menu/m_" + indx + "0_f.gif";
*/

/* ENDE */

  if (bgColor) 
    this.bgColor = bgColor;
  xbcl_mLists[xbcl__id++] = this;
}

function xbcl_SetFont(i,j) 
{
  this.fontIntro = i;
  this.fontOutro = j;
}

function xbcl_GetFont() 
{
  return [this.fontIntro, this.fontOutro];
}

function xbcl_setIndent(indent) 
{ 
  this.i = indent; 
  if (this.i < 0) 
  { 
    this.i = 0; 
    this.space = false; 
  }
  else
    this.space = true;
}

function xbcl_getIndent(indent)
{
  return this.i;
}

function xbcl_writeItemDOMHTML( obj, s, flList, listObj )
{
  var styleObj;
  var outerDiv, innerLeft, innerRight;
  var str;
  var leftEdge = 0;
 

  styleObj = new xbStyle(obj);
  styleObj.setVisibility('hidden');
  outerDiv = document.createElement( "div" );
  outerDiv.id = "DIV_" + obj.id;
  styleObj = new xbStyle( outerDiv );
 styleObj.setWidth( this.width );

  
  if ( flList )
  {
    innerLeft = document.createElement( "div" );
    innerLeft.style.position = "absolute";
    innerLeft.style.valign = "middle";
    leftEdge = 15;
    
    styleObj = new xbStyle( innerLeft );
    styleObj.setWidth( 160 );
    styleObj.setBackgroundColor( "transparent" );
	/* bildname zusammensetzen 	*/
	/* FORMAT: m_10_t.gif 		*/
    indx = listObj.id;
    //indx = --indx;
    img_exp = '' + this.expandedImageURL + '' + indx + '0_t.gif';
    img_col = '' + this.collapsedImageURL + '' + indx + '0_f.gif';
	
/*  flip flop  integrieren */
/* 	ORIGINAL CODE
	onMouseOver="img_act('menu1','menuTxt01')"
	onMouseOut="img_inact('menu1')"
*/



    // wenn HauptmenuItem e.g. Profil
 
    if ( listObj.visible ){
   
      str = '<a class="menuT" id="T0'+indx+'" name="'+indx+'" title=\"'+Axxessa[listObj.id]+'\" target="_self" href="javascript:xbcl_expand('+ listObj.id +');"><div class="MenuT">'+ MenuTxt[listObj.id] +'</div><br/><div class="redBalk"></div></a>';}
    else {
	  str = '<a class="menuT" id="T0'+indx+'" name="'+indx+'" title=\"'+Axxessa[listObj.id]+'\" target="_self" href="javascript:xbcl_expand('+ listObj.id +');"><div class="MenuT">'+ MenuTxt[listObj.id] +'</div><br/><div class="redBalk"></div></a>';

	}
    innerLeft.innerHTML = str;
    outerDiv.appendChild( innerLeft );
  }
  else if ( this.space )
    leftEdge = 25;
  
  innerRight = document.createElement( "div" );
  innerRight.noWrap = true;
  innerRight.style.position = "absolute";
  
  styleObj = new xbStyle( innerRight );
  styleObj.setLeft( leftEdge + ( this.l * this.i ) );
  styleObj.setWidth( this.width - 15 - this.l * this.i );
  styleObj.setBackgroundColor( "transparent" );
  

  s = this.fontIntro + s + this.fontOutro;
  
  innerRight.innerHTML = s;
  outerDiv.appendChild( innerRight );
 

  obj.appendChild( outerDiv );

//if (listObj.id != null) {
// alert(" nr " + listObj.id );
//}
 
  return;
}

function xbcl_writeItem( obj, s, flList, listObj )
{
  var cellStyle = '';
  var str = '';
  var styleObj = new xbStyle( obj );
  
  styleObj.setVisibility( 'hidden' );
  
  if ( document.body && document.body.style )
    cellStyle = ' style="background-color: transparent;"';
  
  str += '<table width='+this.width+' nowrap border="0" cellpadding="0" cellspacing="0"><tr>';

  if ( flList ) 
  {
    str += '<td width="160px" nowrap valing="middle"' + cellStyle + '>';
    str += '<a title="Click" target="_self" href="javascript:xbcl_expand(' + listObj.id + ');" >';
    
	/* bildname zusammensetzen 	*/
	/* FORMAT: m_10_t.gif 		*/
	indx = listObj.id;
    //indx = --indx;
	img_exp = '' + this.expandedImageURL + '' + indx + '0_t.gif';
    img_col = '' + this.collapsedImageURL + '' + indx + '0_f.gif';
  
	
    if ( listObj.visible )
      str += ''; // <img border="0" src="" id="_img' +  listObj.id + '" name="_img' + listObj.id + '">img_exp';
    else
      str += '';// <img border="0" src="" id="_img' +  listObj.id + '" name="_img' + listObj.id + '">img_col';
    
    str += '</a></td>';
  } 
  else if (this.space)
    str += '<td width="15" nowrap' + cellStyle + '>&nbsp;</td>';
  
  if (this.l>0 && this.i>0) 
    str += '<td width="' + this.l*this.i+ '" nowrap' + cellStyle + '>&nbsp;</td>';

  str += '<td height="' + ( this.height - 3) + '" width="' + ( this.width - 15 - this.l * this.i ) + '" valign="middle" align="left"' + cellStyle + '>';
  
  str += this.fontIntro + s + this.fontOutro;
  
  str += '</td></tr></table>';
  
  styleObj.setInnerHTML( str );
  
  return;
}

function xbcl_writeList()
{
  var item;
  var i;
  var flList;
  
  for ( i = 0; i < this.types.length; i++ )
  {
    item = this.items[ i ];
    flList = ( this.types[ i ] == 'list' );
    
    this._writeItem( item, this.strs[ i ], flList, this.lists[ i ] );
    
    if ( flList && this.lists[ i ].visible )
      this.lists[ i ]._writeList();
  }
  
  this.built = true;
  this.needsRewrite = false;
  self.status = '';
}

function xbcl_showList() 
{
  var item;
  var styleObj;
  var i;

  for (i = 0; i < this.types.length; i++) 
  { 
    item = this.items[i];
    styleObj = new xbStyle(item);
    styleObj.setClipLeft(0);
    styleObj.setClipRight(this.width);
    styleObj.setClipTop(0);
    if (item.height)
    {
      styleObj.setClipBottom(item.height);
      styleObj.setHeight(item.height);
    }
    else
    {
      styleObj.setClipBottom(this.height);
      styleObj.setHeight(this.height);
    }
    
    if ( this.visible )
      styleObj.setVisibility( 'visible' );

    var bg = item.oBgColor || this.bgColor;
    if ((bg == null) || (bg == 'null')) 
      bg = '';

    styleObj.setBackgroundColor(bg);

    if (this.types[i] == 'list' && this.lists[i].visible)
      this.lists[i]._showList();
  }
  this.shown = true;
  this.needsUpdate = false;
}

function xbcl_setImage(list, item, file)
{
  var id = '_img' + list.id;
  var img = null;
  
  // for DOMHTML or IE4 use cross browser getElementById from xbStyle
  // can't use it for NN4 since it only works for layers in NN4
  if (document.layers) 
    img = item.document.images[0];
  else 
    img = xbGetElementById(id);
    
  if (img)
    img.src = file;
}

function xbcl_getHeight() 
{
  var totalHeight = 0;
  var i;
  
  if (!this.visible)
    return 0;
  
  for (i = 0; i < this.types.length; i++) 
  {
    if (this.items[i].height)
      totalHeight += this.items[i].height;
    else
      totalHeight += this.height;
    
    if ((this.types[i] == 'list') && this.lists[i].visible)
    {
      totalHeight += this.lists[i].getHeight();
    }
  }
  
  return totalHeight;
}

function xbcl_updateList(pVis, x, y) 
{
  var currTop = y; 
  var item;
  var styleObj;
  var i;

  for (i = 0; i < this.types.length; i++) 
  { 
    item = this.items[i];
    styleObj = new xbStyle(item);

    if (this.visible && pVis) 
    {
      styleObj.moveTo(x, currTop);
      if (item.height)  // allow custom heights for each item
        currTop += item.height;
      else
        currTop += this.height;
      
      styleObj.setVisibility('visible');
    } 
    else 
    {
      styleObj.setVisibility('hidden');
    }

    if (this.types[i] == 'list') 
    {
	/* bildname zusammensetzen 	*/
	/* FORMAT: m_10_t.gif 		*/
	indx = i;
    //indx = --indx;
	img_exp = '' + this.expandedImageURL + '' + indx + '0_t.gif';
    img_col = '' + this.collapsedImageURL + '' + indx + '0_f.gif';
  
	
      if (this.lists[i].visible) 
      {
        if (!this.lists[i].built || this.lists[i].needsRewrite) 
          this.lists[i]._writeList();

        if (!this.lists[i].shown || this.lists[i].needsUpdate) 
          this.lists[i]._showList();

        xbcl_setImage(this.lists[i], item, img_exp );
      } 
      else 
        xbcl_setImage(this.lists[i], item, img_col );

      if (this.lists[i].built)
        currTop = this.lists[i]._updateList(this.visible && pVis, x, currTop);
    }
  }
  return currTop;
}

function xbcl_updateParent( pid, l ) 
{
  var i;

  if ( !l ) 
    l = 0;

  this.pid = pid;
  this.l = l;

  for ( i = 0; i < this.types.length; i++ )
  {
    if ( this.types[ i ] == 'list' )
    {
      this.lists[ i ]._updateParent( pid, l + 1 );
    }
  }
}

function xbcl_expand(i) 
{
/* 	A 	*/
/* 	A 	*/
/* 	A 	*/

  xbcl_mLists[i].visible = !xbcl_mLists[i].visible;
  
  if (xbcl_mLists[i].onexpand != null) 
  {  xbcl_mLists[i].onexpand(xbcl_mLists[i].id);	}

  xbcl_mLists[xbcl_mLists[i].pid].rebuild();

  if (xbcl_mLists[i].postexpand != null) 
  {  xbcl_mLists[i].postexpand(xbcl_mLists[i].id); }


/*  BoCo Hier Index nachführen
(***)
	alle anderen müssten nun invisible gesetzt werden
	eigentlich müssten wir nach der neuen Regel:
	"nur eine Liste darf expanded sein"
	herausfinden welche visible ist und diese kehren,
	in dem wir hier i =  den Wert des Indices der EXPANDED LISTE zuordenen 
	dann wird sie hier automatisch geschlossen
	WELCHE VARIABLE ZEIGT "Visible" an ???
	Vorsicht diese Prüfung sollten wir gleich zu beginn machen, sonst kehren wir die soeben 	angeklickte Liste wieder invisible.
	was passiert wenn wir alle Listen invisibel machen!!! dann finde wir keine die Visible = true hat!!!
*/

// spezial Fall:  bei veränderung der Anzahl Elemente hier iITerationszähler ändern (***)
//for ( q = 0; q < this.types.length; q++)
for ( q = 1; q < 8; q++)
{
  	if ( q != i )
	{ 
		if   (xbcl_mLists[q].visible == true)
		{
			xbcl_mLists[q].visible = !xbcl_mLists[q].visible;
	
			if (xbcl_mLists[q].onexpand != null)
			{	xbcl_mLists[q].onexpand(xbcl_mLists[q].id);		}
			xbcl_mLists[xbcl_mLists[q].pid].rebuild();
			
			if (xbcl_mLists[q].postexpand != null) 
	    	{	xbcl_mLists[q].postexpand(xbcl_mLists[q].id);	}
		}
	}
}
}

function xbcl_build(x, y) 
{
  this._updateParent(this.id);
  this._writeList();
  this._showList();
  this._updateList(true, x, y);
  this.x = x; 
  this.y = y;
}

function xbcl_rebuild() 
{ 
  this._updateList(true, this.x, this.y); 
}

function xbcl_getNewItem()
{
  var newItem = null;

  newItem = xbGetElementById('lItem' + xbcl_item_id);

  if (!newItem) 
  {
    if (document.all && !document.getElementById)
    {
      var parentElement = this.parentElement;
      if (!parentElement)
        parentElement = document.body;
        
      parentElement.insertAdjacentHTML('beforeEnd', '<div id="lItem' + xbcl_item_id + '" style="position:absolute;"></div>');
      newItem = xbGetElementBydId('lItem' + xbcl_item_id);
    }
    else if (document.layers)
    {
      if (this.parentElement)
        newItem = new Layer(this.width, this.parentElement);
      else
        newItem = new Layer(this.width);
    }
    else if (document.createElement)
    {
      newItem = document.createElement('div');
      newItem.id= 'lItem' + xbcl_item_id;
      newItem.style.position = 'absolute';

      if (this.parentElement)
        this.parentElement.appendChild(newItem);
      else 
        document.body.appendChild(newItem);
    }
  }

  return newItem;
}

function xbcl_addItem(str, bgColor, item) 
{
  if (!item) 
    item = this._getNewItem();
  
  if (!item)
    return;

  if (bgColor) 
    item.oBgColor = bgColor;

  this.items[this.items.length] = item;
  this.types[this.types.length] = 'item';
  this.strs[this.strs.length] = str;
  ++xbcl_item_id;
  
  if ( this.built )
  {
    this._writeItem( item, str, false );
    xbcl_mLists[this.pid].rebuild();
    if ( this.visible )
      this._showList();
    else
      this.needsUpdate = true;
  }
  
  return item;
}

function xbcl_addList(list, str, bgColor, item) 
{
  if (!item) 
    item = this._getNewItem();

  if (!item)
    return;

  if (bgColor) 
    item.oBgColor = bgColor;

  this.lists[this.items.length] = list;
  this.items[this.items.length] = item;
  this.types[this.types.length] = 'list';
  this.strs[this.strs.length] = str;
  ++xbcl_item_id;
  
  list.parentList = this;
  
  list.pid = this.pid;
  list.l = this.l + 1;
  
  if ( this.built )
  {
    this._writeItem( item, str, true, list );
    xbcl_mLists[ this.pid ].rebuild();
    if ( this.visible )
      this._showList();
    else
      this.needsUpdate = true;
  }
  
  return item;
}

List.prototype.setIndent     = xbcl_setIndent;
List.prototype.getIndent     = xbcl_getIndent;
List.prototype.addItem       = xbcl_addItem;
List.prototype.addList       = xbcl_addList;
List.prototype.build         = xbcl_build;
List.prototype.rebuild       = xbcl_rebuild;
List.prototype.setFont       = xbcl_SetFont;
List.prototype.getFont       = xbcl_GetFont;
List.prototype.getHeight     = xbcl_getHeight;

List.prototype._writeList    = xbcl_writeList;
List.prototype._getNewItem   = xbcl_getNewItem;

if ( document.createElement )
  List.prototype._writeItem  = xbcl_writeItemDOMHTML;
else
  List.prototype._writeItem  = xbcl_writeItem;

List.prototype._showList     = xbcl_showList;
List.prototype._updateList   = xbcl_updateList;
List.prototype._updateParent = xbcl_updateParent;

List.prototype.onexpand      = null;
List.prototype.postexpand    = null;
List.prototype.lists         = null;  // sublists
List.prototype.items         = null;  // layers
List.prototype.types         = null;  // type
List.prototype.strs          = null;  // content
List.prototype.x             = 0;
List.prototype.y             = 0;
List.prototype.visible       = false;
List.prototype.id            = -1;
List.prototype.i             = 18;
List.prototype.space         = true;
List.prototype.pid           = 0;
List.prototype.fontIntro     = '';
List.prototype.fontOutro     = '';
List.prototype.width         = 350;
List.prototype.height        = 22;
List.prototype.built         = false;
List.prototype.shown         = false;
List.prototype.needsUpdate   = false;
List.prototype.needsRewrite  = false;
List.prototype.l             = 0;
List.prototype.bgColor       = null;
List.prototype.parentList    = null;
List.prototype.parentElement = null;
