var debug = function(){
	return this
};

debug.prototype.createDumpTable = function( dumpVar , expand , maxDepth ){
	var local = new Object();

	if( maxDepth == null )maxDepth=5;
	if( expand == null )expand=true;

	local.table = document.createElement('TABLE');
	
	local.table.cellPadding = 4;
	local.table.border = 2;

	local.table.style.styleFloat='left';
	local.table.style.cssFloat='left';

	/* create column heads */
		local.newRow			= local.table.insertRow(0);
		local.newCell_title		= local.newRow.insertCell(-1);
		local.newCell_type		= local.newRow.insertCell(-1);
		local.newCell_content	= local.newRow.insertCell(-1);
		
		/* style */
			local.newCell_title.style.textAlign		= 'center';
			local.newCell_type.style.textAlign		= 'center';
			local.newCell_content.style.textAlign	= 'center';

			local.newCell_title.style.fontWeight	= 'bold';
			local.newCell_type.style.fontWeight		= 'bold';
			local.newCell_content.style.fontWeight	= 'bold';

			local.newCell_title.style.backgroundColor	= '#333333';
			local.newCell_type.style.backgroundColor	= '#333333';
			local.newCell_content.style.backgroundColor	= '#333333';

			local.newCell_title.style.color		= 'white';
			local.newCell_type.style.color		= 'white';
			local.newCell_content.style.color	= 'white';
		/* end */
		
		local.newCell_title.innerHTML	= "Name";
		local.newCell_type.innerHTML	= "Type";
		local.newCell_content.innerHTML	= "Value";
	/* end */

	/* set body */
		for( local.x in dumpVar ){
			local.newRow			= local.table.insertRow(-1);
			local.newCell_title		= local.newRow.insertCell(-1);
			local.newCell_type		= local.newRow.insertCell(-1);
			local.newCell_content	= local.newRow.insertCell(-1);
			
			local.newCell_title.innerHTML = local.x;
			local.newCell_type.innerHTML = typeof(dumpVar[local.x]);
			if( typeof(dumpVar[local.x]) == typeof(" ") ){
				if( dumpVar[local.x].length ){
					local.newCell_content.innerHTML = dumpVar[local.x];
				}else{
					local.newCell_content.innerHTML = "<i>Empty String</i>";
				}
			}else if( typeof(dumpVar[local.x]) == typeof(1) ){
					local.newCell_content.innerHTML = dumpVar[local.x];
			}else if( typeof(dumpVar[local.x]) == typeof(new Object()) ){
				if( maxDepth > 0 ){
					local.temp_content = this.createDumpTable( dumpVar[local.x] , expand , (maxDepth-1) );
					local.newCell_content.appendChild( local.temp_content );
				}else{
					local.newCell_content.innerHTML = '<i>MAXIMUM DUMP DEPTH REACHED</i>';
				}
			}else if( typeof(dumpVar[local.x]) == typeof(function(){}) ){
				local.method = document.createElement('PRE');
				local.method.style.fontSize = '10px';
				local.method.innerHTML = dumpVar[local.x];
				local.newCell_content.appendChild( local.method );
			}else{
				local.newCell_content.innerHTML = "<i>Error, unknow variable type</i>";
			}
			
			local.newCell_title.setAttribute( "valign" , "top" );
			local.newCell_type.setAttribute( "valign" , "top" );
			local.newCell_content.setAttribute( "valign" , "top" );

			local.newCell_title.style.backgroundColor	= '#CCCCCC';
			local.newCell_type.style.backgroundColor	= '#DDDDDD';
			local.newCell_content.style.backgroundColor	= 'white';

			if( !expand ){
				local.newCell_title.style.textDecoration = 'underline';
				local.newCell_content.style.display='none';
			}

			/* title only settings */
				local.newCell_title.style.cursor = 'pointer';

				local.newCell_title.onclick = function(){
					var local = new Object();
	
					local.targets = this.parentNode.getElementsByTagName('TD');
	
					if( local.targets[2].style.display=='none' ){
						local.targets[2].style.display='';
						this.style.textDecoration = 'none';
					}else{
						local.targets[2].style.display='none';
						this.style.textDecoration = 'underline';
					}
				}
			/* end */
		}
	/* end */

	return local.table;
}

debug.prototype.dump = function (e){
	var msg='';
	for(x in e)msg+=x+'\n\t'+e[x]+'\n\n';
	return msg;
}

//
	debugPanel_array	= new Array();
	debugArea_array		= new Array();
	debug.prototype.createDebugPanel = function( title ){

			var debugPanel = document.createElement("DIV");
			debugPanel.innerHTML='<div style="text-align:center">&nbsp;&nbsp;' + title + '&nbsp;&nbsp;</div><hr />';
			debugPanel.style.background	= '#DDDDDD';
			debugPanel.style.zIndex		= debugPanel_array.length;
			debugPanel.style.fontSize	= '11px';
			debugPanel.style.border		= '2px groove black';
			debugPanel.style.position	= 'absolute';
			debugPanel.style.padding	= '4px';
			debugPanel.style.top		= '0px';
			debugPanel.style.left		= '0px';
			
			var debugArea = document.createElement("DIV");
			debugArea.style.textAlign	= 'left';
			debugArea.style.height		= '100px';
			debugArea.style.overflow	= 'auto';

			/* set easy to pick-up attributes */
				debugPanel.setAttribute( "debugPanel_id" , debugPanel_array.length );
			/* end */

			/* make visible to user */
				debugPanel.appendChild(debugArea);
				document.body.appendChild(debugPanel);
			/* end */

		debugPanel_array[debugPanel_array.length]	= debugPanel;
		debugArea_array[debugArea_array.length]		= debugArea;

		return debugPanel;
	}
//
	debug.prototype.appendDebugContent = function( msg , debugPanel ){

		if(debugPanel == null){
			var debugPanel = this.createDebugPanel();
			this.appendDebugContent(msg,debugPanel);
		}else{
			var debugPanel_id = debugPanel.getAttribute("debugPanel_id");
			var newItem = document.createElement('LI');
			newItem.innerHTML = msg;
			debugArea_array[debugPanel_id].appendChild( newItem );
		}

		return debugPanel;
	}
//
	debug.prototype.getDebugArea = function(debugPanel){
		return debugPanel.getAttribute("debugArea");
	}


if(OlOs==null){
	document.write("<script type=\"text/javascript\" src=\"OlOs.js\"></script>");
}
OlOs.attachTo( new debug() , "debug" );