First, it sounds like you ARE connected to the internet (certainly, you're connected to the internal network at least); the reason you're getting errors trying to access anything is one of two possibilities:
1) DNS issues; your router isn't passing (or your Mac isn't accepting) a valid DNS server address, and so you can't actually get to anything. This seems most likely.
2) Your router isn't passing internal network traffic to the internet. Not sure what would cause this unless you've done some weird configuration stuff.
Direct connection to the modem would solve either problem, so that's why it worked that way.
Easy enough to check which, though:
First, try going to 17.112.152.32 in a web browser--that should be apple.com's IP address, and I believe it will resolve properly. If you get nothing from that, traffic isn't getting through your router, so time to start looking at its detailed settings (maybe do a factory reset or something). If it comes up fine, it's a DNS problem.
Second, try going to the Network Pref Pane on your Mac and manually enter the DNS servers at
http://www.opendns.com/ (208.67.222.222, 208.67.220.220) in the DNS Servers section and click Apply Now.
If apple.com suddenly starts working, then it's a DNS issue.
If it is a DNS issue, check your router's settings and make sure it doesn't have something weird hardwired. If not, maybe just use those OpenDNS ones, or manually enter your ISP's DNS servers on your Mac; there shouldn't really be any disadvantage from either.