var Test = {
	
	autoshow: true,
	
	count: 0,
	
	win: null,
	
	container: '',
	
	dump: function(variable, name, show_functions)
	{
		var name = name || "variabele";
		
		var x = '<pre>';
		
		x += Test.create_string(variable, name, show_functions);
		
		if (!Test.win)
		{
			Test.output();
		}
		
		if (Test.win != null || Test.win === false)
		{
			Test.container += x;
			
			if (Test.win !== false)
			{
				Test.win.document.body.firstChild.innerHTML += x + '<br />';
				if(Test.autoshow === true)
				{
					window.blur();
					Test.win.focus();
				}
			}
			else
			{
				Test.output();
			}
		}
		else
		{
			Test.container += x + '<br />';
		}	
		
	},
	
	create_string: function(variable, name, show_functions)
	{
		var x = '';
		
		name = name || '';

		switch (typeof(variable))
		{
			case 'object':
				// object, array of null
				
				
				if (variable == null)
				{
					x = name + ' :null';
				}
				else
				{
						// object, array
						for (var i in variable)
						{
							var type;
							switch (typeof(variable[i]))
							{
								case 'object':
								
									if (variable == null)
									{
										x = name + ' :null';
										x += '<li>' + i + ': null</li>';
									}
									else
									{
										//alert('typeof(variable[i]): ' + typeof(variable[i]) + '\nvariable[i]: ' + variable[i] + '\nvariable: ' + variable);
										if (variable[i].length != undefined)
											type = 'array';
										else
											type = 'object';
											
										x += '<li>' + i + '' + Test.create_string(variable[i], '', show_functions) + '</li>';
									}
								break;
								
								case 'function':
									if (show_functions == true)
									{
										x += '<li>' + i + ' (' + typeof(variable[i]) + ') : ' + variable[i] + '</li>';	
									}
								break;
		
								case 'undefined':
									x += '<li>' + i + ' (' + typeof(variable[i]) + ') : undefined</li>';	
								break;
								
								default:
									//if (variable[i] === null) alert(i+': '+variable[i]);
									x += '<li>' + i + ' (' + typeof(variable[i]) + ') : ' + variable[i] + '</li>';
								break;
							}
							}
							
							var type = (variable.length ? 'array':'object');
							
							x = name + ' (' + type + '):<ul class="object">' + x + '</ul>';
				}
							
			break;
			
			case 'number':
				// int, float	
				x = name + ' (number):\t' + variable;
			break;
							
			case 'string':
				x = name + ' (string):\t' + variable;
			break;
			
			case 'function':
				if (show_functions == true)
				{
					x += '<li>' + i + ' (' + typeof(variable[i]) + ') : ' + variable[i] + '</li>';	
				}
			break;
			
			case 'undefined':
				x = name + ' (undefined):\t' + undefined;
			break;
							
		}
		return x;
		
	},
	
	
	
		
	output : function()
	{
		// 						internet explorer 	|| 	netscape
		var winw = window.document.body.clientWidth 	||	window.innerWidth;
		var winh = window.document.body.clientHeight 	|| 	window.innerHeight;
		
		var width = 400;
		var height = 400;
		var margin = 50;
		
		if (Test.container == '')
		{
			Test.container = "Er zijn (nog) geen tests uitgevoerd...<br />";
		}
		
		if (Test.win === null)	Test.container += '<hr />';
		
		Test.win = window.open("", "Test", "width=" + width + ", height=" + height + ", scrollbars=yes, resizable=1, top=" + (winh - height) + ", left=" + (winw - width - margin));
		
		Test.win.document.open();
		Test.win.document.write('<html>\n');
		Test.win.document.write('<head>\n');
		Test.win.document.write('<title>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Netomzet Javascript Debugger&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</title>\n');
		Test.win.document.write('<style type="text/css">\n');
		Test.win.document.write('	body { font-size: 11px; background: #000; color: #00ff00; font-family: courier; }\n');
		Test.win.document.write('	ul#main { list-style-type: decimal; }\n');
		Test.win.document.write('	ul#main li { padding-left: 0px; }\n');
		Test.win.document.write('	ul.object { list-style-type: none; margin-left: 60px; }\n');
		Test.win.document.write('	hr { border: 1px solid #00aa00; margin-left: -60px; }\n');
		Test.win.document.write('</style>\n');
		Test.win.document.write('<script type="text/javascript">\n');
		Test.win.document.write('window.onload = function()\n');
		Test.win.document.write('{\n');
		Test.win.document.write('	var x = window.opener.Test.container;\n');
		Test.win.document.write('	document.body.firstChild.innerHTML += x;\n');
		Test.win.document.write('	if (document.addEventListener) { document.onkeydown = keydown } else { document.attachEvent("onkeydown", keydown, false) }\n');
		Test.win.document.write('}\n\n');
		Test.win.document.write('function keydown(e)\n');
		Test.win.document.write('{\n');
		Test.win.document.write('	var keynum; if (e.keyCode) { keynum = e.keyCode; } else if (e.which) { keynum = e.which; }; if (keynum == 27) { window.opener.Test.win = false; window.close() }\n');
		Test.win.document.write('}\n');
		Test.win.document.write('</script>\n');
		Test.win.document.write('</head>\n');
		Test.win.document.write('<body><ul id="main"></ul></body>\n');
		Test.win.document.write('</html>');
		Test.win.document.close();	
	}
	
	//,a : addLoadEvent(function() { Test.output(); })
	
}

