How do I add an if else statement to this?

How do I add an if else statement to this?

How do i add an if else statement to this:

  1. $(function(next) {
            // Setup the player to autoplay the next track

            var a = audiojs.createAll({
              trackEnded: function() {
                var next = $('ol li.playing').next();
                if (!next.length) next = $('ol li');

       next.addClass('playing').attr('id', 'playing').siblings().removeClass('playing').removeAttr('id');

     var container = $('#rightbox'),
        scrollTo = $('#playing');
        container.animate({scrollTop: scrollTo.offset().top - container.offset().top +
                           container.scrollTop()});

        audio.load($('a', next).attr('data-src'));

    $('#nowplaying').empty();
    $('#nowplaying').html('<p>' + $('#myaudio').attr('src').split('\/').pop().trim() + '</p>');

                audio.play();
    $("#playled").addClass("litred");
    $("#stereostat").text("Stereo").addClass("stereo");
              }
            });

I have a button that if clicked once will repeat the current song. If I click it again it adds the class lastsong to the li. and if I click it again it goes back to playing the songs until the end of the playlist. this is working fine


Basically I'm trying to make a loop all function, so if the last li has the class lastsong I want it to load the first song again and play through the list until I click the button again to remove the lastsong class.

I've gotten close a few times, but don't know enough to get this to work. Thank you for any help.