One small point,
changing this line
function gal_nav($array, $level, $parent, $nav_array=array())
to this
function gal_nav($array, $level, $parent, &$nav_array=array())
Could stop a potential memory maxout. Passing the array by reference rather than by value means that a copy is not made, this is often what is required in recursive functions when the result of the function is called into one the same variable as one of the prameters, as happens here.
$nav_array = gal_nav($array,$new_level,$parent_new,$nav_array);
incidentally you could also change this line to just
gal_nav($array,$new_level,$parent_new,$nav_array);
HTH
Bubble