Fading HELP

long time; // pocita cas millis od spusteni programu
long LED1ON = 0; // will store last time LED1 was used
int interval = 1; // interval rozdilu mezi ON/OFF

void loop() {
if (average >= 600)
{ ledval = 255;
analogWrite (ledPin1, ledval);
LED1ON = millis ();}

So far you defined your time tracking variables (though I didn't see the time variable used in your code). Then you check if your reading is over 600.
If it is, you set your ledval = 255 (max analog output), then set the analog pin "ledPin1" to ledval, in other words turn on the led at full brightness.
Then you're recording the time, in milliseconds, that the led was turned on by setting LED1ON = millis().

else
{analogWrite (ledPin1, 250); }
if (millis () - LED1ON == interval);
ledval -= 25;
{analogWrite (ledPin1, ledval);}
if (ledval=0);
{return;}
}

Then you have what happens if the average is not >=600.
First you have it set the ledPin1 output to 250, which is almost full on and not enough really difference to see it being dimmer than full on. So no matter what, you're turning that LED on and full brightness.
Next you're checking if the current time - LED1ON = interval. Interval is set to 1, so you're checking if the current time is 1 millisecond greater than when LED1ON was set. The problem there is the timing. It would be very hard to have the interval actually = 1 millisecond. This should be checking to see if millis() - LED1ON >= interval.
Next you're trying to gradually lower ledval by 25 and write that to ledPin1.
Finally, if ledval is 0, leave the routine.

Thanks a lot for any idea and suggestion!
P.S.: Sorry of my english - I am not native speaker....

Personally I think your english is excellent for not speaking it natively. Sometimes the hardest thing to do is try :wink:
Now on to some code suggestions:

If I understand you correctly, you want the LED to turn on only when the value first gets to that range, then fade out, even if it's still in that range, and the problem is that your LED is staying on as long as the range is true. If that's the case, here's how I would solve that problem aswell as making the LED fade reliably:

long LED1ON = 0; // will store last time LED1 was used
int interval = 1; // interval rozdilu mezi ON/OFF
int LED1Trigger = 0; //stores if LED1 is already on
int led1val = 0; //analog output for led1
int ledDecay = 25; //how fast the leds fade to off
...
void loop() {
if (average >= 600 & LED1Trigger == 0) //if the average is high enough and LED1 is not already on
{ led1val = 250; //set the brightness of LED1
LED1Trigger = 1; //store the fact that LED1 is now on and average has not gone out of range
LED1ON = millis ();} //store what time LED1 was turned on
if (average < 600 & LED1Trigger == 1) //if the average has gone below this range and LED1 was already on
{LED1Trigger = 0;} //store the fact that average has gone out of this range
if (millis () - LED1ON >= interval & led1val > 0); //if it has been more than "interval" milliseconds since LED1 was turned on and LED1 has not dropped to 0 brightness
{led1val -= ledDecay;} //start fading out LED1's brightness
analogWrite (ledPin1, led1val); //set LED1 to it's brightness
}

A couple of notes:
ledDecay can be used the same for all ranges and LEDS. Making it higher will of course make them fade faster.
The way this is setup, if you were to remake the code for all of your ranges this way (seperate variables for each range such as LED2Trigger, led2val, LED3Trigger, etc.) then you could have one led turn on while another one is still fading out, but none of them "should" stay on with this code unless you are rapidly moving in and out of the same range.

There are other modifications I could do to this code, such as making the LEDs fade out on a logarithmic scale instead of a linear one, but for now this should get you going unless I've missed something or messed up any of the syntax. Please look over my code when you test it to make sure I didn't misspell any variables (ledDecay does not need to be made led1Decay, led2Decay, etc) and I haven't missed any symbols like {} or anything.

As far as maping your data from 170-700 to 0-255, you could use the map () function like this:
average = map(average, 170, 700, 0, 255);

This function works with integers. See http://www.arduino.cc/en/Reference/Map

Hope this is what you are looking for. I'd love to see some video of your LEDs in action if possible :wink:

Have fun with your project,
-Jon

PS: Is this just something to experiment with or do you have a larger project/goal you're planning?
This actually gives me ideas to use this technique with audio as the source like you're using IR. I like the idea of only turning on the first time the value is in range.