function doCodeFolds() {
  var spanElements = document.getElementsByTagName("span");

  for(var i = 0; i < spanElements.length; i++) {
    var spanElement = spanElements[i];
    if(spanElement.className == "collapsed" || spanElement.classname == "uncollapsed") {
      var collapseDivNode = document.createElement("div");
      var collapseDivInnerNode = document.createElement("div");
      var parentNode = spanElement.parentNode;

      collapseDivNode.className="collapseboxclosed";
      collapseDivNode.onclick = createToggleFunction(spanElement, collapseDivNode);

      collapseDivInnerNode.className="collapsewidget";

      collapseDivNode.appendChild(collapseDivInnerNode);
      parentNode.insertBefore(collapseDivNode, spanElement);
    }
  }
}

function createToggleFunction(spanElement, collapseDivNode) {
  return function() {
    if (spanElement.className == "collapsed") {
      spanElement.className = "uncollapsed";
      collapseDivNode.className = "collapseboxopen";
    }
    else if (spanElement.className == "uncollapsed") {
      spanElement.className = "collapsed";
      collapseDivNode.className = "collapseboxclosed";
    }
  }
}
