move calculate center of state function to where onclick events can find it