var Drag=function(oElement,oElement2){
	var obj=this;
	this.oElement=oElement;
	this.oElement2=oElement2;
	this.startMouse={x:0,y:0};
	this.startDiv={x:0,y:0};

	oElement.onmousedown=function(ev){
		if(obj.returnTimer){
			clearInterval(obj.returnTimer);
		}//这里是点下去时判断它的位置
		obj.startDrag(ev);
	};


	this.indifineddoDrag=function(ev){
		obj.doDrag(ev);
	};

	this.indifinedstopDrag=function(){
		obj.stopDrag();
	};
};

Drag.prototype.startDrag=function(ev){
	var obj=this;
	var oEvent=window.event || ev;
	this.startMouse.x=oEvent.clientX;
	this.startMouse.y=oEvent.clientY;
	this.startDiv.x=this.oElement2.offsetLeft;
	this.startDiv.y=this.oElement2.offsetTop;


	if(this.oElement.setCapture){
		this.oElement.setCapture();
		this.oElement.onmousemove=function(ev){
			obj.doDrag(ev);
			
		}
		this.oElement.onmouseup=function(ev){
			obj.stopDrag();
			
		}
	}

	else{
		document.addEventListener("mousemove",this.indifineddoDrag,true);
		document.addEventListener("mouseup",this.indifinedstopDrag,true);
		window.captureEvents(Event.MOUSEMOVE | Event.MOUSEUP);
	}
};

/*
Drag.prototype.doDrag=function(ev){
	var oEvent=window.event || ev;
	this.oElement2.style.left=oEvent.clientX-this.startMouse.x+this.startDiv.x+"px";
	this.oElement2.style.top=oEvent.clientY-this.startMouse.y+this.startDiv.y+"px";
	//document.title=oEvent.clientX+":"+this.startMouse.x+"|"+this.startDiv.x+"="+(oEvent.clientX-this.startMouse.x+this.startDiv.x+"px");
	$('.hot').css('z-index','99');
	$('#navContent').css('z-index','5');
};

Drag.prototype.stopDrag=function(){
	if(this.oElement.releaseCapture){
		this.oElement.releaseCapture();
		this.oElement.onmousemove=null;
		this.oElement.onmouseup=null;
		$('.hot').css('z-index','10');
		$('#navContent').css('z-index','15');
	}
	else{
		document.removeEventListener('mousemove',this.indifineddoDrag, true);
		document.removeEventListener('mouseup',this.indifinedstopDrag, true);
	}
	this.returnTimer=null;
	this.oReSpeedl=0;
	this.oReSpeedt=0;
	if(this.returnTimer){
		clearInterval(this.returnTimer);
		this.returnTimer=null;
	}
	this.returnInit();
};
*/
Drag.prototype.returnInit=function(){
	var obj=this;

	if(this.returnTimer){
		clearInterval(this.returnTimer);
	}
	this.returnTimer=setInterval(function(){obj.startReturnMove()},30);
};
Drag.prototype.startReturnMove=function(){
	//document.title=this.oElement2.offsetLeft+"||"+this.oReSpeedl;
	this.oReSpeedl+=(-this.oElement2.offsetLeft/5);
	this.oReSpeedl*=0.75;

	this.oReSpeedt+=(-this.oElement2.offsetTop/5);
	this.oReSpeedt*=0.75;

	//document.title=this.oElement2.offsetLeft+"||"+this.oReSpeedl;

	var l=this.oElement2.offsetLeft+this.oReSpeedl;
	var t=this.oElement2.offsetTop+this.oReSpeedt;
	if(Math.abs(this.oReSpeedl)<0.01 && Math.abs(this.oReSpeedt)<1){
		clearInterval(this.returnTimer);
		l=0;
		t=0;
	}	
	this.oElement2.style.left=l+"px";
	this.oElement2.style.top=t+"px";

};
Drag.prototype.DownTo=function(){
	var obj=this;
	this.slideTimer=null;
	this.slidSpeed=10;
	this.slideTimer=setInterval(function(){obj.doDown();},30);
};
Drag.prototype.doDown=function(){
	this.slidSpeed++;
	var t=this.oElement2.offsetTop+this.slidSpeed;

	if(t>0){
		this.slidSpeed*=-0.5;
		t=0;
	}
	if(Math.abs(this.slidSpeed)<1&&Math.abs(this.oElement2.offsetTop)<1){
		clearInterval(this.slideTimer);
		t=0;
	}
	this.oElement2.style.top=t+"px";
}
$(function(){
	var oDrag=document.getElementById("drag");
	var oDiv=document.getElementById("logo_right");
	if(oDrag){
		var o=new Drag(oDrag,oDiv);
		o.DownTo();
	};
});


