var AitPopup = Class.create();
AitPopup.prototype = {
	initialize: function(content, width, height, posX, posY, opacity) {
		this.windowDimensions = document.viewport.getDimensions();
                this.scrollOffsets = document.viewport.getScrollOffsets();
		this.width = (width) ? parseInt(width) : 240;
		this.height = (height) ? parseInt(height) : 400;
		this.posX = (posX) ? parseInt(posX) : Math.floor((this.windowDimensions.width - this.width) * 0.5) + this.scrollOffsets.left;
		this.posY = (posY) ? parseInt(posY) : Math.floor((this.windowDimensions.height - this.height) * 0.5) + this.scrollOffsets.top;
		this.height = (height) ? parseInt(height) + 'px' : 'auto';
		this.opacity = (opacity) ? parseFloat(opacity) : 1;
		this.content = content;
		this.id = 'aitpopupsingleton';
		this.display();

	},

	display: function() {
		if ($(this.id) != null) {
			obj = $(this.id);
		} else {
			obj = $(document.createElement("div"));
			document.body.appendChild(obj);
			obj.writeAttribute({"id": this.id, "class": "aitpopup"});
			obj.observe('click', this.hide.bind(this));
		}
		obj.update(this.content);
		obj.absolutize();
		obj.setStyle({top: this.posY + "px", left: this.posX + "px", width: this.width + "px", height: this.height, "z-index": 100});
		obj.setOpacity(this.opacity);

		obj.show();
	},

	hide: function() {
		if (typeof $(this.id) != "undefined") {
			$(this.id).hide();
		}
	}
};
/*Event.observe(window, 'load', function() {
	var myPopup = new AitPopup('Test Popupa<br /><a href="http://google.com">Google</a>', 300, 100, 50, 0.7);
});*/
