        }

              if (index[key] == null || index[key] >= templates[key].length) {
                index[key] = 0;
              }
              var t = templates[key][index[key]];
              index[key]++;

              out: while (true) {
                for (k in templates) {
                  if (t.search('{'+k+'}') != -1) {
                    t = t.replace('{'+k+'}', expand(k, depth+1));
                    continue out;
                  }
                }
                break;
          