/*Navi, an autoscroller that only works in Mozilla Firefox. Use it by holding Ctrl and moving the mouse around.
Copyright 2005 Eliazar Parra Cardenas.*/
function Dir(axis, cush, pcent) { 
	this.axis = axis, this.cush = cush, this.pcent = pcent, this.going = 0, this.momentum = 0
	this.range = axis=='x'? innerWidth : innerHeight //you need an onresize in the body, to keep this always accurate
	this.jump = axis=='x'? function(d) {return scrollBy(d, 0)} : function(d) {return scrollBy(0, d)}
}
Dir.prototype.toString = function() { return this.axis }
Dir.prototype.opp = function() { return eval(this.axis=='x' ? 'y':'x') }
Dir.prototype.mover = function() {
	var d = this.now-this.old //delta
	if(d!=0) {
		var dd = Math.abs(d)/d //delta dir
		if(this.going==dd) return;
		if(this.going==-dd) this.halt()
		else {
			if(Math.abs(this.opp().momentum) < 10) {
				this.opp().halt()
				this.jump(d)
				this.momentum = Math.min(2*this.cush, this.momentum+Math.abs(d)) //accelerating
				this.swoosh(d, dd)
			}
			else this.opp().momentum = Math.max(0, this.opp().momentum-Math.abs(d)) //deccelerating
		}
	}
}
Dir.prototype.swoosh = function(d, dd) {
	if(((dd==1)&&(this.now>this.range*(1-this.pcent)))||((dd==-1)&&(this.now<this.range*this.pcent)))
		this.going = dd, this.swoosher(d, dd, 0)
}
Dir.prototype.swoosher = function(d, dd, a) {
	if(this.going!=dd) return;		
	this.jump(d+dd*(500-dd*d)*(Math.pow(a/100, 6)))
	setTimeout(this+'.swoosher('+d+','+dd+','+(a+=(a<100?1:0))+')', 10)
}
Dir.prototype.halt = function() {this.going = 0}

x = new Dir('x', 20, 0.20)
y = new Dir('y', 100, 0.20)
	 
function navi() {
	if(!ctrl_down) return;
	document.body.style.cursor = 'move'
	window.status = "You're naving!"
	x.mover(), y.mover()
}

