How do I automatically reconnect to wifi when the connection is lost?
While this doesn't solve your problem immediately, I can say that I had the exact same issue with my iMac and OS X 10.6. My solution? Get a new router. From that point on, the wireless connection was far more stable, and while the issue itself exists (say I make a lot of changes in the router that requires the connection to drop -- my iMac won't always reconnect), the router itself seems to make a big deal in the connectivity. (I went after one of the newer N routers; my previous router was a G router.)

Other things to try (before shelling out $$$):


Make sure your router's firmware is up-to-date (Mine was, unfortunately)
See if you can install a custom firmware (like DD-WRT) that might solve the problem (this is really dependent upon router type, so not all routers are supported)