Is this an iMac G5 with an isight (camera on the front top center)? Is this an iMac G5 with an ambient light sensor? Look on the bottom and there will be a little thing that looks like a LED next to the center screw if it is an ambient light?
With all that said. If you don't have an iMac G5 w/ iSight sounds like a classic REA issue to me. Couple ways you can check this.
One:
Lay the mac face down on a towel or something soft
Unscrew the 3 screws on the bottom of the iMac (note: they won't come all the way out just loosen em)
Lift up on the foot of the imac way from you and the back should pop off.
Now...
Smell the power supply and see if it smells really awful if it does you got a bad PS.
Also look at the capictors on the MLB they look like little metal capsules. Check to make sure they are all flat! None of them should be bulging or oozing any orange stuff. If they are you got a bad MLB. If either of these issues are present there is a REA for this issue and Apple will fix it for free so take it to the apple store.
Two:
Boot up your mac.
Open up utillities.
Open up console.
Click on system.log
Search shut down, search temp, search thermal...see if you get anything there?
Let me know what you find?