function eventX(e){
return window.event ? window.event.x : e.pageX;
}
function eventY(e){
return window.event ? window.event.y : e.pageY;
}


function row(){
	this.on=1;
	this.objName="row";
	this.text="text";
	this.direction='left';
	this.speed=6;
	this.activate=activate_row;
	this.obj=document.createElement("marquee");
}

function activate_row(){
	document.getElementById(this.objName).appendChild(this.obj);
	this.obj.innerHTML=this.text;
	this.obj.direction=this.direction;
	this.obj.scrollAmount=this.speed;
	
	this.obj.setAttribute("lastspeed",this.speed);
	this.obj.lastspeed=this.speed;
	this.obj.setAttribute("on",1);
	this.obj.on=1;
	this.obj.setAttribute("acceleration",this.acceleration);
	this.obj.acceleration=this.acceleration;
	
	rl=((this.direction=='right' || this.direction=='left')?1:0);
	
	this.obj.setAttribute("oback",(rl?"right":"down"));
	this.obj.oback=(rl?"right":"down");
	this.obj.setAttribute("oforward",(rl?"left":"up"));
	this.obj.oforward=(rl?"left":"up");
	
	this.obj.setAttribute("ofcursor",(rl?"e-resize":"n-resize"));
	this.obj.ocursor=(rl?"e-resize":"n-resize");
	this.obj.style.cursor=(rl?"e-resize":"n-resize");
	
	this.obj.onmousemove=function(e){control(this,e)};
	this.obj.onclick=function(e){onoff(this)};
}

function control(obj,e){
	if(obj.on){
		if(obj.direction=='right' || obj.direction=='left'){
			mid=Math.round(obj.offsetWidth/2);
			amount=eventX(e)-obj.offsetLeft-mid;
		}
		else{
			mid=Math.round(obj.offsetHeight/2);
			amount=eventY(e)-obj.offsetTop-mid;
		}
		obj.direction=(amount>0?obj.oback:obj.oforward);
		speed=Math.round(Math.abs(amount)/mid*obj.acceleration);
		obj.scrollAmount=speed;
		
		//status="eventX: "+mid+" offsetLeft: "+obj.offsetLeft+" offsetWidth: "+obj.offsetWidth;
		//status="speed: "+speed;
	}
}

function onoff(obj){
	if(obj.on){
		obj.on=0;
		obj.lastspeed=obj.scrollAmount;
		obj.scrollAmount=0;
		obj.style.cursor="default";
	}
	else{
		obj.on=1;
		obj.scrollAmount=obj.lastspeed;
		obj.style.cursor=obj.ocursor;
	}
}


