﻿// JavaScript Document
$(document).ready(function(){
	var currentTrack = 0;
 
	var playList = [
		{ title: "Eveil Troublé", artist: "aKtu", file: "http://www.aktu-legroupe.fr/mp3/Eveil_Trouble.mp3" },
		{ title: "Reclus", artist: "aKtu", file: "http://www.aktu-legroupe.fr/mp3/Reclus.mp3" }
	];
 
	$("#jPlayer").jPlayer({
		ready: function() {					
			playListChange(0); // Play first song
		},
		oggSupport: false
	})
	.jPlayer('onSoundComplete', playListNext);						
 
	$("#jplayer_prev").click(function() { playListPrev(); }); // Listen for Previous Track button click
	$("#jplayer_next").click(function() { playListNext(); }); // Listen for Next Track button click
	$(".playSong").click( function() {
		index = parseInt($(this).attr('rel'));
		playListChange(index);
	}); // Change to track defined by rel of link with playSong class
 
	// Switch track
	function playListChange(index) {
		currentTrack = index;
		$("#playerSongInfo").html(playList[currentTrack].artist + ' - <em>' + playList[currentTrack].title + '</em>');
		$("#jPlayer").jPlayer('setFile', playList[currentTrack].file).jPlayer('play');				
	}
 
	// Play next track. If already on last track, start back at the begining
	function playListNext() {
		var index = (currentTrack + 1 < playList.length) ? currentTrack + 1 : 0;
		playListChange(index);
	}
 
	// Play previous track. If already on first track, start back at the end
	function playListPrev() {
		var index = (currentTrack - 1 >= 0) ? currentTrack - 1 : playList.length-1;
		playListChange(index);
	}
 
});
