I would imagine at first glace that it would go after this:
Code:
{if $allcategories[subcat_num].parentid == $categories[cat_num].categoryid && $allcategories[subcat_num].category != $categories[cat_num].category}
But you may get a quicker answer asking cart-labs since they would be familiar with this code you posted.
Carrie