refactor javascript: window resizing