// xFenster, Copyright 2004-2007 Michael Foster (Cross-Browser.com)
// Part of X, a Cross-Browser Javascript Library, Distributed under the terms of the GNU LGPL

function xFenster(eleId, iniX, iniY, barId, resBtnId, maxBtnId) // object prototype
{
  // Private Properties
  var me = this;
  var ele = xGetElementById(eleId);
  var rBtn = xGetElementById(resBtnId);
  var mBtn = xGetElementById(maxBtnId);
  var x, y, w, h, maximized = false;
  // Public Methods
  this.onunload = function()
  {
    if (!window.opera) { // clear cir refs
      xDisableDrag(barId);
      xDisableDrag(rBtn);
      mBtn.onclick = ele.onmousedown = null;
      me = ele = rBtn = mBtn = null;
    }
  };
  this.paint = function()
  {
	
	
    xMoveTo(rBtn, xWidth(ele) - xWidth(rBtn), xHeight(ele) - xHeight(rBtn));
	
    xMoveTo(mBtn, xWidth(ele) - xWidth(mBtn), 0);
  };
  // Private Event Listeners
  function barOnDrag(e, mdx, mdy)
  {
    // Thanks to Jen for this feature:
    var x = xLeft(ele) + mdx;
    var y = xTop(ele) + mdy;
    if (x < 0) x = 0;
    if (y < 0) y = 0;
    xMoveTo(ele, x, y);
  }
  function resOnDrag(e, mdx, mdy)
  {
    xResizeTo(ele, xWidth(ele) + mdx, xHeight(ele) + mdy);
    me.paint();
  }
  function fenOnMousedown()
  {
    xZIndex(ele, xFenster.z++);
  }
  function maxOnClick()
  {
    
	showDetailsWithResize(ele,ele.id);
  }
  // Constructor Code
  xFenster.z++;
  xMoveTo(ele, iniX, iniY);
  this.paint();
  xEnableDrag(barId, null, barOnDrag, null);
  xEnableDrag(rBtn, null, resOnDrag, null);
  mBtn.onclick = maxOnClick;
//  ele.onmousedown = fenOnMousedown;
  xShow(ele);
} // end xFenster object prototype

xFenster.z = 0; // xFenster static property

function xFensterDrag(eleId, iniX, iniY, barId, maxBtnId) // object prototype
{
  // Private Properties
  var me = this;
  var ele = xGetElementById(eleId);
  var mBtn = xGetElementById(maxBtnId);
  var x, y, w, h, maximized = false;
  // Public Methods
  this.onunload = function()
  {
    if (!window.opera) { // clear cir refs
      xDisableDrag(barId);
      mBtn.onclick = ele.onmousedown = null;
      me = ele = mBtn = null;
    }
  };
  this.paint = function()
  {
	 xMoveTo(mBtn, xWidth(ele) - xWidth(mBtn), 0);
  };
  // Private Event Listeners
  function barOnDrag(e, mdx, mdy)
  {
    // Thanks to Jen for this feature:
    var x = xLeft(ele) + mdx;
    var y = xTop(ele) + mdy;
    if (x < 0) x = 0;
    if (y < 0) y = 0;
    xMoveTo(ele, x, y);
  }
  function resOnDrag(e, mdx, mdy)
  {
    xResizeTo(ele, xWidth(ele) + mdx, xHeight(ele) + mdy);
    me.paint();
  }
  function fenOnMousedown()
  {
    xZIndex(ele, xFenster.z++);
  }
  function maxOnClick()
  {
    
	showDetailsWithDrag(ele,ele.id);
  }
  // Constructor Code
  xFenster.z++;
  xMoveTo(ele, iniX, iniY);
  this.paint();
  xEnableDrag(barId, null, barOnDrag, null);
  mBtn.onclick = maxOnClick;
//  ele.onmousedown = fenOnMousedown;
  xShow(ele);
} // end xFenster object prototype