var Logger = new _Logger();
var loggerWindow = null;
// Logger class
/**
 * A basic Logger class that logs anything to a specified window. The Logger
 * can be useful because it does not disrupt the flow of events on the page.
 * Alerts cause the browser to pause while waiting for an answer. This Logger,
 * simply spits out the provided message to another logging window and allows
 * the browser to continue on regardless of a user response.
 */
function _Logger() {
	this.url = '';
	this.loggerDivId = '';
	this.logItemClass = '';
	this.enabled = false;
	this.windowVisible = false;
	this.logCount = 0;
	this.createLogWindow = _createLogWindow;
	this.getUrl = _getUrl;
	this.getLoggerDivId = _getLoggerDivId;
	this.getLogItemClass = _getLogItemClass;
	this.getEnabled = _getEnabled;
	this.getWindowVisible = _getWindowVisible;
	this.setUrl = _setUrl;
	this.setLoggerDivId = _setLoggerDivId;
	this.setLogItemClass = _setLogItemClass;
	this.setEnabled = _setEnabled;
	this.setWindowVisible = _setWindowVisible;
	this.log = _log;
}
/**
 * Creates the Log Window if the url isn't null and logging has been enabled.
 */
function _createLogWindow() {
	if(this.url && this.enabled) {
		loggerWindow = window.open(this.url, 'Log Window', 'width=500,height=300');
		//loggerWindow.onload = _windowOpening;
		//loggerWindow.onunload = _windowClosing;
	}
}
/**
 * Listens for the window.onload event
 */
function _windowOpening(event) {
	Logger.windowVisible = true;
}
/**
 * Listens to the window.onunload event.
 */
function _windowClosing(event) {
	Logger.windowVisible = false;
	Logger.loggerWindow = null;
}
/**
 * @return the url for the windows html source.
 */
function _getUrl() {
	return this.url;
}
/**
 * @return the element id for the logging div.
 */
function _getLoggerDivId() {
	return this.loggerDivId;
}
/**
 * @return the classname for log items.
 */
function _getLogItemClass() {
	return this.logItemClass;
}
/**
 * @return whether logging is currently enabled.
 */
function _getEnabled() {
	return this.enabled;
}
/**
 * @return whether the logging window is currently visible.
 */
function _getWindowVisible() {
	return this.windowVisible;
}
/**
 * Sets the url containing the html of the logging window.
 */
function _setUrl(url) {
	this.url = url;
}
/**
 * Sets the logging div id.
 */
function _setLoggerDivId(loggerDivId) {
	this.loggerDivId = loggerDivId;
}
/**
 * Sets the classname for the log items.
 */
function _setLogItemClass(logItemClass) {
	this.logItemClass = logItemClass;
}
/**
 * Sets whether logging is currently enabled.
 */
function _setEnabled(enabled) {
	this.enabled = enabled;
}
/**
 * Sets whether the logging window is currently showing.
 */
function _setWindowVisible(windowVisible) {
	this.windowVisible = windowVisible;
	if(this.windowVisible && (!loggerWindow || !loggerWindow.document)) {
		this.createLogWindow();
	}
}
/**
 * Logs a message to the logging window, if logging is enabled.
 */
function _log(message) {
	
	if(this.enabled) {
		if(!this.getWindowVisible()) {
			this.setWindowVisible(true);
		}
		logDiv = loggerWindow.document.getElementById(this.loggerDivId);
		logItemHtml = "<a name=\"" + this.logCount + "\">" + message + "</a>";
		logItem = document.createElement("div");
		logItem.className = this.logItemClass;
		logItem.innerHTML = logItemHtml;
		if(logDiv) {
			logDiv.appendChild(logItem);
			loggerWindow.document.location = this.url + "#" + this.logCount;
			this.logCount++;
		}
	}
}
