   function Console(){
     var div,line,area;
     var history=['Dikke duh!'];
     var historyindex=-1;
     var handler=false;
     var me=this;
     var lines=["console version 1.1",""];
     var update=true;
     var numeroflines=200;

     this.hide=function(){
       div.style.display="none";
     }
     this.show=function(){
       div.style.display="block";
     }
      
     this.load=function(){
       var paren=document.body;
       div=document.createElement("div");
       line=document.createElement("input");
       area=document.createElement("textarea");
       div.appendChild(area);
       div.appendChild(document.createElement("br"));
       div.appendChild(line);
       paren.appendChild(div);
       div.className="console";
       area.readOnly=true;
       area.style.width="100%";
       area.style.height="300px";
       area.style.border="0";
       area.style.fontFamily="courier new";
       area.style.fontSize="12px";
       area.spellcheck=false;
       div.style.border="2px solid gray";
       div.style.float='left'
       div.style.width='500';
       div.style.background="white";
       div.style.opacity=".8";
       line.style.width="100%";
       line.style.border="0";
       line.style.margin= "0";
       line.style.fontFamily= "courier new";
       line.style.fontSize= "12px";
       this.scroll();


       area.onfocus=function(){
         line.focus();
       }
       this.topright=function(){
	 div.style.position="absolute";
	 div.style.top="0";
	 div.style.right="0";
       }
       this.leftbottom=function(){
	 div.style.position="absolute";
	 div.style.right="0";
	 div.style.bottom="0";
       }

       line.onkeyup=function(e){
	 var result;
	 switch(e.keyCode){

	     case 13:
	       if(handler){
		 try{
		   result=handler(line.value);
		 }catch(e){
		   result=e;
		 }
	       }else{
		 try{
		   result=(eval(line.value)||"");
		 }catch(e){
		   result=e;
		 }
	       }
	       me.writeln(result);
	       history.push(line.value);
	       historyindex=-1;
	       line.value="";
	     break;
	     case 38://history up
	       if(historyindex==-1){
		 historyindex=history.length-1;
	       }else if(historyindex>0){
		 historyindex--;
	       }
	       if(historyindex!=0){
		  line.value=history[historyindex];
	       }
	     break;
	     case 40://history down
	       if(historyindex==-1){
		 historyindex=history.length-1;
	       }else if(historyindex <history.length-1){
		 historyindex++;
	       }
	       if(historyindex!=0){
		  line.value=history[historyindex];
	       }
	     break;
	 }
       }
       line.focus();
     }
     this.hold=function(){
         update=false;
     }
     this.free=function(){
         update=true;
	 this.scroll();
     }
     this.lines=function(l){
       numeroflines=l*1 ||200;
     }
     this.j=function(o){
      this.writeln(JSON.stringify(o,null," "));
     }
     this.scroll=function(){
         while(lines.length>numeroflines){
	   lines.shift();
	 }
	 if(update){
	   area.value=lines.join("\n");
	   area.scrollTop = area.scrollHeight - area.clientHeight;
	 }
     }
     this.writeln=function(text){
       this.write((text || "")+"\n");
     }
     window.writeln=function(text){
       me.writeln(text);
     }
     window.write=function(text){
       me.write(text);
     }
     this.write=function(text){
       var toadd=(text || "").split(/\n/);
       var n;
       lines[lines.length-1]+=toadd[0];
       for(n=1;n<toadd.length;n++){
	 lines.push(toadd[n]);
       }       
       this.scroll();
     }
     this.clear=function(){
       lines=[""];
       this.scroll()
     }
     this.width=function(w){
       div.style.width=w;
     }
     this.height=function(h){
       area.style.height=h;
     }
     this.handler=function(h){
       if(h){
	 handler=h;
       }else{
	 handler=false;
       }
     }
     
   }
