var newX=0;
var newY=0;
var currentX=0;
var currentY=0;
var obj=null;
var objx=null;
var anim=false;


function setTargetY(_obj,dy,e){
	obj=_obj;
	if(!e) e=event;
	if(auto_c>220) currentY=ban_obj.scrollLeft;
	newY+=dy;
	if(newY>obj.scrollHeight-obj.clientHeight) newY=obj.scrollHeight-obj.clientHeight;
	else if(newY<0) newY=0;
	if(!anim){
		anim=true;
		animation();
	}
}

function setTargetX(_obj,dx,e){
	objx=_obj;
	if(!e) e=event;
	if(auto_c>220){
		currentX=ban_obj.scrollLeft;
		newX=currentX;
		auto_c=0;
	}
	newX+=dx;
	if(newX>objx.scrollWidth-objx.clientWidth) newX=objx.scrollWidth-objx.clientWidth;
	else if(newX<0) newX=0;

	if(!anim){
		anim=true;
		animation();
	}
}

function animation(){
	auto_c=0;
	if(Math.abs(newY-currentY)<1 && Math.abs(newX-currentX)<1) anim=false;
	var vx,vy,lenx,leny;
	if(anim){
		lenx=Math.abs(newX-currentX);
		leny=Math.abs(newY-currentY);
		vx=lenx*lenx/300+lenx/30+1;
		vy=leny*leny/300+leny/30+1;
		if(vx>15) vx=15;
		if(vy>15) vy=15;
		currentX+=sign(newX-currentX)*vx;
		currentY+=sign(newY-currentY)*vy;
		if(objx) objx.scrollLeft=currentX;
		if(obj) obj.scrollTop=currentY;
	//	document.getElementById("test").innerHTML=currentX+"|"+newX+"|"+sign(currentX-newX);
		
		setTimeout("animation()",30);
	}
}
function sign(a){
	if(a==0) return 0;
	if(a<0) return -1; else return 1;
}
