var Pi2 = 3.1415 * 2;

function extend(Child, Parent) {
    var F = function() { }
    F.prototype = Parent.prototype
    Child.prototype = new F()
    Child.prototype.constructor = Child
    Child.superclass = Parent.prototype
}

function fixPageXY(e) {
	if (e.layerX == null && e.clientX != null ) { 
		var wrapper = document.getElementById('wrapper');
		e.layerX = e.clientX - wrapper.offsetLeft;
		e.layerY = e.clientY - wrapper.offsetTop;
	}
}




function PointLength(X1, Y1, X2, Y2) {
	var Xd =X1 - X2;
	var Yd =Y1 - Y2; 
	return Math.sqrt(Xd*Xd + Yd*Yd);
}

function rand(min, max) {
	return Math.floor( Math.random() * (max - min) + min );
}

function to1(x) {
	return x > 0 ? 1 : x < 0 ? -1 : 0;
}