Moved several anonymous functions out of $(document).ready for cleanliness, converted to 2 spaces per indent