Power behavior issues with iMac Intel

http://support.apple.com/kb/TA27217

discusses issues with the power cord of the iMac Intel or G5 that may trigger an automatic restart, or automatic shut down or not allowing the machine to startup if they are related to the power cord.  Check that first, before assuming issues internal to the machine.

Note, the iMac G5 also was known to have issues with capacitors, and early iMac Intel may also have those issues.  Check with an authorized service center if they can help you.