function debug(){
  //properties
  this.on = false;
  this.debugWindow;
  //methods
  this.debugOn = debugOn;
  this.createDebugWindow = createDebugWindow;
  this.displayDebugMessage = displayDebugMessage;
  this.dm = dm;
  this.dv = dv;
  this.de = de;
}

function debugOn(){
  this.on = true;
  //this.createDebugWindow();
}

function createDebugWindow(){
  this.debugWindow  = window.open('','debugWindow','resizable=yes,menubar=no,toolbar=no,scrollbars=yes,width=200,height=200');
  this.debugWindow.document.open('text/html','replace');
  this.debugWindow.document.write('<html><head><style type="text/css">body{background-color:#000;color:#0f0;font-size:8pt;font-family:monospace;}</style></head><body><div id="debug_content"></div></body></html>');
}
//main display function
function displayDebugMessage(message){
  if(!this.debugWindow || this.debugWindow.closed) this.createDebugWindow();
  //this.createDebugWindow();
  this.debugWindow.focus();
  var oBody = this.debugWindow.document.getElementById('debug_content');
  oBody.innerHTML += message+'<br/>';
  //this.debugWindow.document.write(message+'<br/>');
}

//disp message
function dm(message){
  if(this.on){
    this.displayDebugMessage(message);
  }
}
//disp error
function de(message){
  this.displayDebugMessage('<span style="color:#f00">error: '+message+'</span>');
}
//disp variable
function dv(varToDesc){
  var message;
  if(typeof(varToDesc) == 'object'){
    for(i in varToDesc){
      message += i + '<br>';
    }
  }else message = varToDesc+'<br>';
  this.displayDebugMessage('var '+typeof(varToDesc)+': '+message);
}
