I finally solved my problem connecting to my wireless router. I couldn't believe that I was having more luck connecting to my neighbour's unsecured WiFi connection than to my wireless modem/router (a Billion 7300G) in the same room.
My wireless setup was:
Now all along I was thinking it was one of these reasons:
1. the Airport card was faulty
2. it was an OS X config problem - WPA2 encryption-related
3. it was a Leopard problem
Now I was really hoping it wasn't #1, because it would have been a royal pain in the ass to try and send back a 9kg computer in the mail. It didn't seem likely because I was able to connect to my neighbour's wifi network without problem. Which leads us to #2 - well, no way was I going to leave my connection unsecured, but just to test out this theory, I turned off the wifi security for a while. And for a couple of times it worked - I could connect to the network and use a browser, etc. Until it stopped doing it.
The last one was #3, and I was all ready to update to 10.5.1 - but I remembered that when I first set up my wireless connection I was using Channel 1. I moved to Channel 6 because I was getting some trouble connecting from the Powerbook downstairs. So I hooked up the iMac to the router, changed to Channel 1, unplugged from the router - voila! all working!
I later found a forum posting (http://discussions.apple.com/thread.jspa?messageID=1822533#1822533) which claimed that Apple engineers had mentioned a conflict between Bluetooth and Channel 6 on wifi. Looks like that was the problem I was having. Bluetooth is on by default, so I turned it off. But I haven't changed the router back to Channel 6. I figure it's better to leave things alone once they work!
Solution to Problem:
4. change wireless channel from channel 6 to channel 1. In some cases Channel 6 conflicts with Bluetooth. So either turn off Bluetooth or stop using Channel 6.