//移动
var moveDiv = {
	obj : null,
	init : function(o ,oRoot ,minY ,maxX ,maxY, minX){
		o.onmousedown	= moveDiv.start;
		o.root = oRoot? oRoot : o ;
		o.root.style.left   = o.root.offsetLeft+'px';
		o.root.style.top    = o.root.offsetTop+'px';

		o.minX	= minX? minX : null;
		o.minY	= minY? minY : null;
		o.maxX	= maxX? maxX : null;
	    o.maxY	= maxY? maxY : null;
	},
	unset : function(o){
		o.onmousedown = null;	
	},
	cloneElement : function(o){
		var c = create('DIV');
		c.style.position = 'absolute';
		c.style.width = o.clientWidth + 'px';
		c.style.height = o.clientHeight + 'px';
		c.style.top = o.style.top;
		c.style.left = o.style.left;
		c.style.border = '1px dashed #FFF';
		c.style.zIndex = '1100';
		return c;
	},
	start : function(e){
		e = moveDiv.fixE(e);
		var o = moveDiv.obj = this;
		
		if(moveDiv.isIE())o.setCapture();
		var y = parseInt(o.root.style.top);
		var x = parseInt(o.root.style.left);

		o.lastMouseX = e.clientX;
		o.lastMouseY = e.clientY;

	    if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
	    if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;	
		if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
		if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		moveDiv.timer = setTimeout(function(){Doc.onmousemove = moveDiv.subsidise;},200);
		Doc.onmouseup = function(){clearTimeout(moveDiv.timer);moveDiv.end();}
		return false;
	},
	subsidise : function(){
		procesSelects(0,moveDiv.obj.root);
		moveDiv.obj.moveBox = Doc.body.appendChild(moveDiv.cloneElement(moveDiv.obj.root));
		moveDiv.obj.root.style.zIndex = '800';
		Doc.onmousemove = moveDiv.drag;
	},
	drag : function(e){
		e = moveDiv.fixE(e);
		var o = moveDiv.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.moveBox.style.top);
		var x = parseInt(o.moveBox.style.left);
		var nx, ny;

		if (o.minX != null) ex = Math.max(ex, o.minMouseX);
		if (o.maxX != null) ex = Math.min(ex, o.maxMouseX);
		if (o.minY != null) ey = Math.max(ey, o.minMouseY);
		if (o.maxY != null) ey = Math.min(ey, o.maxMouseY);

		nx = x + ex - o.lastMouseX;
		ny = y + ey - o.lastMouseY;

		o.moveBox.style.left = nx + "px";
		o.moveBox.style.top = ny + "px";
		o.lastMouseX	= ex;
		o.lastMouseY	= ey;
		return false;
	},
	end : function(){
		var o = moveDiv.obj;
		Doc.onmousemove = null;
		Doc.onmouseup   = null;
		if(moveDiv.isIE())moveDiv.obj.releaseCapture();
		if(o.moveBox){
			o.root.style.top = o.moveBox.style.top;
			o.root.style.left = o.moveBox.style.left;
			o.moveBox.parentNode.removeChild(o.moveBox);
			o.moveBox = null;
			o.root.style.zIndex = '1100';
			procesSelects(1,o.root);
		}
		moveDiv.obj = null;
	},
	fixE : function(e){
		if (typeof e == 'undefined')e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	},
	isIE : function() {
	   if(Doc.all) return true;
	   return false;
    }
};
