
function Point(x,y)
{
	if(x)
		this.x = x;
	if(y)
		this.y = y;
	return this;
}
Point.prototype.x = 0;
Point.prototype.y = 0;

Point.prototype.toString = function() { return "Point(" + this.x + "," + this.y + ")";}
Point.prototype.copy = function()
{
	return new Point(this.x, this.y);
}
Point.offsetPoint = function(el)
{
	var x = el.offsetLeft;
	var y = el.offsetTop;
	while((el = el.offsetParent) != null){
		x += el.offsetLeft;
		y += el.offsetTop;
	}
	return new Point(x,y);
}

function Rect(x, y, w, h)
{
	if(x)
		this.x = x;
	if(y)
		this.y = y;
	if(w)
		this.width = w;
	if(h)
		this.height = h;
	return this;
}
Rect.prototype.x = 0;
Rect.prototype.y = 0;
Rect.prototype.width = 0;
Rect.prototype.height = 0;

Rect.prototype.toString = function()
{
	return "Rect(" + this.x + "," + this.y + "," + this.width + "," + this.height + ")";
}

Rect.prototype.copy = function()
{
	return new Rect(this.x, this.y, this.width, this.height);
}
Rect.elementRect = function(el)
{
	if(el){
		var x = el.offsetLeft;
		var y = el.offsetTop;
		var width = el.offsetWidth;
		var height = el.offsetHeight;
		while((el = el.offsetParent) != null){
			x += el.offsetLeft;
			y += el.offsetTop;
		}
		return new Rect(x, y, width, height);
	}
	return new Rect();
}

Rect.zeroRect = function()
{
	return new Rect();
}

Rect.prototype.setElementFrame = function(el)
{
	el.style.left = this.x + "px";
	el.style.top = this.y + "px";
	el.style.width = this.width + "px";
	el.style.height = this.height + "px";
}

function mouseInRect(eventObj, rect)
{
	var p = Point.convertEvent(eventObj);
	return pointInRect(p, rect);
}

function pointInRect(p, rect)
{
	return p.x >= rect.x && p.x < rect.x + rect.width && p.y >= rect.y && p.y < rect.y + rect.height;
}

function setFrame(el, rect)
{
	rect.setElementFrame(el);
}

Point.convertEvent = function(eventObj)
{
	var dx = (window.scrollX != null)? window.scrollX : document.documentElement.scrollLeft;
	var dy = (window.scrollY != null)? window.scrollY : document.documentElement.scrollTop;
	return new Point(eventObj.clientX + dx, eventObj.clientY + dy);
}
