/*****	路径：newInTow.js	********/
/*****	名称：拖拽类	********/
/*****	作者：应龙	********/
/*****	时间：2009-5-5	********/
/*****	介绍：存放各类拖拽特效	********/
!function (bool){
	//兼容FF一些方法
	if (bool){
		//event
		window.constructor.prototype.__defineGetter__("event", function (){//兼容Event对象
			var o=arguments.callee;
			do{
				if (o.arguments[0] instanceof Event)return o.arguments[0];
			}while (o=o.caller);
			return null;
		});
	}
}(/Firefox/.test(window.navigator.userAgent));
var inTowBase={
	$:function(id){return document.getElementById(id)}
	,tagArr:function(o,name){return o.getElementsByTagName(name)}
	,att:function(o,name,fun){return document.all ? o.attachEvent(name,fun) : o.addEventListener(name.substr(2),fun,false);}
	,style:function(o){	//获取全局样式表、内嵌样式（不能设置）
		return o.currentStyle || document.defaultView.getComputedStyle(o,null);
	}
	,dElement:function(){//兼容DTD头
		return	document.documentElement || document.body;
	}
	,position:function(){//获取当前鼠标位置(x,y)
		return {
		'x':event.pageX || (event.clientX + this.dElement().scrollLeft)
		,'y':event.pageY || (event.clientY + this.dElement().scrollTop)
		}
	}
	,capture:function(obj,num){
		if(document.all){
			num?obj.setCapture():obj.releaseCapture();
		}	
	}
	,cleanOutSelect:function(){
		try {
			document.selection.empty();
		} catch (exp) {
			try {
				window.getSelection().removeAllRanges();
			} catch (exp) {}
		}
	}
	,rewriteAtt:function(formerObj,newObj){//给对象设置属性
		for(var i in newObj){
			formerObj[i]=newObj[i];
		}
		return formerObj;
	}
};
var newInTow=function(newObj){
	this.base=inTowBase;
	var pro=this;
	pro=this.base.rewriteAtt(pro,newObj);
	this.event();
};
newInTow.prototype={
	onOff:false
	,left:-10000,right:10000,top:-10000,bottom:10000
	,event:function(){
		var pro=this;
		this.base.att(document,'onmousemove',function(){if(pro.onOff){pro.move()}});
		this.base.att(document,'onmouseup',function(){if(pro.onOff){pro.up()}});
		if(this.downObj)this.base.att(this.downObj,'onmousedown',function(){pro.down()});
	}
	,down:function(){
		this.base.capture(this.obj,1);
		this.downTop=this.base.position().y-this.obj.offsetTop;
		this.downLeft=this.base.position().x-this.obj.offsetLeft;
		this.onOff=true;
		if(this.downCallBack){this.downCallBack();}
	}
	,move:function(){
		var pos=this.base.position(),pro=this;
		var y=pos.y-this.downTop,x=pos.x-this.downLeft;
		y=y>this.bottom?this.bottom:(y<this.top?this.top:y);
		x=x>this.right?this.right:(x<this.left?this.left:x);
		switch (this.type) {
			case 'vertical' : this.obj.style.top=y+"px";break;
			case 'horizontal' : this.obj.style.left=x+"px";break;
			case 'both' : this.obj.style.top=y+"px";this.obj.style.left=x+"px";break;
		}
		this.base.cleanOutSelect();
		if(this.moveCallBack){this.moveCallBack();}
	}
	,up:function(){
		this.onOff=false;
		this.base.capture(this.obj,0);	
		if(this.upCallBack){this.upCallBack();}
	}
};