mbm.playItem = 0;
$jq(document).ready(function(){
	var playItem = mbm.playItem;
	$jq("#jquery_jplayer").jPlayer({
		ready: function() {
			playListInit(true); // Parameter is a boolean for autoplay.
		},
//		cssPrefix: "jqjp",
		volume: 80,
		oggSupport: false

	})
	.jPlayerId("play", "player_play")
	.jPlayerId("pause", "player_pause")
	.jPlayerId("stop", "player_stop")
	.onSoundComplete( function() {
		playListChange( playItem );
//		playListNext();
	});

	$jq("#ctrl_prev").click( function() {
		playListPrev();
		return false;
	});

	$jq("#ctrl_next").click( function() {
		playListNext();
		return false;
	});

	function displayPlayList() {
		for (i=0; i < myPlayList.length; i++) {
			$jq("#playlist_list ul").append("<li id='playlist_item_"+i+"'>"+ myPlayList[i].name +"</li>");
			$jq("#playlist_item_"+i).data( "index", i ).hover(
				function() {
					if (playItem != $jq(this).data("index")) {
						$jq(this).addClass("playlist_hover");
					}
				},
				function() {
					$jq(this).removeClass("playlist_hover");
				}
			).click( function() {
				var index = $jq(this).data("index");
				if (playItem != index) {
					playListChange( index );
				} else {
					$jq("#jquery_jplayer").play();
				}
			});
		}
	}

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

	function playListConfig( index ) {
		playItem = index;
//		$jq("#song_title").text(myPlayList[playItem].name);
		$jq("#jquery_jplayer").setFile(myPlayList[playItem].mp3);
	}

	function playListChange( index ) {
		playListConfig( index );
		$jq("#jquery_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 );
	}
});

