@BWinchell - the problem is not related to global functions or nested objects.
Look at the statements that assign a value of rootFolder variable
var rootFolder = ...;
In all these assignments (except the first one) you are assigning a string value to rootFolder variable, and later you are trying to invoke createFolder() method on this string object. Obviously, string type does not have such method, so the invocation fails with type error.
You need to ensure that assignments to rootFolder assign a valid folder value, like the solution provided by robrtb12 does.
Hope this helps,
-Ilian