var playItem = 0;
var tempoAntigo = 0;

$(document).ready(function(){
    
    $('#jquery_jplayer').jPlayer({
        
        ready: function(){
            playListInit(false);
        },
        swfPath: baseUrl + ASSETS + "/swf",
        preload:'none'
        
    }).jPlayer("onProgressChange", function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
//        jpPlayTime.text($.jPlayer.convertTime(playedTime));
//        jpTotalTime.text($.jPlayer.convertTime(totalTime));
    }).jPlayer("onSoundComplete", function() {
        playListNext();
//        return false;
    });
    
    $("#jplayer_previous").click( function() {
        playListPrev();
        return false;
    });

    $("#jplayer_next").click( function() {
        playListNext();
        return false;
    });
    
    function playListInit(autoplay) {
        if(autoplay) {
            playListChange( playItem );
        } else {
            playListConfig( playItem );
        }
    }

    function playListConfig( index ) {
        $("#jplayer_playlist_item_"+playItem).removeClass("jplayer_playlist_current");
        $("#jplayer_playlist_item_"+index).addClass("jplayer_playlist_current");
        playItem = index;
        $("#trackname").html(myPlayList[playItem].name);
        $("#jquery_jplayer").jPlayer("setFile", myPlayList[playItem].mp3, myPlayList[playItem].ogg);
    }

    function playListChange( index ) {
        playListConfig( index );
        $("#jquery_jplayer").jPlayer("play");
    }

    function playListNext() {
        var index = (playItem+1 < myPlayList.length) ? playItem+1 : 0;
        playListChange( index );
    }

    function playListPrev() {
        var index = (playItem-1 >= 0) ? playItem-1 : myPlayList.length-1;
        playListChange( index );
    }
    
});


