<!--
$(document).ready(function(){
						   
	var playItem = 0;	
	
	// Local copy of jQuery selectors, for performance.
	var jpPlayTime = $("#jplayer_play_time");
	var jpTotalTime = $("#jplayer_total_time");

	$("#jquery_jplayer").jPlayer({
		ready: function() {
			$("#track_title").html( myPlayList[playItem].artist + '<br /><span class="track_col">' + myPlayList[playItem].name + '</span>' );
			$("#wavefile").attr("src", myPlayList[playItem].img );
			$("#cover").attr("src", myPlayList[playItem].cover );
			displayPlayList();
			playListInit(false); // Parameter is a boolean for autoplay.
		},
		swfPath: site + 'js',
		nativesupport: true,
		oggSupport: false
	})
	.jPlayer("onProgressChange", function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
		jpPlayTime.text($.jPlayer.convertTime(playedTime));
		jpTotalTime.text($.jPlayer.convertTime(totalTime));
	})
	.jPlayer("onSoundComplete", function() {
		playListNext();
	});

	$("#jplayer_previous").click( function() {
		playListPrev();
		$(this).blur();
		return false;
	});

	$("#jplayer_next").click( function() {
		playListNext();
		$(this).blur();
		return false;
	});

	function displayPlayList() {
		$("#jplayer_playlist ul").empty();
		for (i=0; i < myPlayList.length; i++) {
			var listItem = (i == myPlayList.length-1) ? "<li id='track_" + i + "' class='jplayer_playlist_item_last'>" : "<li id='track_" + i + "'>"; 
			listItem += "<a href='#' id='jplayer_playlist_item_"+i+"' tabindex='1' onmouseover='track_scroll(" + i + ");' onmouseout='track_reset(" + i + ");'>"+ myPlayList[i].artist + " - " + myPlayList[i].name +"</a></li>";
			$("#jplayer_playlist ul").append(listItem);
			$("#jplayer_playlist_item_"+i).data( "index", i ).click( function() {
				var index = $(this).data("index");
				if (playItem != index) {
					$("#track_title").html( myPlayList[index].artist + '<br /><span class="track_col">' + myPlayList[index].name + '</span>');
					$("#wavefile").attr("src", myPlayList[index].img );
					$("#cover").attr("src", myPlayList[index].cover );
					playListChange( index );					
				} else {
					//$("#jquery_jplayer").jPlayer("play");
					$("#jquery_jplayer").jPlayer( "playHead",0.01 );
				}
				$(this).blur();
				return false;
			});
		}
	}

	function playListInit(autoplay) {
		if(autoplay) {
			playListChange( playItem );
		} else {
			playListConfig( playItem );
		}
	}

	function playListConfig( index ) {
		$("#jplayer_playlist_item_"+playItem).removeClass("jplayer_playlist_current").parent().removeClass("jplayer_playlist_current");
		$("#jplayer_playlist_item_"+index).addClass("jplayer_playlist_current").parent().addClass("jplayer_playlist_current");
		playItem = index;
		$("#jquery_jplayer").jPlayer("setFile", myPlayList[playItem].mp3, myPlayList[playItem].ogg);
	}

	function playListChange( index ) {
		$("#track_title").html( myPlayList[index].artist + '<br /><span class="track_col">' + myPlayList[index].name + '</span>');
		$("#wavefile").attr("src", myPlayList[index].img );
		$("#cover").attr("src", myPlayList[index].cover );
		playListConfig( index );
		displayPlayList();
		//$("#jquery_jplayer").jPlayer("play");
		$("#jquery_jplayer").jPlayer( "playHead",0.01 );
	}

	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 );
	}	
	
	addNewTrack = function(name,mp3,wavimg,cover,artist,track_id,release_id) {
		 
		bodyContent = $.ajax({
		   url : site + "ajax/ajax_player_waveform.php",
		   async: false,
		   type: "POST",
		   data : ({track_id: track_id, release_id: release_id})
		});
		 
	 	var nowplay = -1;
		 
		var myPlayList2 = [{name:"", mp3:"", img:"", cover:"", artist:""}];
		myPlayList2[0].name = name;
		myPlayList2[0].mp3 = mp3;
		myPlayList2[0].img = wavimg;
		myPlayList2[0].cover = cover;
		myPlayList2[0].artist = artist;		
		
		for (i=0; i < myPlayList.length; i++) {
			if ( myPlayList[i].mp3 == myPlayList2[0].mp3) {
				nowplay = i;
				break;
			}			
		}
		
		if (nowplay < 0) {			
			nowplay = 0;
			myPlayList = $.merge(myPlayList2, myPlayList);
			$('#track_container').scrollTo( {top:'0', left:'0'}, 800 );
		} else {
			scroll_pixels = nowplay * 20;
			$('#track_container').scrollTo( {top:scroll_pixels + 'px', left:'0'}, 800 );
		}
		
		playListChange(nowplay);

	 }
	
	 prevButton = function() {
		$('#track_container').scrollTo( {top:'-=80px', left:'0'}, 800 );
	 }

	 nextButton = function() {
		$('#track_container').scrollTo( {top:'+=80px', left:'0'}, 800 );
	 }
	
	 track_scroll = function(index) {
		$('#track_' + index).scrollTo( {top:'0', left:'+=300'}, 2000 );		
	}
	
	 track_reset = function(index) {
		$('#track_' + index).scrollTo( {top:'0', left:'0'}, 100 );		
	}
	
});		
-->
