Most probably, this is caused either by some kind of corruption of the HD data, cache corruption, or some software you've installed which has issues.
Since this has been happening a few times, it would be worth booting from your software install disks and running Disk Utility (it's in the menu when the installer loads). There is both a "Repair Disk" and "Repair Permissions" option.
You can also start the machine holding down apple-v which puts it in verbose mode. When you shut down as well, you'll be able to visibly see what's going on and, hopefully, what's hanging the machine, possibly useful if you've installed some software causing issues.
Something worth installing which does this without the need for booting from your software disks is
Applejack. It installs a utility that can be run when you boot the machine into what's known as Single User Mode (holding down apple-s at the very start of switching on the machine). It does a few more things, such as deleting caches (which can become corrupt) and checking preferences.
I'm quite certain all of the above will nail down the issue (unless it's software you've installed, which might be a bit trickier to track down).