
Modalbox.notify = function(message, showOk, options) {
		options = typeof(options) != "undefined"? options : new Object();
		showOk = typeof(showOk) == "undefined"? false: showOk;
		var html = '<div class="MB_alert"><table align="center"><tr><td><img src="' + Cosplay.Base.BASE_URL +'images/alert.gif"/></td><td width="6px"></td><td><b>' + message + '</b></td></tr>';
		if (showOk) {
			html += '<tr><td colspan="3" align="center"><a class="MB_messageButton" href="javascript:Modalbox.__hideMessageBox();"/>OK</a><td></tr>';
		}
		html += '</table></div>';
		options.timeout = typeof(options.timeout) != "undefined"? options.timeout: null;
		Modalbox.showMessage(html, options);
}

Modalbox.message = function(message, showOk, options) {
		options = typeof(options) != "undefined"? options : new Object();
		showOk = typeof(showOk) == "undefined"? true: showOk;
		var html = '<div class="MB_alert"><table align="center"><tr><td align="center"><b>' + message + '</b></td></tr>';
		if (showOk) {
			html += '<tr><td align="center"><a class="MB_messageButton" href="javascript:Modalbox.__hideMessageBox();"/>OK</a><td></tr>';
		}
		html += '</table></div>';
		Modalbox.showMessage(html, options);
}

Modalbox.confirm = function(message, yesScript, noScript, options) {
		options = typeof(options) != "undefined"? options : new Object();
		yesScript = typeof(yesScript) == "undefined"? "": yesScript;
		noScript = typeof(noScript) == "undefined"? "": noScript;
		var html = '<div class="MB_alert"><table align="center"><tr><td align="center"><b>' + message + '</b></td></tr>';
		
		html += '<tr><td align="center"><a class="MB_messageButton" href="javascript:Modalbox.__hideMessageBox(); ' + yesScript + ';"/>YES</a><td>' +
				'<td align="center"><a class="MB_messageButton" href="javascript:Modalbox.__hideMessageBox(); ' + noScript + ';"/>NO</a><td></tr>';
	
		html += '</table></div>';
		Modalbox.showMessage(html, options);
}

Modalbox.zoom = function(imageUrl, showOk, options) {
		options = typeof(options) != "undefined"? options : new Object();
		showOk = typeof(showOk) == "undefined"? true: showOk;
		var img = new Image();
		addEvent(img, 'load', Modalbox.__showImage);
		addEvent(img, 'error', Modalbox.__showNoImage);
		Modalbox.__image = img;
		Modalbox.__showOk = showOk;
		Modalbox.__options = options;
		img.src = imageUrl;
		if(!img.complete) {
			Modalbox.message('Loading image...');
		} else {
			Modalbox.__showImage();
		}
}

Modalbox.__showNoImage = function(direct, count) {
		Modalbox.message('Image not available.', false, {timeout: 5000});
		Cosplay.Mail.sendInternal('Image missing: ' + Modalbox.__image.src, Modalbox.__image.src);
	};

Modalbox.__showImage = function(direct, count) {
		var cd = Cosplay.Dom.getClientDimensions();
		var style = "";
		var options = Modalbox.__options;
		var img = Modalbox.__image;
		if (img.height > cd.height - 150) {
			style += "height: " + (cd.height - 100) + "; ";
		}
		if (img.width > cd.width - 100) {
			style += "width: " + (cd.width - 100) + "; ";
			options.width = cd.width - 100 + 30;
		} else {
			if (style != "") {
				options.width = img.width + 51;
			} else {
				options.width = img.width + 30;
			}
		}
		if (style != "") {
			style += "overflow: auto;";
		}
		var html = '<div class="MB_alert" align="center"><table align="center"><tr><td align="center"><div align="center" style="alignment: center;'
			+ style
			+ '"><a class="MB_imageLink" href="javascript:Modalbox.hide()"><img align="center" src="' + img.src + '"/></a></div></td></tr>';
		if (Modalbox.__showOk) {
			html += '<tr><td align="center"><a class="MB_messageButton" href="javascript:Modalbox.__hideMessageBox();"/>Close</a><td></tr>';
		}
		html += '</table></div>';
		Modalbox.showMessage(html, options);
	};


////

Modalbox.__initializeMessageBox = function() {
		Modalbox.__currentTimerId = null;
		Modalbox.__initializeMessageBox = function() {};
	};
	
Modalbox.__showWithTimeout = function(html, options) {
		Modalbox.__initializeMessageBox();
		if (Modalbox.__currentTimerId != null) {
			clearTimeout(Modalbox.__currentTimerId);
			Modalbox.__currentTimerId = null;

		}
		options.timeout = typeof(options.timeout) != "undefined" && options.timeout != null? options.timeout: 3000;

		Modalbox.__currentTimerId = setTimeout("Modalbox.__hideMessageBox();", options.timeout);
		
		Modalbox.__callback = options.afterHide;
		options.afterHide = function() {
				if(Modalbox.__callback) {
					Modalbox.__callback();
				}
				if (Modalbox.__currentTimerId == null) {
					return;
				}
				clearTimeout(Modalbox.__currentTimerId);
				Modalbox.__currentTimerId = null;
			};
		var noTimeout;
		options.timeout = noTimeout;
		Modalbox.showMessage(html, options);
	};

Modalbox.__hideMessageBox = function() {
		Modalbox.__currentTimerId = null;
		Modalbox.hide();
	};

Modalbox.showMessage = function(html, options) {
	options = typeof(options) != "undefined"? options : new Object();
	if (typeof(options.timeout) == "undefined" || options.timeout == 0) {
			if (options.blocking) {
				if (options.transitioning) {
					Modalbox.__showNormal(html, options);
				} else {
					Modalbox.__showNonTransitioning(html, options);
				}
			} else {
				Modalbox.__showNonBlocking(html, options);
			}
		} else {
			Modalbox.__showWithTimeout(html, options);
		}
	};
	
Modalbox.__showNonBlocking = function(html, options) {
		options.blocking = true;
		Modalbox.showMessage(html, options);
		Modalbox.MBoverlay.hide();
	};

Modalbox.__showNonTransitioning = function(html, options) {
		options.transitioning = true;
		options.transitions = false;
		options.overlayDuration = 0;
		options.slideDownDuration = 0;
		options.slideUpDuration = 0;
		options.overlayOpacity = 0;
		
	//	options.beforeLoad = function() {
	//			
	//			return true;
	//		};
		Modalbox.showMessage(html, options);
		Modalbox.MBwindow.style.Visibility = 'hidden';
		setTimeout("Modalbox.MBwindow.style.Visibility = 'visible';", 300);
	};

Modalbox.__showNormal = function(html, options) {
		options.title = null;
		Modalbox.show(html, options);
	};
	

Modalbox.__originalSetFocus = Modalbox._setFocus;
Modalbox._setFocus = function() {
		try {
			Modalbox.__originalSetFocus();
		} catch(e) {
		}
	};