To detect mouse inactivity easily, here is the LazyMouse jQuery plugin, which attaches two new events to the body element: one is mouse.active and another one is mouse.inactive. You can just add two listeners for those events and do whatever you want to do.
Events
Plugins