var currentTrack = 0;
var currentVol = 0.6;

playList = new Array();

$(function(){
	$('#tocador').jPlayer({
		ready: function () {
			playListChange(0);
		},
		swfPath: '/js/libs/jplayer/',
		ended: playListNext,
		volume: currentVol
	});

	$('.pl').click(function() { $('#tocador').jPlayer('play'); return false; });
	$('.ps').click(function() { $('#tocador').jPlayer('pause'); return false; });
	$('.st').click(function() { $('#tocador').jPlayer('stop'); return false; });
	$('.pr').click(function() { playListPrev(); return false; });
	$('.nx').click(function() { playListNext(); return false; });
	$('.mn').click(function() { volumeMenos(); return false; });
	$('.mx').click(function() { volumeMais(); return false; });
});

function playListChange(index) {
	currentTrack = index;
	$('#tocador').jPlayer('setMedia', { mp3: playList[currentTrack].file }).jPlayer('play');				
}

function playListNext() {
	var index = (currentTrack + 1 < playList.length) ? currentTrack + 1 : 0;
	playListChange(index);
}

function playListPrev() {
	var index = (currentTrack - 1 >= 0) ? currentTrack - 1 : playList.length-1;
	playListChange(index);
}

function volumeChange(index) {
	currentVol = index;
	$('#tocador').jPlayer('volume', index);				
}

function volumeMenos() {
	var index = (currentVol - 0.1 >= 0) ? currentVol - 0.1 : 0;
	volumeChange(index);
}

function volumeMais() {
	var index = (currentVol + 0.1 < 1) ? currentVol + 0.1 : 1;
	volumeChange(index);
}

