
if (!("console" in window) || !("firebug" in console)){
	var names = [
			   	"log", "debug", "info", "warn", "error", 
			   	"assert", "dir", "dirxml", "group", 
				"groupEnd", "time", "timeEnd", "count", 
				"trace", "profile", "profileEnd"
			];
	jQuery(document).ready(function(){
		$(document.body).append('<div id="DEBUG"><ol></ol></div>');
	});
	window.console = {};
	for (var i = 0; i < names.length; ++i){
		window.console[names[i]] = function(msg){
			$('#DEBUG ol').append( '<li>' + msg + '</li>' );
		}
	}
}

jQuery.fn.debug = function(){return this.each(function(){$.log(this);});};
jQuery.log = function(message){
	if( window.DEBUG ){
		var str = message;
		if(!('firebug' in console)){
			if( typeof(message) == 'object' ){
				str = '&lt;';
				str += message.nodeName.toLowerCase();
				for( var i = 0; i < message.attributes.length; i++ ){
					str += ' ' + message.attributes[i].nodeName.toLowerCase() + '="' + message.attributes[i].nodeValue + '"';
				}
				str += '&gt;';
			}
		}
		console.debug(str);
	}
};


/**
 * Interface Elements for jQuery
 * Logger
 * 
 * http://interface.eyecon.ro
 * 
 * Copyright (c) 2006 Stefan Petre
 * Dual licensed under the MIT (MIT-LICENSE.txt) 
 * and GPL (GPL-LICENSE.txt) licenses.
 *   
 * $Revision: 1.4 $
 * $Log: ilogger.js,v $
 * Revision 1.4  2006/09/16 06:04:50  Stef
 * *** empty log message ***
 *
 * Revision 1.3  2006/09/09 18:48:14  Stef
 * The logger builds itself on load
 * Parameter 'type' for log function is not mandatory anymore
 *
 * Revision 1.2  2006/09/07 05:19:03  Stef
 * *** empty log message ***
 *
 * Revision 1.1  2006/09/07 05:18:04  Stef
 * *** empty log message ***
 *
 * 
 */

jQuery.iLogger = {
	options : {
		background: '#eee',
		types : {
			notice 	: '#FEFFBF', 
			warning	: '#FFAE5F',
			error	: '#FF5F3F',
			testing	: "#ff6666",
			dbcall	: "#66FF66",
			TODO	: "#ffcc00"
		},
		top: 520,
		right: 0,
		bottom: false,
		left: false,
		width: 800,
		height: 275
	},
	startTime : null,
	lastTime : null,
	logger : null,
	loggerContent : null,
	loggerTypes : null,
	loggerToggler : null,
	loggerClose : null,
	paused : false,
	
	showLogs : function(e)
	{
		logType = jQuery(this).attr('logType');
		
		if(logType) {
			jQuery('.iLogger_' + logType, jQuery.iLogger.loggerContent.get(0)).show();
			jQuery(this).css('textDecoration', 'none');
		}
	},
	
	hideLogs : function(e)
	{
		logType = jQuery(this).attr('logType');
		
		if(logType) {
			jQuery('.iLogger_' + logType, jQuery.iLogger.loggerContent.get(0)).hide();
			jQuery(this).css('textDecoration', 'line-through');
		}
	},
	
	toggleContent : function(e)
	{
		if (jQuery.iLogger.loggerContent.css('display') == 'none') {
			jQuery.iLogger.showContent();
		} else {
			jQuery.iLogger.hideContent();
		}
	},
	
	hideContent : function()
	{
		jQuery.iLogger.loggerContent.hide();
		jQuery.iLogger.loggerTypes.hide();
		jQuery.iLogger.loggerToggler.html('[+]');
	},
	
	showContent : function()
	{
		jQuery.iLogger.loggerContent.show();
		jQuery.iLogger.loggerTypes.show();
		jQuery.iLogger.loggerToggler.html('[-]');
	},
	hideLogger : function ()
	{
		jQuery.iLogger.logger.hide();
	},
	
	pauseLogging : function()
	{
		jQuery.iLogger.paused = true;
	},
	
	resumeLogging : function()
	{
		jQuery.iLogger.paused = false;
	},
	
	clearLogs : function()
	{
		jQuery.iLogger.loggerContent.empty();
	},
	
	toggleFunction : function(el)
	{
		functionCode = jQuery(el).next();
		if (functionCode.css('display') == 'none') {
			functionCode.css('display', 'block');
			jQuery(el).html('[-]');
		} else {
			functionCode.css('display', 'none');
			jQuery(el).html('[+]');
		}
	},
	
	log : function(message, type, source)
	{
		if(DEBUG){
			if (!type)
				type = 'notice';
			if (jQuery.iLogger.options.types[type] && jQuery.iLogger.paused == false) {
				now = new Date();
				diffTime = now - jQuery.iLogger.startTime;
				diffTimeLast = now - jQuery.iLogger.lastTime;
				dateString = now.toLocaleDateString();
				timeString = now.toLocaleTimeString();
				jQuery.iLogger.lastTime = now;
				jQuery.iLogger.loggerContent.append(
					'<p style="background-color: ' + jQuery.iLogger.options.types[type] + '; padding: 5px; margin: 0 0 1px 0;font-size:12px" class="iLogger_' + type + '">'+
						'<strong>' + type + '</strong> ' + diffTime + 'ms (' + diffTimeLast + 'ms )<br />' + 
						timeString + ' ' + dateString + '<br />'+
						(source ? '<strong>' + source + '</strong>:' : '') + message + 
					'</p>'
				);
				jQuery.iLogger.loggerContent.get(0).scrollTop = jQuery.iLogger.loggerContent.get(0).scrollHeight;
				if($.browser.mozilla){
					$.log("["+type+"] " + diffTime + 'ms (' + diffTimeLast + 'ms )');
					$.log(timeString + ' ' + dateString);
					$.log((source ? '<strong>' + source + '</strong>:' : '') + message);
					$.log('-------------------------------------------------------------------')
				}
			}
		}
	},
	
	logObj : function(el)
	{
		if (el && el.tagName) {
			this.log(el.toString(), 'notice', el.tagName);
		} else if (el && el.constructor) {
			consName = el.constructor.toString();
			end = consName.indexOf('(');
			realName = consName.substring(9,end);
			
			if (el.constructor == Function) {
				functionString = el.toString()
				functionName = functionString.substring(9,functionString.indexOf('('));
				if (functionName == '') {
					functionName = 'Anonymous';
				}
				message = functionName + ' <a href="#" onclick="jQuery.iLogger.toggleFunction(this)">[+]</a><code style="display: none;">' + functionString + '</code>';
			} else {
				message = el.toString();
			}
			this.log(message, 'notice', realName);
		} else if (!el) {
			this.log(el == null ? 'null' : 'empty', 'notice', typeof el);
		}
	},
	
	handler: function (msg,url,l)
	{
		jQuery.iLogger.log("Javascript: " + msg, 'error', url + ' line: ' + l);
		return true
	},
	
	build : function (options){
		for (i in options) {
			this.options[i] = options[i];
		}
		logger = 
			'<div id="iLogger" style="z-index:1000;position: absolute; background-color: '+ this.options.background + ';' +
			'padding: 10px;font-family: \'Courier New\', Courier, monospace; font-size: 11px;' + 
			(typeof this.options.top == 'number' ? 'top:' + this.options.top + 'px;':'')+
			(typeof this.options.right == 'number' ? 'right:' + this.options.right + 'px;':'')+
			(typeof this.options.bottom == 'number' ? 'bottom:' + this.options.bottom + 'px;':'')+
			(typeof this.options.left == 'number' ? 'left:' + this.options.left + 'px;':'')+
			'">'+
			'<a href="#" style="color: #000; text-decoration: none;" id="iLoggerToggle">[-]</a>' +
			' <a href="#" style="color: #000; text-decoration: none;" id="iLoggerClose">[X]</a>' +  
			' <a href="#" style="color: #000; text-decoration: none;" id="iLoggerClear">[C]</a>' +  
			'<div id="iLoggerLogs" style="overflow: auto; margin-top: 10px;background-color: #fff; color: #000;'+
			(typeof this.options.width == 'number' ? 'width:' + this.options.width + 'px;':'')+
			(typeof this.options.height == 'number' ? 'height:' + this.options.height + 'px;':'')+
			'"></div>' + 
			'<div id="iLogerTypes" style="padding-top: 10px;">';
		for (i in this.options.types) {
			logger += 
				'<a href="#" id="iLogger_' + i + '"' +
				'style="color: #000; background-color: ' + this.options.types[i] + '; text-decoration: none;">' +
				i + '</a> ';
		}
		logger += 
			'</div>'+
			'</div>';
		$('body', document).append(logger);
		
		jQuery.iLogger.logger = jQuery('#iLogger');
		jQuery.iLogger.loggerContent = jQuery('#iLoggerLogs', jQuery.iLogger.logger.get(0));
		jQuery.iLogger.loggerTypes = jQuery('#iLogerTypes', jQuery.iLogger.logger.get(0));
		jQuery.iLogger.loggerToggler = jQuery('#iLoggerToggle').click(jQuery.iLogger.toggleContent);
		jQuery.iLogger.loggerClose = jQuery('#iLoggerClose').click(jQuery.iLogger.hideLogger);
		jQuery.iLogger.loggerClear = jQuery('#iLoggerClear').click(jQuery.iLogger.clearLogs);
		for (i in this.options.types) {
			$('#iLogger_' + i).attr('logType', i).toggle(
				jQuery.iLogger.hideLogs,
				jQuery.iLogger.showLogs
			);
		}
		jQuery.iLogger.startTime = jQuery.iLogger.lastTime = new Date();
	}
};
jQuery(document).ready(
	function()
	{
		if(DEBUG){
			$.iLogger.build();
		}
	}
);
window.onerror = jQuery.iLogger.handler;