// ----------------------------------------------------------------------------
//  cbFenster
// ----------------------------------------------------------------------------
//
//  synopsis:
//    var cfg = {
//        container: { ... }, client: { ... }, tbar: { ... }, sbar: { ... },
//        minimize: { ... }, maximize: { ... }, close: { ... }, resize: { ... },
//        restore: { ... },
//    };
//    var myFenster = new cbFenster( cfg );
//
//    all of the cfg keys are optional
//    for their meanings and default settings cf. cbFenster constructor.
//
//    cbFenster.js relies heavily on the cbFenster.css stylesheet
//
//    functions should return true to allow, false to cancel respective action
//
// ----------------------------------------------------------------------------


// ----------------------------------------------------------------------------
// ... static properties
// ----------------------------------------------------------------------------
cbFenster.nextZ     = 100;
cbFenster.focused   = null;
cbFenster.instances = { };
cbFenster.heights   = { };

/*@cc_on
@if (@_jscript)

cbFenster.selectBoxes = xGetElementsByTagName( 'select' );
cbFenster.IEhide
   = function( ) {
      for ( var i = 0; i < cbFenster.selectBoxes.length; i++ ) {
         var b = cbFenster.selectBoxes[ i ];
         var intersects = false;
         for ( var id in cbFenster.instances ) {
            var f = cbFenster.instances[ id ];
            if ( f && f.con && xIntersects( f.con, b ) ) {
               intersects = true;
               break;
            }
         }
         if ( intersects )
            xHide( b );
         else
            xUnsetVis( b );
      }
   };

@end @*/

	
cbFenster.setInitialHeight
	= function( id, to_hide_class ) {
		if ( to_hide_class ) {
			var to_hides = xGetElementsByClassName( to_hide_class );
			for ( var i = 0; i < to_hides.length; i++ ) {
				xAddClass( to_hides[ i ], 'hidden' );
			}
		}
		xRemoveClass( id, 'hidden' );
		cbFenster.heights[ id ] = xHeight( id );
		xAddClass( id, 'hidden' );
		xShow( id );
	};

cbFenster.getInitialHeight
	= function( id ) {
		return cbFenster.heights[ id ] || 0;
	};

// ----------------------------------------------------------------------------
// ... constructor
// ----------------------------------------------------------------------------
function cbFenster( cfg ){
   var _f = this;

   // --------------------------------------------------------------------------
   //  provide complete set of config params
   // --------------------------------------------------------------------------
   function ff( o, p, v ) { if ( !isDef( o[ p ] ) ) o[ p ] = v; }

   ff( cfg,      'tbar',        {}          ); // title bar
   ff( cfg.tbar, 'cls',         'cbfTBar'   ); // class
   ff( cfg.tbar, 'cls_focused', 'cbfTBarF'  ); // class focused
   ff( cfg.tbar, 'title',       ''          ); // initial title

   ff( cfg,           'container', {}       ); // container
   ff( cfg.container, 'fenceId',   null     ); // id of 'fencing' container
   ff( cfg.container, 'enable_drag', true   );
   ff( cfg.container, 'fMove',     null     ); // called: f(cont,x_tgt,y_tgt)
   ff( cfg.container, 'fFocus',    null     ); // called: f(cont)
   ff( cfg.container, 'cls',       'cbfCon' ); // class
   ff( cfg.container, 'fixed',     false    ); // position: fixed ?
   ff( cfg.container, 'layout',         {}  );
   ff( cfg.container.layout, 'x',       100 ); // initial x pos
   ff( cfg.container.layout, 'y',       100 ); // initial y pos
   ff( cfg.container.layout, 'w',       400 ); // initial width
   ff( cfg.container.layout, 'h',       200 ); // initial height
   ff( cfg.container.layout, 'hc',        0 ); // height correction IE
   ff( cfg.container.layout, 'wc',        0 ); // width correction IE
   /*@cc_on
      @if (@_jscript)
       	cfg.container.layout.w += cfg.container.layout.wc;
       	cfg.container.layout.h += cfg.container.layout.hc;
   @end @*/
   ff( cfg.container.layout, 'minw',    200 ); // mimimized window width
   ff( cfg.container.layout, 'minleft', 2   ); // mimimized window left dist
   ff( cfg.container.layout, 'mintop',  2   ); // mimimized window top dist
   ff( cfg.container.layout, 'border',  1   ); // border width
   ff( cfg.container.layout, 'padding', 1   ); // padding width

   ff( cfg,          'client',   {}         ); // will be generated, if not passed
   ff( cfg.client,   'id',       null       ); // client id
   ff( cfg.client,   'cls',      ''         ); // class
   ff( cfg.client,   'url',      null       ); // <iframe> instead of <div>
   ff( cfg.client,   'fLoad',    null       ); // called after iframe is loaded
   ff( cfg.client,   'border',    1         ); // border width

   ff( cfg,       'sbar',        {}         ); // status bar
   ff( cfg.sbar,  'enabled',     true       ); // use it or not
   ff( cfg.sbar,  'cls',         'cbfSBar'  ); // class
   ff( cfg.sbar,  'cls_focused', 'cbfSBarF' ); // class focused

   ff( cfg,          'resize',   {}         ); // resize button
   ff( cfg.resize,   'enabled',  true       ); // use it or not
   ff( cfg.resize,   'icon_cls', 'cbfIconR' ); // class for icon
   ff( cfg.resize,   'text',     'Resize'   ); // 'title' attribute
   ff( cfg.resize,   'fn',       null       ); // called: f(cont,x_tgt,y_tgt)

   ff( cfg,          'minimize', {}         ); // minimize button
   ff( cfg.minimize, 'enabled',  true       ); // use it or not
   ff( cfg.minimize, 'icon_cls', 'cbfIconN' ); // class for icon
   ff( cfg.minimize, 'text',     'Minimize' ); // 'title' attribute
   ff( cfg.minimize, 'fn',        null      ); // called: f(cont)

   ff( cfg,          'maximize', {}         ); // maximize button
   ff( cfg.maximize, 'enabled',  true       ); // use it or not
   ff( cfg.maximize, 'icon_cls', 'cbfIconM' ); // class for icon
   ff( cfg.maximize, 'text',     'Maximize' ); // 'title' attribute
   ff( cfg.maximize, 'fn',        null      ); // called before: f(cont,w_tgt,h_tgt)

   ff( cfg,          'close',    {}         ); // close button
   ff( cfg.close,    'enabled',  true       ); // use it or not
   ff( cfg.close,    'icon_cls', 'cbfIconC' ); // class for icon
   ff( cfg.close,    'text',     'Close'    ); // 'title' attribute
   ff( cfg.close,    'fn',       null       ); // called: f(cont)

   ff( cfg,          'restore',  {}         ); // restore button
   ff( cfg.restore,  'icon_cls', 'cbfIconO' ); // class for icon
   ff( cfg.restore,  'text',     'Restore'  ); // 'title' attribute
   ff( cfg.restore,  'fn',       null       ); // called after restore: f(cont)

   // --------------------------------------------------------------------------
   //  public methods
   // --------------------------------------------------------------------------

   _f.delete_content
      = function( ) {
         var children = _f.client.childNodes;
         for ( var i = 0; i < children.length; i++ ) {
            _f.client.removeChild( children[ i ] );
         }
      };

   _f.set_content
      = function( c ) {
         var el = _f.isIFrame ? _f.client.contentDocument.body : _f.client;
         xInnerHtml( el, c );
      };

   _f.prepend_content
      = function( c ) {
         var el = _f.isIFrame ? _f.client.contentDocument.body : _f.client;
         xInnerHtml( el, c + xInnerHtml( el ) );
      };

   _f.append_content
      = function( c ) {
         var el = _f.isIFrame ? _f.client.contentDocument.body : _f.client;
         xInnerHtml( el, xInnerHtml( el ) + c );
      };

   _f.set_content_node
      = function( node ) {
         _f.delete_content( );
         _f.client.appendChild( node );
      };

   _f.append_content_node
      = function( node ) {
         _f.client.appendChild( node );
      };


   _f.paint
      = function( dw, dh ) {
         _f.conW += dw;
         _f.conH += dh;
         set_geo( _f.con, { width: _f.conW - BB, height: _f.conH - BB } );
         /*@cc_on
         @if (@_jscript)
            xWidth(_f.tbar, _f.conW - PP - BB);
            if (!_f.isMin && _f.sbar) {
               xWidth(_f.sbar, _f.conW - PP - BB);
               _f.sbar.style.top = _f.conH - _f.sbar.offsetHeight - P - BB;
            }
         @end @*/
         if ( !_f.isMin ) {
            var sh = _f.sbar ? _f.sbar.offsetHeight : 0;
            set_geo( _f.client,
               { top:    P + _f.tbar.offsetHeight,
                 width:  _f.conW - PP - BB - cBB,
                 height: _f.conH - _f.tbar.offsetHeight -sh - PP - BB - cBB } );
         }
         /*@cc_on
         @if (@_jscript)
            cbFenster.IEhide( );
         @end @*/
      };

   _f.focus
      = function( ) {
         if (     cbFenster.focused != _f
              && ( !cfg.container.fFocus || cfg.container.fFocus(_f) ) ) {
            _f.con.style.zIndex = cbFenster.nextZ++;
            if ( cbFenster.focused ) {
               cbFenster.focused.tbar.className = cbFenster.focused.clsTB;
               if ( cbFenster.focused.sbar ) {
                  cbFenster.focused.sbar.className = cbFenster.focused.clsSB;
               }
            }
            _f.tbar.className = cfg.tbar.cls_focused;
            if ( _f.sbar ) _f.sbar.className = cfg.sbar.cls_focused;
            cbFenster.focused = _f;
         }
         /*@cc_on
         @if (@_jscript)
            cbFenster.IEhide( );
         @end @*/
      };

   _f.href
      = function( s ) {
         if ( !_f.isIFrame ) return s;

         // all reputable browsers and IE
         if ( _f.client.contentWindow ) {
            if ( s )  _f.client.contentWindow.location = s;
            return _f.client.contentWindow.location.href;
         }
         // for Safari/Apollo/WebKit on Windows
         if ( typeof _f.client.src == 'string' ) {
            if ( s ) _f.client.src = s;
            return _f.client.src;
         }
         return s;
      };

   _f.hide
      = function( e ) {
         var i, o = getInstances( ), z = 0, hz = 0, f = null;
         if ( !cfg.close.fn || cfg.close.fn( _f ) ) {
            _f.con.style.display = 'none';
            _f.isHidden = true;
            xStopPropagation( e );
            if ( _f == cbFenster.focused ) {
               for ( i in o ) { // find the next appropriate fenster to focus
                  if ( !o[ i ].isHidden && o[ i ] != _f ) {
                     z = parseInt( o[ i ].con.style.zIndex );
                     if ( z > hz ) {
                        hz = z;
                        f  = o[ i ];
                     }
                  }
               }
               if ( f ) f.focus( );
            }
            /*@cc_on
         	@if (@_jscript)
            	cbFenster.IEhide( );
         	@end @*/
         }
      };

   _f.show
      = function() {
         expand( _f.con );
         _f.isHidden = false;
         _f.focus( );
      };

   _f.status
      = function( s ) {
         if ( _f.sbar) {
            if ( s ) _f.sbar.innerHTML = s;
            return _f.sbar.innerHTML;
         }
      };

   _f.title
      = function( s ) {
         if ( s ) _f.tbar.innerHTML = s;
         return _f.tbar.innerHTML;
      };

   _f.destroy
      = function( ) {
         try {
            _f.hide();
            xRemoveEventListener( window, 'unload', winUnload, false );
            xRemoveEventListener( window, 'resize', winResize, false );
            _f.con.parentNode.removeChild( _f.con );
            winUnload( );
         }
         catch ( e ) {
            alert( "ups --- Error in destroy:\n" + e );
         }
      };

   _f.minimize
      = function( ) {
         if ( cfg.minimize.enabled && !_f.isMin && !_f.isHidden ) {
            h_minimize( );
            return true;
         }
         return false;
      };

   _f.maximize
      = function( ) {
         if ( cfg.maximize.enabled && !_f.isMax && !_f.isHidden ) {
            h_maximize( );
            return true;
         }
         return false;
      };

   _f.restore
      = function( ) {
         var b, i, t;
         if ( _f.isMax ) {
            b = _f.mbtn;
            b.onclick = h_maximize;
            i = cfg.maximize.icon_cls;
            t = cfg.maximize.text;
            _f.isMax = false;
         }
         else if ( _f.isMin ) {
            b = _f.nbtn;
            b.onclick = h_minimize;
            i = cfg.minimize.icon_cls;
            t = cfg.minimize.text;
            _f.isMin = false;
            expand( _f.client );
            if ( _f.sbar ) expand( _f.sbar );
         }
         else {
            return false;
         }
         xMoveTo( _f.con, rX, rY );
         b.className = i;
         b.title = t;
         if ( _f.rbtn ) expand( _f.rbtn );
         _f.conW = rW;
         _f.conH = rH;
         _f.paint( 0, 0 );
         if ( cfg.restore.fn ) cfg.restore.fn( _f );
         return true;
      };


   // -------------------------------------------------------------------------
   // Event handlers
   // -------------------------------------------------------------------------

   function dragStart( ) {
      var o = getInstances( );
      for ( var i in o ) {
         if ( !o[ i ].isMin && o[ i ].isIFrame ) {
            collapse( o[ i ].client );
         }
     }
   }

   function dragEnd( ) {
      var o = getInstances( );
      for ( var i in o ) {
         if ( !o[ i ].isMin && o[ i ].isIFrame ) {
            expand( o[i].client );
         }
      }
   }

   function h_tbarDrag( e, mdx, mdy ) {
      var x = _f.con.offsetLeft + mdx;
      if ( x < 0 ) x = 0;
      var y = _f.con.offsetTop  + mdy;
      if ( y < 0 ) y = 0;
      if ( !cfg.container.fMove || cfg.container.fMove( _f, x, y ) ) {
         if ( !cfg.container.fenceId ||
              inFence( x, y, _f.con.offsetWidth, _f.con.offsetHeight ) ) {
            set_geo( _f.con, { left: x, top: y } );
            /*@cc_on
            @if (@_jscript)
               cbFenster.IEhide( );
            @end @*/
         }
      }
   }

   function h_resize( e, mdx, mdy ) {
      var w = _f.con.offsetWidth  + mdx;
      var h = _f.con.offsetHeight + mdy;
      if ( !cfg.resize.fn || cfg.resize.fn( _f, w, h ) ) {
         if ( !cfg.container.fenceId
              || inFence( _f.con.offsetLeft, _f.con.offsetTop, w, h ) ) {
            _f.paint(mdx, mdy);
         }
      }
   }

   function h_maximize( ) {
      var f, fx, fy, x = 0, y = 0, w, h, fx2, fy2;
      var sl = xScrollLeft( );
      var st = xScrollTop( );
      var cw = xClientWidth( );
      var ch = xClientHeight( );
      if ( cfg.container.fenceId ) {
         f = xGetElementById( cfg.container.fenceId );
         x = fx = xPageX( f );
         y = fy = xPageY( f );
         w = f.offsetWidth;
         h = f.offsetHeight;
         if ( cfg.container.fixed ) {
            x = ( fx >= sl ) ? fx - sl : 0;
            y = ( fy >= st ) ? fy - st : 0;
            fx2 = ( fx + w >= sl + cw ) ? cw : fx + w;
            fy2 = ( fy + h >= st + ch ) ? ch : fy + h;
            w = fx2 - x;
            h = fy2 - y;
         }
      }
      else {
         if ( !cfg.container.fixed ) {
            x = sl;
            y = st;
         }
         w = cw;
         h = ch;
      }

      if ( !cfg.maximize.fn ||
            cfg.maximize.fn( _f, w - PP - BB, h - _f.tbar.offsetHeight
                            - (_f.sbar ? _f.sbar.offsetHeight : 0) - PP - BB)) {
         _f.restore( );
         _f.isMax = !_f.isMax;
         minmax( _f.mbtn, w, h, x, y );
      }
   }

   function set_minx_minr( ) {
      if ( _f.minx && _f.minr ) {
         return;
      }

      var i, r = 1, x = ML;
      var o = getInstances( );
      for ( i in o ) {
         if ( o[ i ].isMin ) {
            x += o[ i ].con.offsetWidth + ML;
            if ( x + _f.minw > xClientWidth( ) ) {
               x = ML;
               ++r;
            }
         }
      }
      _f.minx = x;
      _f.minr = r;
   }

   function h_minimize( ) {
      var y, h;
      var o = cbFenster.instances;
      if ( !cfg.minimize.fn || cfg.minimize.fn( _f ) ) {

         set_minx_minr( );
         h = _f.tbar.offsetHeight + PP + BB;
         y = xClientHeight( ) - ( _f.minr * ( h + MT ));
         if ( !cfg.container.fixed ) y += xScrollTop( );

         _f.restore( );
         _f.client.style.display = 'none';
         if (_f.sbar) _f.sbar.style.display = 'none';
         _f.isMin = !_f.isMin;
         minmax( _f.nbtn, _f.minw, h, _f.minx, y );
      }
   }

   function winResize( ) {
      if ( _f.isMax ) {
         xResizeTo( _f.con, 100, 100 ); // avoid scrollbars
         if ( !cfg.container.fixed )
            xMoveTo( _f.con, xScrollLeft( ), xScrollTop( ) );
         _f.conW = xClientWidth( );
         _f.conH = xClientHeight( );
         _f.paint( 0, 0 );
      }
   }

   function winUnload( ) {
      _f.con.onmousedown = _f.con.onclick = null;
      if ( _f.nbtn ) _f.nbtn.onclick = null;
      if ( _f.mbtn ) _f.mbtn.onclick = _f.tbar.ondblclick  = null;
      if ( _f.cbtn ) _f.cbtn.onclick = _f.cbtn.onmousedown = null;
      cbFenster.instances[ cfg.client.id ] = null;
      _f = null;
   }

   // -------------------------------------------------------------------------
   // ... private functions
   // -------------------------------------------------------------------------
   function getInstances( ) {
      var activeInstances = {};
      for ( var i in cbFenster.instances ) {
         if ( cbFenster.instances.hasOwnProperty( i ) && cbFenster.instances[ i ] )
            activeInstances[ i ] = cbFenster.instances[ i ];
      }
      return activeInstances;
   }

   function set_geo( e, o ) { for ( var p in o ) { e.style[ p ] = o[ p ] + 'px'; } }
   function set_style( e, o ) { for ( var p in o ) { e.style[ p ] = o[ p ]; } }
   function collapse( e ) { set_style( e, { display: 'none'  } ); }
   function expand( e )   { set_style( e, { display: 'block' } ); }

   function create_cl_div( cl, o ) {
      var el = document.createElement( 'div' );
      el.className = cl;
      for ( var p in o ) { el[ p ] = o[ p ]; }
      return el;
   }

   function minmax( b, w, h, x, y ) {
      rW = _f.con.offsetWidth;
      rH = _f.con.offsetHeight;
      rX = _f.con.offsetLeft;
      rY = _f.con.offsetTop;

      xMoveTo( _f.con, x, y );

      b.className = cfg.restore.icon_cls;
      b.title     = cfg.restore.text;
      b.onclick   = _f.restore;
      if ( _f.rbtn ) {
         set_style( _f.rbtn, { display: 'none' } );
      }
      _f.conW = w;
      _f.conH = h;
      _f.paint( 0, 0 );
   }

   function inFence( x, y, w, h ) {
      var f = xGetElementById( cfg.container.fenceId );
      if ( cfg.container.fixed ) {
         x += xScrollLeft( );
         y += xScrollTop( );
      }
      return (    x >= f.offsetLeft && x + w <= f.offsetLeft + f.offsetWidth
               && y >= f.offsetTop  && y + h <= f.offsetTop  + f.offsetHeight );
   }

   //
   // -------------------------------------------------------------------------
   // ... the Constructor Code
   // -------------------------------------------------------------------------
   if ( cbFenster.instances[cfg.client.id] ) {
   	  cbFenster.instances[cfg.client.id].show( );
   	  return null;
   }
   cbFenster.instances[cfg.client.id] = this;

   //
   //	public properties
   //
   _f.con  = null; // container
   _f.tbar = null; // title bar
   _f.sbar = null; // status bar
   _f.rbtn = null; // resize icon
   _f.nbtn = null; // minimize icon
   _f.mbtn = null; // maximize icon
   _f.cbtn = null; // close icon

   _f.isMin    = false;
   _f.isMax    = false;
   _f.isHidden = false;
   _f.isIFrame = ( typeof cfg.client.url == 'string' );
   _f.client   = xGetElementById( cfg.client.id );
   _f.clsSB    = cfg.sbar.cls;
   _f.clsTB    = cfg.tbar.cls;
   _f.conW     = cfg.container.layout.w;
   _f.conH     = cfg.container.layout.h;

   _f.minw     = cfg.container.layout.minw;
   _f.minx     = 0;
   _f.minr     = 0;

   //
   //	private properties
   //
   var rX, rY, rW, rH; // "restore" values
   var P  = cfg.container.layout.padding;
   var B  = cfg.container.layout.border;
   var cB = cfg.client.border;
   var PP = 2 * P, BB = 2 * B, cBB = 2 * cB;
   var MT = cfg.container.layout.mintop;
   var ML = cfg.container.layout.minleft;

   // create elements
   if ( !_f.client ) {
      _f.client = document.createElement( _f.isIFrame ? 'iframe' : 'div' );
      _f.client.id = cfg.client.id;
      if ( !_f.isIFrame ) xInnerHtml( _f.client, ' --- autogenerated --- ' );
   }
   xAddClass( _f.client, 'cbfClient' );
   xAddClass( _f.client, cfg.client.cls );

   _f.con  = create_cl_div( cfg.container.cls, { } );
   _f.tbar = create_cl_div( cfg.tbar.cls, { innerHTML: cfg.tbar.title } );
   _f.con.appendChild( _f.tbar );
   if ( cfg.minimize.enabled ) {
      _f.nbtn = create_cl_div( cfg.minimize.icon_cls, { title: cfg.minimize.text } );
      _f.con.appendChild( _f.nbtn );
   }
   if ( cfg.maximize.enabled ) {
      _f.mbtn = create_cl_div( cfg.maximize.icon_cls, { title: cfg.maximize.text } );
      _f.con.appendChild (_f.mbtn );
   }
   if ( cfg.close.enabled ) {
      _f.cbtn = create_cl_div( cfg.close.icon_cls, { title: cfg.close.text } );
      _f.con.appendChild( _f.cbtn );
   }

   _f.con.appendChild( _f.client );

   if (cfg.sbar.enabled) {
      _f.sbar = create_cl_div( cfg.sbar.cls );
      _f.con.appendChild( _f.sbar );
      if ( cfg.resize.enabled ) {
         _f.rbtn = create_cl_div( cfg.resize.icon_cls, { title: cfg.resize.text } );
         _f.con.appendChild( _f.rbtn );
      }
   }

   document.body.appendChild( _f.con );

   //
   //	position and paint the fenster
   //
   /*@cc_on
   @if (@_jscript_version <= 5.6) // IE6 or down
      cfg.container.fixed = false;
   @else @*/
      if (cfg.container.fixed) set_style( _f.con, { position: 'fixed' } );
   /*@end @*/
   set_geo( _f.con,    { borderWidth: B } );
   set_geo( _f.tbar,   { left: P, right: P, top: P } );
   set_geo( _f.client, { left: P, borderWidth: cfg.client.border } );
   set_style( _f.client,    { display: 'block', visibility: 'visible' } );
   if ( _f.sbar ) set_geo( _f.sbar, { left: P, right: P, bottom: P } );

   xMoveTo( _f.con, cfg.container.layout.x, cfg.container.layout.y );
   _f.paint( 0, 0 );


   //
   //	find and set the icons positions
   //
   var t = P + B, r = t;
   if ( _f.cbtn ) {
      set_geo( _f.cbtn, { top: t, right: r } );
      r += _f.cbtn.offsetWidth + 2;
   }
   if ( _f.mbtn ) {
      set_geo( _f.mbtn, { top: t, right: r } );
      r += _f.mbtn.offsetWidth + 2;
   }
   if ( _f.nbtn ) {
      set_geo( _f.nbtn, { top: t, right: r } );
   }
   if ( _f.rbtn ) {
      set_geo( _f.rbtn, { right: t, bottom: t } );
   }

   //
   //	register the event listeners
   //
   if ( _f.isIFrame ) {
      _f.href( cfg.client.url );
      if ( cfg.client.fLoad ) {
         xAddEventListener(
            _f.client, 'load', function( ) { cfg.client.fLoad( _f ); }, false );
      }
      _f.client.name = cfg.client.id;
   }
   if ( cfg.container.enable_drag )
      xEnableDrag( _f.tbar, dragStart, h_tbarDrag, dragEnd );
   if ( cfg.resize.enabled )
      xEnableDrag( _f.rbtn, dragStart, h_resize, dragEnd );
   _f.con.onmousedown = _f.focus;
   if ( cfg.minimize.enabled ) _f.nbtn.onclick = h_minimize;
   if ( cfg.maximize.enabled ) _f.mbtn.onclick = _f.tbar.ondblclick = h_maximize;
   if ( cfg.close.enabled ) {
      _f.cbtn.onclick = _f.hide;
      _f.cbtn.onmousedown = xStopPropagation;
   }
   xAddEventListener( window, 'unload', winUnload, false );
   xAddEventListener( window, 'resize', winResize, false );

   xShow( _f.con );
   _f.focus();

   return this;

}

// ----------------------------------------------------------------------------
//    ... end of code   -  cbFenster
// ----------------------------------------------------------------------------

