$(document).ready(function(){


	var autoPlay = (document.location.pathname == '/') ? true : false;
	
	var myPlayList = [
		{mp3: '/static/music/howard-CD1-trk01.mp3'},
		{mp3: '/static/music/howard-CD1-trk02.mp3'},
		{mp3: '/static/music/howard-CD1-trk03.mp3'},
		{mp3: '/static/music/howard-CD1-trk04.mp3'},
		{mp3: '/static/music/howard-CD1-trk05.mp3'},
	];

	var playItem = Math.floor(Math.random() * myPlayList.length);

	function playListInit(autoplay) {
		if(autoplay) {
			playListChange(playItem);
		} else {
			playListConfig(playItem);
		}
	}

	function playListConfig(index) {
		playItem = index;
		$('#player').jPlayer('setFile', myPlayList[playItem].mp3);
	}

	function playListChange(index) {
		playListConfig(index);
		$('#player').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);
	}


	$('#player').jPlayer({
		nativeSupport: true, 
		oggSupport: false,
		customCssIds: false,
		volume: 90,
		swfPath: "/static/js",
		ready: function(){
			playListInit(autoPlay);
		}
	});
	$('#player').jPlayer('onSoundComplete', function(){
		playListNext();
	});
	
});
