moveBackground depends on limitX and limitY being initalized, so you should register this event handler in the onload function instead of here.