index = 0;
function sploogeObj(layer,speed,elastic) {
	this.layer			= layer;
	this.sploogeActive	= false;
	this.sploogeTimeout	= null;
	this.speed			= speed;
	this.elastic		= elastic;
	this.obj		= "SploogeObj" + index++;
  	eval(this.obj + "=this");

}
sploogeObj.prototype.sploogeInit = new Function("")
sploogeObj.prototype.sploogeTo = SploogeTo
sploogeObj.prototype.sploogeBy = SploogeBy
sploogeObj.prototype.sploogeStart = SploogeStart
sploogeObj.prototype.splooge = Splooge
sploogeObj.prototype.moveTo = MoveTo
sploogeObj.prototype.moveBy = MoveBy
sploogeObj.prototype.onSplooge = new Function("")
sploogeObj.prototype.onSploogeEnd = new Function("")

function SploogeTo(endx,endy,speed,fn) {
	if (endx==null) endx = parseInt(getCss(this.layer).left)
	
	if (endy==null) endy = parseInt(getCss(this.layer).top)
	var distx = endx-parseInt(getCss(this.layer).left)
	var disty = endy-parseInt(getCss(this.layer).top)
	this.sploogeStart(endx,endy,distx,disty,speed,fn)
}
function SploogeBy(distx,disty,speed,fn) {
	var endx = parseInt(getCss(this.layer).left) + distx
	var endy = parseInt(getCss(this.layer).top) + disty
	this.sploogeStart(endx,endy,distx,disty,speed,fn)
}
function SploogeStart(endx,endy,distx,disty,speed,fn) {
	//if (this.sploogeActive) return
	if (!speed) speed = 20
	var num = Math.sqrt(Math.pow(distx,4/this.speed) + Math.pow(disty,4/this.speed))
	if (num==0) return
	var dx = distx/num
	var dy = disty/num
	
	if (!fn) fn = null
	this.sploogeActive = true
	this.splooge(distx,disty,0,0,endx,endy,speed,fn)
}
function Splooge(dx,dy,lx,ly,endx,endy,speed,fn,acc) {
	//if (!this.sploogeActive) return

	if(!acc) acc = .1;
	var distx = endx-parseInt(getCss(this.layer).left);
	var disty = endy-parseInt(getCss(this.layer).top);
	
	if ((!(distx<=1 && distx>=-1)) || (!(disty<=1 && disty>=-1))) {
		var nx = lx; var ny = ly;
		lx = dx; ly = dy;
		acc = acc * this.speed;
		//window.status = acc;
			
		dx	= Math.floor(((distx/4) + (lx * this.elastic))*acc)
		dy	= Math.floor(((disty/4) + (ly * this.elastic))*acc)
		
		this.moveBy(dx,dy)
		this.onSplooge()
		
		clearTimeout(this.sploogeTimeout)
		this.sploogeTimeout = setTimeout(this.obj+".splooge("+dx+","+dy+","+lx+","+ly+","+endx+","+endy+","+speed+",\""+fn+"\","+acc+")",speed)
		
	}
	else {
		//alert("done")
		this.sploogeActive = false
		this.moveTo(endx,endy)
		this.onSplooge()
		this.onSploogeEnd()
		eval(fn)
	}
}

function MoveTo(x,y) {
	if (x!=null) {
		getCss(this.layer).left = x;
	}
	if (y!=null) {
		getCss(this.layer).top = y;
	}
	
}
function MoveBy(x,y) {
	//alert(x + ", " + y)
	(x != 0)? x = parseInt(getCss(this.layer).left)+x : x = null;
	(y != 0)? y = parseInt(getCss(this.layer).top)+y : y = null;
	this.moveTo(x,y);
}