function vafDoLevel($level, $parent_id = 0)
{
    $schema = new Elite_Vaf_Model_Schema();
    $finder = new Elite_Vaf_Model_Level($level);
    $parentLevel = $schema->getPrevLevel($level);
    if ($parentLevel) {
        $entities = $finder->listInUse(array($parentLevel => $parent_id));
    } else {
        $entities = $finder->listInUse();
    }
    echo $level . '["' . $parent_id . '"] = new Array();';
    foreach ($entities as $entity) {
        ?>
        var obj = new Array();
        obj["title"] = "<?php 
        echo $entity->getTitle();
        ?>
";
        obj["id"] = "<?php 
        echo $entity->getId();
        ?>
";
        <?php 
        echo $level;
        ?>
["<?php 
        echo $parent_id;
        ?>
"].push( obj );
        <?php 
        if ($level != $schema->getLeafLevel()) {
            vafDoLevel($schema->getNextLevel($level), $entity->getId());
        }
        echo "\n";
    }
}