atthebeach, what you're describing is typical for a tracking cookie. Most advertisers use them.
Cookies are a tiny file sent to your computer by the webserver. When you visit a given site, its server queries your browser to see if you already have its cookie (or several as the case may be), and if it does, your browser responds by sending the cookie back to the server. It's kinda like a special-handshake ID. Aha, here's a cookie we recognise, atthebeach wants to log in. Welcome! (This is also why when you delete all your cookies, you have to log back in everywhere you go.)
Cookies are used for all sorts of things, such as automatic login here on AW. Cookies can contain just about anything and be short-lived or essentially permanent. (My old system still has my original New York Times login cookie -- from 1996! and it still works.)
Most cookies don't contain anything that identifies you personally. You're just a number in the cookie database.
Most ad servers partner with many different sites. Basically what a tracking cookie does is let the ad server look you up in its database:
User # 12345678 is here! what ads have we sent them lately? Oh yeah, on Site One we sent them X Y and Z. Here on Site Two, let's send them related ads A B and C. Wouldn't want them to get bored...
Webservers can query your browser's "history" for a list of everywhere you've visited in however-long your history is set for. If they find you've recently visited candy.com, and one of their advertisers sells chocolate, guess what you'll gets ads for -- even tho now you're on a site about shoes.
While this is often decried as a "violation of privacy", the fact is ad tracking cookies don't really do anything but follow you around the web, hoping they're sending you ads that you're more likely to actually look at. Yes, the aggregate information is often sold to advertisers, but they really don't care about you personally.
If you don't want tracking cookies or other forms of tracking (such as browser history parsing), you can disable browsing history (but I don't, because it's actually useful sometimes) and in your browser's preferences, set cookies to whatever looks most like "Allow cookies only from from the originating server" (or perhaps "Don't allow 3rd party cookies). Voila, once these ad cookies expire (or you delete them), advertising will stop following you around. Which on today's web, is mostly cosmetic.
The real benefit of blocking 3rd party cookies is that they can have less savory uses (like password stealing, and profiling individuals, and could potentially be used by an oppressive government to track who associates with whom).
(Incidentally Facebook not only queries your browser history, it also matches your history to other Facebook users' histories ... that's one way it "knows" who "you might know" -- it can see which sites you and others have visited in common. This, IMO,
does fall under "violation of privacy", because this
can be used to personally identify individuals by way of their associations. If you're involved in a secret conspiracy,
don't use Facebook.
ETA: And t'other day I received proof positive that YouTube does the same.)
And remember, advertising is mostly about name recognition. They don't really expect you to buy something every time you see an ad.
https://en.wikipedia.org/wiki/HTTP_cookie
http://www.unc.edu/courses/2006spring/law/357c/001/projects/jhubbard/cookiesrisks.html
And, what mirandashell said!!