I've been learning JS for a few days. stackoverflow was a great help. However I came up with a problem I cannot even determine or describe (since I'm new to this).

I've built an < audio >-based mp3 player.
You need to see /try it by yourself. (sorry)

[Please check JS code here - ctrl-f 'STACKoverflow' in it - AntonFrolov.net/music.php](http://AntonFrolov.net/music.php)

Here is the actions you need to perform to see where the problem is (I've put these to website too).

1. Click on track #2 - You will notice an alert('Track #' +ID); = [Track #2]
2. There is a player in the bottom-right corner - Set track progress to 98% so it ends.
3. (ID++), You are sent to the track#3 . alert('Track #' +ID); = [Track #3]. good.
4. Repeat step 2.
5. (ID++), You should be sent to the track#4. ... PROBLEM Events:

	* 5a. alert('Track #' +ID); = [Track #3].
	* 5b. Track#3 starts playing. AGAIN. then you instantly receive next .. alert
	* 5c. alert('Track #' +ID); = [Track #4].
	* 5d. Track#4 starts playing. that's what I expected but without events 5a-5b.

This will continue if you keep doing the steps.

However the JS code is here:

```
    function FuncPlay(ID,Rnd){
    alert('Track #'+ID);
    if (Rnd==0){
    $('.liActive').removeClass('liActive');
    $('#'+ID).next().addClass('liActive');

    // Set track Data
    $('audio').attr('id','audioNor');
    $('audio').attr('src',$('.liActive').attr('rel'));

    // Play
    var player = $('.tbd').get(0);
    player.play();
    $('#pause').removeClass('hi');
    ID++;
        $(player).bind('ended', function () { 
                if (ID <= <?php echo $am ?>){FuncPlay(ID, 0);}
                else {alert('"...End of the list."' );}
        });
    }
}

```

I have completely no idea how to deal with this. Thank you for your patience.