I suspect part of the problem is that you turn the LED off if the value is high wheras you should turn it off only when it changes from low to high.
That means you need a variable to record the previous reading - something like
prevAnalogValue = analogValue; // save old value
analogValue = analogRead(analogPin);
if (analogValue > threshold && prevAnalogValue < theshold) {
// turn light off etc
}
You may also find problems using delay() as it blocks the Arduino from doing other things. Have a look at how millis() is used to manage timing without blocking in several things at a time
...R