modalWindow = {
	parent:"body",
	windowId:null,
	content:null,
	width:null,
	height:null,
	close:function()
	{
		jQuery(".modal-window").remove();
		jQuery(".modal-overlay").remove();
		try {
			delete window.frames["modalWin"];
		}
		catch(err) {};
		
	},
	hide:function() {
		jQuery(".modal-window").hide();
		jQuery(".modal-overlay").hide();
	},
	show:function() {
		jQuery(".modal-window").show();
		jQuery(".modal-overlay").show();
		
		//
	},
	open:function()
	{
		var modal = "";
		modal += "<div class=\"modal-overlay\"></div>";
		var newTop = jQuery(document).scrollTop() + ((jQuery(window).height() - this.height)/2);
		modal += "<div id=\"" + this.windowId + "\" class=\"modal-window\" style=\"width:" + this.width + "px; height:" + this.height + "px; top:" + newTop + "px; margin-left:-" + (this.width / 2) + "px;\">";
		
		modal += this.content;
		modal += "</div>";	

		jQuery(this.parent).append(modal);
		jQuery(".modal-overlay").click(function(){modalWindow.hide();});
		if (this.source.length) {
			var win = window.frames["modalWin"]
			win.document.open();
			win.document.write("<div style='background: url(indicator.gif) no-repeat center;position:absolute;top:0;width:97%;height:97%;'></div>");
			win.document.close();
			setTimeout("window.frames['modalWin'].document.location.href = modalWindow.source;", 200);
		}
		
		
		if (jQuery.fn.bgiframe) {
			jQuery(".modal-overlay").bgiframe({opactity: false});
			var bgframe = jQuery("iframe.bgiframe");
			if (bgframe.length) {
				bgframe.attr('src', 'closer.htm');
			}
		}
		
	},
	loaded:function() {
		jQuery("#myModal").removeClass("waiting");
	}
};

var openModal = function(source, width, height, content)
{
	modalWindow.windowId = "myModal";
	modalWindow.width = width;
	modalWindow.height = height;
	modalWindow.source = source;
	
	if (modalWindow.height > jQuery(window).height()) {
		modalWindow.height = jQuery(window).height() - 20;
	}
	
	if (source.length) { //then create the iframe
		if (typeof openModalLastSource == 'undefined') {
			openModalLastSource = '';
		}
		if (jQuery(".modal-window").length) {
			if (openModalLastSource == source) {
				modalWindow.show();
				return;
			} else {
				modalWindow.close();
			}
		}
		openModalLastSource = source;
		var fullWidth = (Number(modalWindow.width)+17).toString();
		modalWindow.content = "<iframe allowtransparency='false' name='modalWin' style='background-color:#fff;width:" + fullWidth + "px; height:" + modalWindow.height + "px; border: 1px #000 solid;' frameborder='1' scrolling='yes' src=''></iframe>";
	} else {
		modalWindow.content = content;
	}
	modalWindow.open();
};

