Optimal timing control of switched systems with applications to optimal bridge repairs