Checkboxes have an indeterminate state that can be checked with .prop('indeterminate'). This should be used by the select all box when some but not all checkboxes are checked to better conform with Human Interface Guidelines (in most cases).
It gets funky pretty fast though, since you need indeterminate & checked set to show an indeterminate checkbox, but if the checkbox is checked it freaks out the rest of the code.
I'm working on a solution for myself, I'll see what I come up with.