Reduced number of calculations on resize event

Added a window variable to avoid calculations of the best candidate if a calculation is already running. This avoids an overhead of calculations and increases the performance of the event listener.