Mortice.Hoverbox = Class.create(Mortice.Component, {
	initialize: function($super, element, title, width, height) {
		if (!width) {
			width = 400;
		}
		if (!height) {
			height = 300;
		}
		
		// Do we have a link or just some text
		if (typeof(element) == "string") {
			this.frame = new Element("div", {"class": "content"});
			this.frame.innerHTML = element;
		}
		else {
			$super(element);
			var source = this.element.href;
			if (source.indexOf(".gif") == -1) {
				this.frame = new Element("iframe", {
				"src": source,
				"width": width,
				"height": height,
				"scrolling": "no",
				"frameBorder": "no",
				"marginWidth": "0",
				"marginHeight": "0",
				"allowTransparency": "true",
				"class": "frame"
				});
			}
			else {
				this.frame = new Element("img", {
				"src": source
				});
			}
		}
		
		
		this.hoverbox = new Element("div", {
			"class": "hoverbox",
			"style": "display: none"	
		});
		
		this.container = new Element("div", {
			"class": "container",
			"style": "width: " + (width+2) + "px; height: " + (height+2) + "px"
		});
		
		
		
		var header = new Element("div", {
			"class": "header"
		});
		
		
		var close = new Element("a", {
			"class": "close"
		});
		close.innerHTML = "Close";
		close.observe("mousedown", this.hide.bind(this));
		header.appendChild(close);
		
		if(title) {
			var element = new Element("div", {
				"class": "title"
			});
			element.innerHTML = title;
			header.appendChild(element);
		}
		
		this.container.appendChild(header);
		this.container.appendChild(this.frame);
		
		this.hoverbox.appendChild(this.container);
		
		var application = $("application") || $("form");
		
		application.appendChild(this.hoverbox);	
	},
		
	
	show: function() {
		overlay.show();
		this.hoverbox.show();
	},
	
	hide: function() {
		overlay.hide();
		this.hoverbox.hide();
		this.hoverbox.remove();
	}
});

/**
 * Override of the default window alert so it looks nice and pretty.
 * 
 * @param {String} message
 * @param {String} title
 */
window.alert = function(message, title, width, height) {
	if(!title) {
		title = "Alert";
	}
	
	if (!width) {
		width = 400;
	}
	if (!height) {
		height = 200;
	}
	
	var hoverbox = new Mortice.Hoverbox(message, title, width, height);
	hoverbox.show();
	
}
