Star-San is a no rinse sanitizer, and in many cases you will see texts that say "Don't fear the foam!".
You should sanitize everything that comes in contact with the cooled wort, typically just prior to using it. For example, put some star-San into your fermenter, slosh it around so that it touches all of the surfaces, pour out the excess for use again...leave the foam and move your beer into the fermenter. The foam will have no effect on your beer.
Star-San sanitizes surfaces in something like 15-30 seconds of contact (and yes the foam works as well as the liquid), so there is no need to sanitize in advance of your brewing session.
I use to sanitize my bottles after cleaning, which could be weeks before they were used. This was a pain, since I also had to either cap them, or cover the openings with sanitized foil. Now I just use star-san right before I'm going to bottle...a quick dip, slosh, and empty...and I'm good to go.
-Dan