You should consider removing all the other functions from the global scope, especially because they have relatively generic names like "generateTree", "toArray", "depth", and "toggleClass".
Consider using an actual class or a closure perhaps?
Consider using an actual class or a closure perhaps?