Modal = function(boxContent) {
	ie6 = ($.browser.msie && $.browser.version < 7);
	this.LOADING = "<div class=\"defaultModalLoading\">Loading...</div>";
	this.ERROR = "<div class=\"defaultModalError\">Error</div>";
	this.allowEsc = true;
	this.xhr = null; // placeholder for an XmlHttpRequest object - to allow aborts when hiding mid-laod
	this.bg = document.createElement("div");
	this.bg.style.position = "absolute";
	this.bg.style.top = "0px";
	this.bg.style.left = "0px";
	this.bg.style.width = "100%";
	this.bg.style.height = ie6 ? $(document).height() : "100%";
	this.bg.style.overflow = "auto";
	this.bg.style.zIndex = "9000";
	this.bg.style.display = "none";
	this.bg.className = "defaultModalBg";

	this.box = document.createElement("div");
	this.box.style.position = "absolute";
	if (ie6) this.box.style.top = "0px";
	this.box.style.display = "none";
	this.box.style.zIndex = "9001";
	this.box.className = "defaultModalBox";
	this.ieFixed = false;
	
	var t = this;
	this.onshow = function() {}
	this.onhide = function() {}

	this.bodyOverflow = document.body.style.overflow;
	this.show = function() {
		this.onshow();

		if (this.allowEsc) {
			$(document).keydown(
				function(event) {
					if (event.keyCode == "27") {
						t.hide();
						$(document).unbind("keydown");
						event.stopPropagation();
					}
				}
			);
		}
		oldScroll = $(document).scrollTop();
		$(document).scroll(
			function(event) {
				$(document).scrollTop(oldScroll);
				debug("scrolled!");
			}
		);

		this.bg.style.top = document.body.scrollTop;
		this.bg.style.display = "block";
		this.bg.style.visibility = "visible";
		this.box.style.display = "block";
		this.box.style.visibility = "visible";
		$(this.box).click(
			function(event) {
				event.stopPropagation();
			}
		)

/* - not sure this is really needed for most versions of IE. Kept it on ie6, though.
		if ($.browser.msie && !this.ieFixed) {
			var l = 0;
			if (!isNaN(parseFloat(this.box.style.left))) {
				l = parseFloat(this.box.style.left);
			}
			this.box.style.left = l + ($(window).width() - $(document).width())/2;
			this.ieFixed = true;
		}
*/
		if (ie6) {
			document.body.scrollTop = 0;
			this.bg.style.top = "0px";
			this.bg.style.height = $(document).height();
			if (!this.ieFixed) {
				var l = 0;
				if (!isNaN(parseFloat(this.box.style.left))) {
					l = parseFloat(this.box.style.left);
				}
				this.box.style.left = l + ($(window).width() - $(document).width())/2;
				this.ieFixed = true;
			}
		} else {
			document.body.style.overflow = "hidden";
		}
	}
	this.hide = function() {
		this.onhide();

		if (this.allowEsc) {
			$(document).unbind("keydown");
		}
		$(document).unbind("scroll");

		if (this.xhr != null) {
			this.xhr.abort();
			this.xhr = null;
		}
		this.setContentText("");
		this.bg.style.display = "none";
		this.bg.style.visibility = "hidden";
		this.box.style.display = "none";
		this.box.style.visibility = "hidden";
		if (ie6) {
			document.body.scrollTop = 0;
		} else {
			document.body.style.overflow = this.bodyOverflow;
		}
	}
	this.setContentFromId = function(id) {
		if (document.getElementById(id)) {
			this.setContentText(document.getElementById(id).innerHTML);
		}
	}
	this.setContentText = function(text) {
		$(this.box).html(text);
	}
	
	if (boxContent) {
		this.setContentText(boxContent);
	} else {
		this.setContentText(this.LOADING);
	}
	
	document.body.appendChild(this.bg);
	if (ie6) {
		document.body.appendChild(this.box);
	} else {
		this.bg.appendChild(this.box);
	}
}

