Adaptive variability in the duration of critical windows of plasticity