This demo shows how the script works with Layers.
Layer 1
Link 1
Link 2
Link 3
Link 4
Link 5
Link 6

3 ON

Layer 2
Link 1
Link 2
Link 3
Link 4
Link 5
Link 6

3 OFF