Added check to only run Ajax when window in focus