$(document).ready(function(){

	$("#player01").jPlayer({
		ready: function () {
			// $(this).stop();
			$("#player01").volume(100);
		},
		swfPath:"/system/application/assets/swf"

	})
	
	// $("#player_liotm").jPlayerId("play", "play")
	// $("#player_liotm").jPlayerId("pause", "pause")
	// $("#player_liotm").jPlayerId("stop", "stop")
	.onProgressChange( function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
		var myPlayedTime = new Date(playedTime);
		var ptMin = (myPlayedTime.getMinutes() < 10) ? "0" + myPlayedTime.getMinutes() : myPlayedTime.getMinutes();
		var ptSec = (myPlayedTime.getSeconds() < 10) ? "0" + myPlayedTime.getSeconds() : myPlayedTime.getSeconds();
		$("#play_time").text(ptMin+":"+ptSec);

		var myTotalTime = new Date(totalTime);
		var ttMin = (myTotalTime.getMinutes() < 10) ? "0" + myTotalTime.getMinutes() : myTotalTime.getMinutes();
		var ttSec = (myTotalTime.getSeconds() < 10) ? "0" + myTotalTime.getSeconds() : myTotalTime.getSeconds();
		$("#total_time").text(ttMin+":"+ttSec);
	});

	$(".player01").toggle(
		function() {
			//Load track info for displaying in hero for new album
			$("#trackname").text($(this).text());
			$("#trackStatus").css('display','block');
			
			//Remove pause button on items playing from other playlists.
			$("#list02").find('a.pause').removeClass('pause');
			$("#list03").find('a.pause').removeClass('pause');
			//Remove class on items playing in THIS list.
			$(this).parent().parent().find('a.pause').removeClass('pause');
			$(this).addClass('pause');
			
			//Hide track info on items playing from other playlists.
			$("#list02").find('div.hideTrackInfo').removeClass('showTrackInfo');
			$("#list03").find('div.hideTrackInfo').removeClass('showTrackInfo');
			//Hide track info on item in THIS list.
			$(this).parent().parent().find('div.hideTrackInfo').removeClass('showTrackInfo');
			$(this).parent().find("div.hideTrackInfo").addClass('showTrackInfo');
			
			//Pause other items playing from other playlists
			$("#player02").setFile($(this).attr('rel')).pause();
			$("#player03").setFile($(this).attr('rel')).pause();
			//Pause item playing from THIS playlis
			$("#player01").setFile($(this).attr('rel')).play();
			return false;
		},
		function() {
			$(this).removeClass('pause');
			$("#player01").setFile($(this).attr('rel')).pause();
			return false;
		}
	);
	
	
	$("#player02").jPlayer({
		ready: function () {
			// $(this).stop();
			$("#player02").volume(100);
		},
		swfPath:"/system/application/assets/swf"

	})
	
	$(".player02").toggle(
		function() {
			
			//Remove pause button on items playing from other playlists.
			$("#list01").find('a.pause').removeClass('pause');
			$("#list03").find('a.pause').removeClass('pause');
			//Remove class on items playing in THIS list.
			$(this).parent().parent().find('a.pause').removeClass('pause');
			$(this).addClass('pause');
			
			//Hide track info on items playing from other playlists.
			$("#list01").find('div.hideTrackInfo').removeClass('showTrackInfo');
			$("#list03").find('div.hideTrackInfo').removeClass('showTrackInfo');
			//Hide track info on item in THIS list.
			$(this).parent().parent().find('div.hideTrackInfo').removeClass('showTrackInfo');
			$(this).parent().find("div.hideTrackInfo").addClass('showTrackInfo');
			
			//Pause other items playing from other playlists
			$("#player01").setFile($(this).attr('rel')).pause();
			$("#player03").setFile($(this).attr('rel')).pause();
			//Pause item playing from THIS playlis
			$("#player02").setFile($(this).attr('rel')).play();
			return false;
		},
		function() {
			$(this).removeClass('pause');
			$("#player02").setFile($(this).attr('rel')).pause();
			return false;
		}
	);
	
	
	$("#player03").jPlayer({
		ready: function () {
			// $(this).stop();
			$("#player03").volume(100);
		},
		swfPath:"/system/application/assets/swf"

	})
	
	$(".player03").toggle(
		function() {

			//Remove pause button on items playing from other playlists.
			$("#list01").find('a.pause').removeClass('pause');
			$("#list02").find('a.pause').removeClass('pause');
			//Remove class on items playing in THIS list.
			$(this).parent().parent().find('a.pause').removeClass('pause');
			$(this).addClass('pause');
			
			//Hide track info on items playing from other playlists.
			$("#list01").find('div.hideTrackInfo').removeClass('showTrackInfo');
			$("#list02").find('div.hideTrackInfo').removeClass('showTrackInfo');
			//Hide track info on item in THIS list.
			$(this).parent().parent().find('div.hideTrackInfo').removeClass('showTrackInfo');
			$(this).parent().find("div.hideTrackInfo").addClass('showTrackInfo');
			
			//Pause other items playing from other playlists
			$("#player01").setFile($(this).attr('rel')).pause();
			$("#player02").setFile($(this).attr('rel')).pause();
			//Pause item playing from THIS playlis
			$("#player03").setFile($(this).attr('rel')).play();
			return false;
		},
		function() {
			$(this).removeClass('pause');
			$("#player03").setFile($(this).attr('rel')).pause();
			return false;
		}
	);
	
});