var debug_is_show = false;
function debug_show(){

	if(debug_is_show) return false;
	debug_is_show = true;	

	var objDebugOutputShow = true;
	var css = "#debug-output{";
	css+="position: absolute;";
	css+="left: 0px;";	
	css+="top: 0px;";
	css+="line-height: 0px;";
	css+="font-size: 0px;";	
	css+="border-bottom: 1px solid #000000;";
	css+="background: #FFFFCC;";
	css+="width: 100%;";
	css+="padding: 0px;";
	css+="z-index: 11;";
	css+="text-align: left;";
	css+="}";		
	css+="#debug-btn{";
	css+="position: absolute;";
	css+="left: 99%;";	
	css+="top: 0px;";		
	css+="background: none;";
	css+="width: 1%;";
	css+="height: 1%;";
	css+="z-index: 11;";
	css+="}";	
	css+="pre{";
	css+="font-size: 12px;";	
	css+="line-height: 12px;";	
	css+="padding: 10px;";
	css+="color: #333;";
	css+="}";		
	
	// style	
	var objDebugStyle = document.createElement("style");
	objDebugStyle.setAttribute("type", "text/css");
	if(objDebugStyle.styleSheet){// IE
		objDebugStyle.styleSheet.cssText = css;
	} else {// w3c
		var cssText = document.createTextNode(css);
		objDebugStyle.appendChild(cssText);
	}	

	// output
	var objDebugOutput = document.createElement("div");
	objDebugOutput.setAttribute('id','debug-output');	
	objDebugOutput.style.display = (objDebugOutputShow) ? '' : 'none';
	objDebugOutput.onclick = function () {
		objDebugOutputShow = (objDebugOutputShow) ? false : true;
		objDebugOutput.style.display = (objDebugOutputShow) ? '' : 'none';
		objDebugBtn.style.display = (!objDebugOutputShow) ? '' : 'none';
		clearCookie("debug");
		debug_is_show = false;
	};	
	

	// button		
	var objDebugBtn = document.createElement("div");
	objDebugBtn.setAttribute('id','debug-btn');
	//objDebugBtn.onmouseover = function () {
	//	objDebugOutputShow = (objDebugOutputShow) ? false : true;
	//	objDebugOutput.style.display = (objDebugOutputShow) ? '' : 'none';
	//	objDebugBtn.style.display = (!objDebugOutputShow) ? '' : 'none';
	//};

	var objBody = document.getElementsByTagName("body").item(0);

	objBody.appendChild(objDebugOutput);
	objBody.appendChild(objDebugBtn);
	objBody.appendChild(objDebugStyle);
		
	log_it("Site running in debug mode. In this yellow area you can see the information about debugging or javascript errors:\r\n");	
}

function debug_output_refresh(){
	if(debug_data != ""){
		var objBody = document.getElementsByTagName("body").item(0);
		if(o = document.getElementById("debug-output"))
			o.innerHTML = "<pre>"+debug_data+"</pre>";
	}

}

var _debug_input_keys = "";
function debug_onkeyaction(e)
{
	if (e == null) { // ie
		keycode = event.keyCode;
	} else { // mozilla
		keycode = e.which;
	}
	key = String.fromCharCode(keycode).toLowerCase();
	_debug_input_keys+=key;
	if(_debug_input_keys.substr(-6).toLowerCase() == "debug"){
		_debug_input_keys = "";
		debug_show();
		setCookie("debug", 1);
	}
}






document.onkeydown = debug_onkeyaction;
start_debug = getCookie("debug");

if(start_debug == 1){
	if(WebKit && WebKit.n.indexOf("msie 5.0") == -1){
		//document.onload = debug_show;
		WebKit.addEvent(window, "load", debug_show);
	}
}
//if(WebKit && WebKit.n.indexOf("msie 5.0") == -1){
	//WebKit.addEvent(window, "error", handleErr);
	//document.onkeydown = debug_onkeyaction;
	//WebKit.addEvent(window, "load", debug_show);
//}
