This seems to be a fairly common issue that does not have one "magic" fix. One work-around is when your system loses the wi-fi connection is to simply click the wi-fi symbol in your menu, choose turn off wi-fi and then turn it back on. However what seems to work is a router upgrade. What seems to work are routers that have dual frequency (2.4GHz & 5GHz) and the ability to handle wireless protocols IEEE 802.11a/b/g/n. Apple's Airport Extreme and Airport Express are one example however many router manufacturers have similar specifications.
How do you get your internet service? DSL? Cable? DialUp?
How is your iMac connected to the internet?
The following articles may also provide some help. If you are using PPPoE then the following information from the article referenced below may help. It's referring to an option in the advanced section of the Network System Preferences pane. I've included a screenshot from my system below.
"Tip: To have the computer automatically connect whenever you open a network application (Web browser, email, and so forth), click PPPoE Options and select the "Connect automatically when needed" checkbox."