No worries, I did post the version number above, but I probably could have been clearer.
This was developed using version
4.0.8. I'm assuming it will work on 4.x but haven't had time to test on other installations.
May also be worth trying on 3.5.x - as long as
$allcategories is supported and the subcategory_count can be checked, all should be fine.
I'm not sure if smarty supports recursion, (will check later) but this could actually be done using a fraction of the code (and also be of unlimited depth).
Oh yeah, if anyone has any joy on other versions let us know!