porting php nestedset to js