When the switch is closed, the diode is in on-state so its shining. When you will open the switch, capacitor on the mosfet gate is discharging trough the resistors. When the Voltage on the cap is very low, mosfet is turning off and the transistor which drives the diode is closed so there is no current flowing trough the diode and its of. The discharging time is controled by potentiometer and C capacity