Simple self-adjusting javascript timer