No need to mod Wayfinder, all you need to do is to create another small snippet to wrap the logic and control which Wayfinder call is executed.
Something like this, for example:
<?php
if (count($modx->getChildIds($modx->documentObject['id'],1)) == 0 || $modx->runSnippet('Wayfinder', array('startId'=>$modx->documentObject['id'])) == '') {
// no children or output from wayfinder will be an empty string, so use the parent ID as the start ID
return $modx->runSnippet('Wayfinder', array('startId'=>$modx->documentObject['parent'], 'level'=>'1'));
} else {
// has children and output will not be an empty string, so use this page's ID as the start ID
return $modx->runSnippet('Wayfinder', array('startId'=>$modx->documentObject['id'], 'level' => '1'));
}
?>
You just need to customise the runSnippet() calls to use your own snippet parameters (in the second argument of the runSnippet call, see how the snippet parameters are passed in as an array - that’s what you will need to add to if you use custom parameters).
Then, call this snippet on the page where you want the horizontal menu to be displayed.
Hope that helps,
Garry