I'm pretty sure you should start by reading the copious comments in the settings.php file for multiple databases, db table prefixing & even target db fallback. The db stanzas start on line 53, so it's not like it's even buried. ;-)
(It's worth noting however that Drupal's db prefixing isn't designed to scale as you add more prefixes!)
Having said that, I would suggest carefully considering your reasons for wanting to use multiple databases. As Patrick points out, that's not necessary in Drupal for multiple themes, and you are adding a layer of complexity that you should make sure you really need-- for most cases this seems like it would be an anti-pattern.