var BLOCKQUOTE = createDOMFunc('blockquote');
var ABBR       = createDOMFunc('abbr');

function prettyHTML(dom, indent_string, indent_step) {
  if (typeof(indent_step) == 'undefined' || indent_step === null) {
    indent_step = 2;
  }
  
  // if we're just starting out, no indent
  if (typeof(indent_string) == 'undefined' || indent_string === null){
    indent_string = "\n";
  } else {
    for(var i = 0; i < indent_step; i++) {indent_string += ' ';}
  }
  
  var output  = '';
  
  var self = MochiKit.DOM;
  var escapeHTML = self.escapeHTML;
  var attributeArray = self.attributeArray;
  
  if (typeof(dom) == 'string') {
    output += indent_string + dom;
  } else if (dom.nodeType == 1) {
    //type 1 = element
    output += indent_string + '<' + dom.nodeName.toLowerCase();
    var attributes = [];
    var domAttr = attributeArray(dom);
    for (var i = 0; i < domAttr.length; i++) {
      var a = domAttr[i];
      output += " " + a.name + '="' + a.value + '"';
    }
    if (dom.hasChildNodes()){
      output += '>';
      if(dom.childNodes.length == 1 && dom.childNodes[0].nodeType == 3) {
        output += dom.childNodes[0].nodeValue;
        output += '</' + dom.nodeName.toLowerCase() + '>';
      } else {
        var children = dom.childNodes;
        for (i = 0; i < children.length; i++) {
          output += prettyHTML(children[i], indent_string);
        }
        output += indent_string + '</' + dom.nodeName.toLowerCase() + '>';
      }

    } else {
      output += ' />';
    }
  } else if (dom.nodeType == 3) {
    output += dom.nodeValue;
  }
  if(indent_string == "\n" && output[0] == "\n"){
    output = output.substring(1, output.length);
  }
  
  return output;
}