Fix jshint errors

- Refactor idle logic to changeIdle function
- Hoist to single 'i' declaration that was used in consecutive for loops
- Remove hanging comma
- Fixed up some malformed JSHint directives