//Shows debug information
//Requires jquery
var debug =true;
var browserHeight;
		var oriHeight=null;
		$(document).ready(function(){
			fixHeight();
			$(window).resize(function(){
				fixHeight();
			});
			try{
				if($('#debug').html().length > 1)
					out($('#debug').html());
					//out($('#debug').html().length);
			}catch(e){}
		});
		function fixHeight(){ //will work if body contains div with id="background" without height set
			if(navigator.userAgent.indexOf("MSIE")>0){
				browserHeight=$(window).height();
			}else{
				browserHeight=window.innerHeight;
			}
			if(oriHeight==null){
				oriHeight=document.body.offsetHeight;
				//$("#background").css("height",oriHeight);
			}
			if(browserHeight>$('body').innerHeight() || (oriHeight!=null && browserHeight>oriHeight)){
				//$("#background").css("height",browserHeight);
			}
		}
		
	String.prototype.replaceAll=function(s,r){
		return this.split(s).join(r);
	}
		
function out(str){
	if(debug){
		var Stamp = new Date();
		var Hours = Stamp.getHours();
		if(Hours<10)
			Hours="0"+Hours;
		var Mins = Stamp.getMinutes();
		if(Mins<10)
			Mins="0"+Mins;
		var Seconds = Stamp.getSeconds();
		if(Seconds<10)
			Seconds="0"+Seconds;
		str=""+Hours+":"+Mins+":"+Seconds+" "+xa(str,0);
		height=browserHeight/1.7;
		width=$('body').innerWidth()/2;
		ieAddWidth=0;
		if(navigator.userAgent.indexOf("MSIE")>0){
			ieAddWidth=-20;
		}
		try{
			var tmp=document.getElementById('debugDIV').id;
			$('#debugDIV').prepend(str+"<br><br>");
			$('#debugDIV').css("top",(browserHeight-height-5));
			$('#debugDIV').css("height",height+"px");
			$('#debugDIV').css("left",($('body').innerWidth()-width+ieAddWidth-5));
			$('#debugDIV').css("width",width+"px");
		}catch (e) {
			$(document.body).append("<div id='debugDIV' style='font-size:11px;top:"+(browserHeight+$(document).scrollTop()-height-5)+"px;left:"+($('body').innerWidth()-width+ieAddWidth-5)+"px;height:"+height+"px;width:"+width+"px;overflow:auto;z-index:1000;background-color:#c0c0c0;border:1px solid #000000;position:absolute;text-align:left;' onclick='if(!outHold){this.style.width=$(\"body\").innerWidth()/2;this.style.left=($(\"body\").innerWidth()-$(\"body\").innerWidth()/2+ieAddWidth-5);if(this.style.height==\"15px\"){this.style.top=(browserHeight+$(document).scrollTop()-(browserHeight/1.3+5));this.style.height=browserHeight/1.3+\"px\";}else{this.style.height=\"15px\";this.style.top=(browserHeight+$(document).scrollTop()-20);}$(window).scroll();}'>"+str+"</div>");
			$('#debugDIV').fadeTo(0,0.8);
			$(window).resize(function(){
				width=$('body').innerWidth()/2;
				$('#debugDIV').css("top",(browserHeight+$(document).scrollTop()-$("#debugDIV").css('height').split("px")[0]-5));
				$('#debugDIV').css("left",($('body').innerWidth()-width+ieAddWidth-5));
				$('#debugDIV').css("width",width+"px");
			});
			$(window).scroll(function(){
				$('#debugDIV').css("top",(browserHeight+$(document).scrollTop()-$("#debugDIV").css('height').split("px")[0]-5));
				$('#debugDIV').css("left",($('body').innerWidth()-width+ieAddWidth-5));
				$('#debugDIV').css("width",width+"px");
			});
		}
	}
}
var outTmp=Array();
var RunWhenDone=Array();
var outUid=1;
var outHold=false;
function xa(arr,steps){
	//out(1);
	if(debug){
		var res="";
		var step="";
		var color="black";
		for(j=0;j<steps;j++)
			step=step+"&nbsp;&nbsp;&nbsp;";
		//alert(typeof(arr));
		if(typeof(arr)=="object" || typeof(arr)=="array" || typeof(arr)=="function"){
			//out(2);
			if(typeof(arr)=="function"){
				res=res+"<br><b style='font-size:11px;'>"+step+"[<b style='color:darkblue;'>function</b>]</b> = <span><b style='cursor:pointer;' onclick='if(!outHold){if($(this).parent().find(\"span\").css(\"display\")==\"none\"){$(this).parent().find(\"span\").show(0);}else{$(this).parent().find(\"span\").hide(0);}outHold=true;setTimeout(\"outHold=false;\",100);}'>&nbsp;+/-</b><span style='display:none;'><br><textarea style='width:90%;height:150px;'>"+(arr+"").replace("function","")+"</textarea></span></span>";
			}else{
				var flagx=false;
				for (var i in arr){
					//out(3);
					try{
						var flag=false;
						if(typeof(arr[i])=="function"){
							res=res+"<br><b style='font-size:11px;'>"+step+"[<b style='color:darkblue;'>"+i+"</b>]</b> = { <span><b style='cursor:pointer;' onclick='if(!outHold){if($(this).parent().find(\"span\").css(\"display\")==\"none\"){$(this).parent().find(\"span\").show(0);}else{$(this).parent().find(\"span\").hide(0);}outHold=true;setTimeout(\"outHold=false;\",100);}'>&nbsp;+/-</b><span style='display:none;'><br><textarea style='width:90%;height:150px;'>"+(arr[i]+"").replace("function "+i+"()","")+"</textarea></span></span>";
						}else if(typeof(arr[i])=="object" || typeof(arr[i])=="array"){
							flag=true;
							res=res+"<br><b style='font-size:11px;'>"+step+"["+i+"]</b> = { <b style='cursor:pointer;' onclick='if(!outHold){if($(\"#out_"+outUid+"\").html()==\"\"){loop(\"out_"+outUid+"\");outHold=true;setTimeout(\"outHold=false;\",100);}else{$(\"#out_"+outUid+"\").html(\"\");outHold=true;setTimeout(\"outHold=false;\",100);}}'>&nbsp;+/-</b><span id='out_"+outUid+"'></span></b>";// "+xa(arr[i],steps+1)+"</b>";
							outTmp["out_"+outUid]={arr:arr[i],step:steps+1};
							if(steps==0){
								setTimeout("loop(\"out_"+outUid+"\");",100);
							}
							outUid++;
						}else{
							res+="<br><b style='font-size:11px;'>"+step+"["+i+"]</b> = { "+xa(arr[i],steps+1)+"</b>";
						}
						if(flag){
							res=res+"<br>"+step;
						}
						res=res+" }";
						//out(4);
						flagx=true;
					}catch(e){
						res=res+"<br><b style='font-size:11px;'>"+step+"["+i+"]</b> = { <b style='color:red;'>error</b> }";
					}
				}
				if(!flagx){
					res+="<br><b style='font-size:11px;'>"+step+"[?]</b> = { "+arr+" }</b>";
				}
			}
		}else{
			if(typeof(arr)=="int" || typeof(arr)=="double" || typeof(arr)=="float" || typeof(arr)=="decimal")
				color="blue";
			else if(typeof(arr)=="string")
				color="purple";
			else if(typeof(arr)=="char")
				color="yellow";
			else if(typeof(arr)=="boolean" && arr==true)
				color="green";
			else if(typeof(arr)=="boolean" && arr==false)
				color="red";
			else if(typeof(arr)=="undefined")
				color="teal";
			if(arr==null){
				arr="null";
				color="teal";
			}
			//out(5);
			res="<b style='color:"+color+";font-size:11px;'>"+arr+"</b>";
		}
		//out(6);
		return res;
	}else{
		return "?";
	}
}
function loop(id){
	$("#"+id).html(xa(outTmp[id].arr,outTmp[id].step));
}
function placeContent(content){
	$("#content").html(content);
}

