/**
 * Simple logging for debug purposes.
 * rand.
 */
var Log = {
		/**
		 * level definitions
		 */
	messageDivId:'msgDiv',	// ID of the message display area
	warn:0, // const
	info:1, // const
	debug:2, // const
	logLevel:0,
	logCount:0,
	getLevelName:function( level ) {
		switch( level ) {
			case 0: return 'WARN';
			case 1: return 'INFO';
			case 2: return 'DEBUG';
			default: return '';
		}
	},
	stackTrace:function() {
	},
	removeMsgDiv:function() {
		var msgDiv = document.getElementById( Log.messageDivId );
		if( msgDiv ) {
			msgDiv.parentNode.removeChild( msgDiv );
		}
	},
	getMsgDiv:function() {
		var msgDiv = document.getElementById( Log.messageDivId );
		if( !msgDiv ) {
			msgDiv = document.createElement( 'div' );
			msgDiv.id = Log.messageDivId;
			document.getElementsByTagName( 'body' )[0].appendChild( msgDiv );
			Events.addListener( msgDiv, 'click', Log.removeMsgDiv, false );
		}
		return msgDiv;
	},
		/**
		 * Create a special "div" on the page and add supplied messages. If creating the "div", set the link
		 * to remove the "div" when clicking on it. This is a DEBUG thing and could be removed.
		 */
	message:function( level, msg ) {
		if( level > Log.logLevel ) {
			return;
		}
		var msgDiv = Log.getMsgDiv();
		var levelName = Log.getLevelName( level );
		var newText = document.createTextNode( ++Log.logCount + ' ' + levelName + ' ' + msg );
		var newPara = document.createElement( 'p' );
		newPara.appendChild( newText );
		msgDiv.appendChild( newPara );
	}
};


/*
function printStackTrace() {
var callstack = [];
var isCallstackPopulated = false;
try {
i.dont.exist+=0; //doesn't exist- that's the point
} catch(e) {
if (e.stack) { //Firefox
var lines = e.stack.split("\n");
for (var i=0, len=lines.length; i<len; i++) {
if (lines[i].match(/^\s*[A-Za-z0-9\-_\$]+\(/)) {
callstack.push(lines[i]);
}
}
//Remove call to printStackTrace()
callstack.shift();
isCallstackPopulated = true;
}
else if (window.opera && e.message) { //Opera
var lines = e.message.split("\n");
for (var i=0, len=lines.length; i<len; i++) {
if (lines[i].match(/^\s*[A-Za-z0-9\-_\$]+\(/)) {
var entry = lines[i];
//Append next line also since it has the file info
if (lines[i+1]) {
entry += " at " + lines[i+1];
i++;
}
callstack.push(entry);
}
}
//Remove call to printStackTrace()
callstack.shift();
isCallstackPopulated = true;
}
}
if (!isCallstackPopulated) { //IE and Safari
var currentFunction = arguments.callee.caller;
while (currentFunction) {
var fn = currentFunction.toString();
var fname = fn.substring(fn.indexOf("function") + 8, fn.indexOf("(")) || "anonymous";
callstack.push(fname);
currentFunction = currentFunction.caller;
}
}
output(callstack);
}
 
function output(arr) {
//Optput however you want
alert(arr.join("nn"));
}
*/

