Point  = function(x, y) {
	this.x = x;
	this.y = y;
};
Dimension = function(width, height) {
	this.width = width;
	this.height = height;
}

Overlay = function(displayContainer, offsetDimensions, tail) {
	this.init(displayContainer, offsetDimensions, tail);
}
Overlay.prototype = {	
		init: function(displayContainer, offsetDimensions, tail) {
			this.container = document.getElementById(displayContainer);
			this.offsetDimensions = offsetDimensions;
			this.offsetX = 0;
			this.offsetY = 0;
			this.container.style.position = "absolute";
			this.container.style.left = 0;
			this.container.style.top = 0;
			Event.addEvent(window,"unload", this.unload);
		},
		show: function(e,obj){
			this.localObj = obj;
			this.localObj.offsetX = parseInt(this.localObj.offsetDimensions.x);
			this.localObj.offsetY = parseInt(this.localObj.offsetDimensions.y);
			this.localObj._changeContent(this);
			this.localObj.defaultPositionX = parseInt(this.offsetWidth / 2);
			this.localObj.defaultPositionY = parseInt(this.offsetHeight / 2);	
			this.localObj._calculateOverlayPositionAndSize(this);
			this.localObj._moveContainer();
			
			this.localObj.container.style.visibility = "visible";
			Event.stopEvent(e);
		},
		
		hide: function(e,obj){
			obj.container.style.visibility = "hidden";
		},
		
		setChangeContentCallback: function(f) {
			this._changeContent = f;
			return true;
		},
		
		_changeContent: function() {
			return;
		},
		
		_calculateOverlayPositionAndSize: function(obj) {
			this.posX = Event.getPageX(obj) + this.defaultPositionX + this.offsetX;
			if (this.tailToUse == this.tailOnBottom) {
				this.posY = Event.getPageY(obj) + this.defaultPositionY + this.offsetY - this.container.offsetHeight - 20;
			} else {
				this.posY = Event.getPageY(obj) + this.defaultPositionY + this.offsetY;
			}
			return true;
		},
		
		_moveContainer: function(obj) {
			var scrollPos = this._getScrollingPosition();
			if (document.documentElement.clientWidth < this.posX + this.container.offsetWidth) {
				this.container.style.left = (((this.posX - (this.container.offsetWidth - (document.documentElement.clientWidth - this.posX)))) + scrollPos[0]) + "px";
			} else if (this.posX <= 0) {
				this.container.style.left = (scrollPos[0] + 10) + "px";
			} else {
				this.container.style.left = this.posX +"px";
			}
			this.container.style.top  = this.posY +"px";
		},
		unload: function() {
			this.localObj = null;
			this.container = null;
		}
};
