Add hooks before and after a state change.

Useful for plugin authors.
Merge pull request #76 from sagittarian/state-change-hooks

Add hooks before and after a state change.