code: function get_children(layer) {
  
              // Build array of children
              var children = [];
              for (var index in layer.children)
                  children.push(layer.children[index]);
  
              // Sort
              children.sort(function children_comparator(a, b) {
  
                  // Compare based on Z order
                  var diff = a.z - b.z;
                  if (diff !== 0)
                      return diff;
  
                  // If Z order identical, use document order
                  var a_element = a.getElement();
                  var b_element = b.getElement();
                  var position = b_element.compareDocumentPosition(a_element);
  
                  if (position & Node.DOCUMENT_POSITION_PRECEDING) return -1;
                  if (position & Node.DOCUMENT_POSITION_FOLLOWING) return  1;
  
                  // Otherwise, assume same
                  return 0;
  
              });
  
              // Done
              return children;
  
          }
docs: Returns sorted array of children