
var Log = function($){
	var priv = {
		debug : 0,		//enables/disables the error logging
		level : 0,	 	//default level of debugging (debug : 0, info : 1, warn : 2, error : 3)
		
		console : $("<ul>").addClass("debug-console"),
		
		initConsole : function(){
			//if the console has not yet been added to the document (when no JS console available), do so now
			if(!priv.console.parentNode){
				$("body").append(priv.console);
			} 
		},
		
		//writes the message to the screen, if the error level allows it
		write : function(msg, level){
			if(typeof(level) == "undefined"){
				level = 0;
			}
			
			if(priv.debug && priv.level <= level){
				//check whether debug console exists
				if(typeof(console) != "undefined" && console.log){
					console.log(msg);
				}
				//if no debug console exists: create debug div
				else {
					priv.initConsole();
					$(priv.console).append(
						$("<li>").html(msg.toString())
					);
				}
			}
		}
	};
	
	return {
		Debug  : function(msg){
			priv.write(msg, 0);
		},
		
		Info  : function(msg){
			priv.write(msg, 1);
		},
		
		Warn  : function(msg){
			priv.write(msg, 2);
		},
		
		Error  : function(msg){
			priv.write(msg, 3);
		},
		
		Alert : function(msg){
			if(priv.debug){
				alert(msg);
			}
		},
		
		SetDebugging : function(value){
			priv.debug = value;
		}
	}
}(jQuery);