Not an easy request unfortunately. I am thinking about how this might be accomplished...
It is easy to write an if statement for the category page itself in smarty:
PHP Code:
{if $cat eq 1}
Do this
{elseif $cat eq 2}
Do that
{/if}
Getting it to stick on all the sub cats and products is going to be the tough part. You will have to write some php code that looks at the entire category structure, then determines which main category this particular product or category is in. Certainly not impossible, but a little daunting.