	function WinHandler(bt) {
		this._bt = typeof(bt) == "undefined" ? "t_" : bt;
		this.__list = [];
		this._lastX = -1;
		this._lastY = -1;
		this._posX = -1;
		this._posY = -1;
		this._item = null;
		this._target = null;
		this._parent = null;
		this._direction = -1;
		this._canMove = false;
		this._group = [];
		var _base = this;
		if (typeof(WinHandler._initialized) == "undefined") {
			var _wh = WinHandler.prototype;
			_wh.$ = document.getElementById;
			/*获取基本变量-START*/
			_wh.getBt = function() {
				return this._bt;
			}
			_wh.setBt = function(s) {
				this._bt = s;
			}
			_wh.getIndex = function() {
				return this.getListLength();
			}
			_wh.getList = function() {
				return this.__list;
			}
			_wh.getListLength =function() {
				return this.__list.length;
			}
			_wh.getLastX = function() {
				return this._lastX;
			}
			_wh.setLastX = function(n) {
				this._lastX = parseInt(n);
			}
			_wh.getLastY = function() {
				return this._lastY;
			}
			_wh.setLastY = function(n) {
				this._lastY = parseInt(n);
			}
			_wh.getPosX = function() {
				return this._posX;
			}
			_wh.setPosX = function(n) {
				this._posX = parseInt(n);
			}
			_wh.getPosY = function() {
				return this._posY;
			}
			_wh.setPosY = function(n) {
				this._posY = parseInt(n);
			}
			_wh.getItem = function() {
				return this._item;
			}
			_wh.setItem = function(o) {
				this._item = o;
			}
			_wh.getTarget = function() {
				return this._target;
			}
			_wh.setTarget = function(o) {
				this._target = o;
			}
			_wh.getParent = function() {
				return this._parent;
			}
			_wh.setParent = function(o) {
				this._parent = o;
			}
			_wh.getDirection = function() {
				return this._direction;
			}
			_wh.setDirection = function(n) {
				this._direction = parseInt(n);
			}
			_wh.getCanMove = function() {
				return this._canMove;
			}
			_wh.setCanMove = function(b) {
				this._canMove = b || b == "true" ? true : false;
			}
			_wh.getGroupList = function() {
				return this._group;
			}
			_wh.getGroupListLength = function() {
				return this._group.length;
			}
			_wh.getGroupStr = function() {
				return this._group.join("$");
			}
			/*获取基本变量-END*/
			//根据索引查找元素;
			_wh.getByIndex = function(index) {
				var _index = parseInt(index);
				if (_index > -1 && _index < this.getListLength()) {
					return this.__list[_index];
				}
				return null;
			}
			//根据ID查找元素;
			_wh.getById = function(id) {
				var _len = this.getListLength();
				for (var i = 0; i < _len; i ++) {
					var _entity = this.getByIndex(i);
					if (_entity.getId() == id) {
						return _entity;
					}
				}
				return null;
			}
			//根据label查找元素;
			_wh.getByLabel = function(label) {
				var _len = this.getListLength();
				for (var i = 0; i < _len; i ++) {
					var _entity = this.getByIndex(i);
					if (_entity.getLabel() == label) {
						return _entity;
					}
				}
				return null;
			}
			//计算绝对座标;
			_wh.getABSPos = function(o) {
				var _in = o;
				var _out = {x:0,y:0};
				while (_in != null) {
					_out["x"] += _in.offsetLeft;
					_out["y"] += _in.offsetTop;
					_in = _in.offsetParent;
				}
				return _out;
			}
			//
			//添加元素;
			_wh.addItem = function(label) {
				var _o = this.$(label);
				if (_o != null) {
					var _pos = this.getABSPos(_o);
					this.__list.push(new EntityWin(this.getIndex(),label,_pos["x"],_pos["y"],_o.offsetWidth,_o.offsetHeight));
				}
			}
			//批量添加元素;
			_wh.addItems = function(labels) {
				if (labels != "") {
					var _list = labels.split("|");
					var _len = _list.length;
					for (var i = 0; i < _len; i ++) {
						this.addItem(_list[i]);
					}
				}
			}
			//初始化childNode
			_wh.initializeChildNode = function(o,pid) {
				if (o != null) {
					var _p = this.getById(pid);
					var _id = o.getId();
					if (o.getParentId() > -1) {
						this.deleteChild(this.getById(o.getParentId()),_id);
					}
					if (this.isEmbed(o.getLabel(),_p.getLabel())) {
						o.setOffsetLeft(o.getDefaultLeft() - _p.getDefaultLeft());
						o.setOffsetTop(o.getDefaultTop() - _p.getDefaultTop());
						o.setPosX(o.getOffsetLeft());
						o.setPosY(o.getOffsetTop());
						o.setIsEmbed(true);
					} else {
						o.setPosX(o.getDefaultLeft());
						o.setPosY(o.getDefaultTop());
					}
					//
					o.setParentId(pid);
					if (this.addChild(_p,_id) && _p.getMinLeft() == -1) {
						var _entity = this.getById(_p.getChildList()[_p.getChildListLength() - 1]);
						_p.setMinLeft(_entity.getPosX());
						_p.setMinTop(_entity.getPosY());
					};
				}
			}
			//
			_wh.isEmbed = function(clabel,plabel) {
				var _o = this.$(clabel);
				var _isEmbed = false;
				while (_o != null) {
					if (_o.id == plabel) {
						_isEmbed = true;
						break;
					}
					_o = _o.parentElement;
				}
				return _isEmbed;
			}
			//检测是否已存在;
			_wh.checkExist = function(o,id) {
				var _list = o.getChildList();
				var _len = _list.length;
				for (var i = 0; i < _len; i ++) {
					if (_list[i] == id) {
						return i;
					}
				}
				return -1;
			}
			//删除子节点;
			_wh.deleteChild = function(o,id) {
				if (o != null) {
					var _index = this.checkExist(o,id);
					if (_index > -1) {
						o.getChildList().splice(_index,1);
					}
				}
			}
			//添加子节点;
			_wh.addChild = function(o,id) {
				if (o != null) {
					var _index = this.checkExist(o,id);
					if (_index < 0) {
						o.getChildList().push(id);
						return true;
					}
				}
				return false;
			}
			//生成群组字符串;
			_wh.getGroupItemStr = function(p) {
				return p.getId() + "|" + p.getChildList().join("|");
			}
			//
			_wh.addGroup = function(p) {
				if (p != null) {
					p.setGroupId(this.getGroupListLength());
					this._group.push(this.getGroupItemStr(p));
				}
			}
			//设置所属;
			_wh.addChildNodes = function(p,childstr,padding,direction) {
				var _p = this.getByLabel(p);
				if (_p != null) {
					_p.setDirection(typeof(direction) == "undefined" ? 0 : direction);
					_p.setPadding(typeof(padding) == "undefined" ? 0 : padding);
					var _childList = childstr.split("|");
					var _len = _childList.length;
					for (var i = 0; i < _len; i ++) {
						this.initializeChildNode(this.getByLabel(_childList[i]),_p.getId());
					}
					this.addGroup(_p);
				}
			}
			//初始化;
			_wh.initialize = function() {
				var _len = this.getListLength();
				for (var i = 0; i < _len; i ++) {
					var _entity = this.getByIndex(i);
					//没有父节点的初始X,Y座标;
					_entity.setPosX(_entity.getPosX() == -1 ? _entity.getDefaultLeft() : _entity.getPosX());
					_entity.setPosY(_entity.getPosY() == -1 ? _entity.getDefaultTop() : _entity.getPosY());
					var _o = this.$(_entity.getLabel());
					_o.style.width = _entity.getWidth();
					_o.style.height = _entity.getHeight();
					_o.style.position = "absolute";
					_o.style.left = _entity.getPosX();
					_o.style.top = _entity.getPosY();
					_o.style.zIndex = _entity.getZ();
					this.BTinitialize(_entity.getLabel());
				}
			}
			//按钮初始化(搜索到按钮后定义);
			_wh.BTinitialize = function(label) {
				var _o = this.$(this.getBt() + label);
				if (_o != null) {
					_o.style.cursor = "move";
					_o.onmouseup = function() {	_base.BTmouseUp(_base,this);};
					_o.onmousemove = function() {	_base.BTmouseMove(_base);};
					_o.onmousedown = function() { _base.BTmouseDown(_base,this,label);};
				}
			}
			//返回鼠标座标;
			_wh.getCurMPos = function(e) {
				var _pos = {x:0,y:0};
				_pos["x"] = e.clientX - document.body.clientLeft + document.body.scrollLeft;
				_pos["y"] = e.clientY - document.body.clientTop + document.body.scrollTop;
				return _pos;
			}
			//
			_wh.setProperty = function(o,isfocus) {
				var _o = o;
				if (_o != null) {
					this._setProperty(_o,isfocus);
					var _len = _o.getChildListLength();
					for (var i = 0; i < _len; i ++) {
						var _entity = this.getById(_o.getChildList()[i]);
						this.setProperty(_entity,isfocus);
					}
				}
			}
			//移动初始化;
			_wh.moveInitialize = function(e,ref) {
				var _pos = ref.getCurMPos(e);
				ref.setLastX(_pos["x"]);
				ref.setLastY(_pos["y"]);
				ref.setPosX(parseInt(ref.getTarget().style.left));
				ref.setPosY(parseInt(ref.getTarget().style.top));
			}
			//
			_wh.BTmouseMove = function(ref) {
				if (ref.getCanMove()) {
					var _pos = ref.getCurMPos(event);
					var _offsetX = _pos["x"] - ref.getLastX();
					var _offsetY = _pos["y"] - ref.getLastY();
					ref.getItem().setPosX(ref.getPosX() + _offsetX);
					ref.getItem().setPosY(ref.getPosY() + _offsetY);
					ref.setPosition(ref.getTarget(),ref.getItem().getPosX(),ref.getItem().getPosY());
					//ref.offsetMove(ref.getItem(),_offsetX,_offsetY);
				}
			}
			//
			_wh.BTmouseUp = function(ref,bt) {
				ref.setCanMove(false);
				bt.releaseCapture();
				ref.setLastX(-1);
				ref.setLastY(-1);
				/*ref.getTarget().style.left = ref.getPosX();
				ref.getTarget().style.top = ref.getPosY();*/
				ref.setPosX(-1);
				ref.setPosY(-1);
				if (ref.getItem() != null) {
					ref.getItem().setPosX(ref.getTarget().style.left);
					ref.getItem().setPosY(ref.getTarget().style.top);
					ref.setProperty(ref.getItem(),false);
				}
				if (ref.getParent() != null) {
					ref.getParent().getChildList().sort(ref._compare);
					ref.reOrganize(ref.getParent());
					ref.getGroupList()[ref.getParent().getGroupId()] = ref.getGroupItemStr(ref.getParent());
					//ref.$("jj").value = ref.getGroupStr();
				}
				ref.setDirection(-1);
				ref.setItem(null);
				ref.setParent(null);
				ref.setTarget(null);
			}
			//
			_wh.BTmouseDown = function(ref,bt,label) {
				ref.setCanMove(true);
				bt.setCapture();
				ref.setItem(ref.getByLabel(label));
				//
				ref.setProperty(ref.getItem(),true);
				//
				var _pId = ref.getItem().getParentId();
				if (_pId > -1) {
					ref.setParent(ref.getById(_pId));
				}
				ref.setTarget(ref.$(label));
				ref.moveInitialize(event,ref);
			}
			//对于不被嵌套在内的群组元素相对移动;
			_wh.offsetMove = function(o,offsetx,offsety) {
				/*if (o != null) {
					var _len = o.getChildListLength();
					for (var i = 0; i < _len; i ++) {
						var _id = o.getChildList()[i];
						var _entity = this.getById(_id);
						if (! _entity.getIsEmbed()) {
							_entity.setPosX(_entity.getOffsetLeft() + offsetx);
							_entity.setPosY(_entity.getOffsetTop() > 0 ? offsety + _entity.getOffsetTop() : offsety - _entity.getOffsetTop());
							window.status = _entity.getPosX() + "," + _entity.getPosY();
							this.setPosition(this.$(_entity.getLabel()),_entity.getPosX(),_entity.getPosY());
						}
					}
				}*/
			}
			//
			_wh.setPosition = function(o,x,y) {
				o.style.left = x;
				o.style.top = y;
			}
			//
			_wh._setProperty = function(o,isfocus) {
				var _target = this.$(o.getLabel());
				o.setZ(o.getZ() + (isfocus ? 1000 : -1000));
				_target.style.zIndex = o.getZ() ;
				//window.status = o.getZ() + "," + _target.style.position;
			}
			//获取范围;
			_wh.getRange = function(entity) {
				var _range = {l:-1,t:-1,r:-1,b:-1};
				if (entity != null) {
					_range["l"] = entity.getPosX();
					_range["t"] = entity.getPosY();
					_range["r"] = _range["l"] + entity.getWidth();
					_range["b"] = _range["t"] + entity.getHeight();
				}
			}
			//
			_wh._compare = function(a,b) {
				if (_base.getDirection() == -1) {
					_base.setDirection(_base.getParent().getDirection());
				}
				switch(_base.getDirection()) {
					case 0:
						return _base.getById(a).getPosY() > _base.getById(b).getPosY() ? 1 : -1;
					case 1:
						return _base.getById(a).getPosX() > _base.getById(b).getPosX() ? 1 : -1;
					default:
						return 0;
				}
			}
			//重排;
			_wh.reOrganize = function(pentity) {
				if (pentity != null) {
					var _list = pentity.getChildList();
					var _len = _list.length;
					var _minLeft = pentity.getMinLeft();
					var _minTop = pentity.getMinTop();
					var _direction = pentity.getDirection();
					var _padding = pentity.getPadding();
					for (var i = 0; i < _len; i ++) {
						var _entity = this.getById(_list[i]);
						_entity.setPosX(_minLeft);
						_entity.setPosY(_minTop);
						this.setPosition(this.$(_entity.getLabel()),_entity.getPosX(),_entity.getPosY());
						switch(_direction) {
							case 0:
								_minTop += _entity.getHeight() + _padding;
								break;
							case 1:
								_minLeft += _entity.getWidth() + _padding;
								break;
							default:
								break;
						}
					}
				}
			}
			//
			_wh.checkRange = function(o) {
				var _isOut = false;
				if (o != null) {
					
				}
				return _isOut;
			}
			//
			_wh.importStr = function(s) {
				if (s != "" && s != "undefined" && typeof(s) != "undefined") {
					var _gList = s.split("$");
					var _len = _gList.length;
					for (var i = 0; i < _len; i ++) {
						var _eStr = _gList[i];
						var _pos = _eStr.indexOf("|");
						//window.status = s;
						var _pEntity = this.getById(parseInt(_eStr.substring(0,_pos)));
						if (_pEntity.getDirection() < 3) {
							_pEntity.setChildList(_eStr.substring(_pos + 1).split("|"));
							this.reOrganize(_pEntity);
							this.getGroupList()[_pEntity.getGroupId()] = this.getGroupItemStr(_pEntity);
						}
					}
				}
			}
			WinHandler._initialized = true;
		}
	}