/* Author: */

$(document).ready(function() {
 
  
  // jPlayer for In My View
 
 	var	inmyview_jPlayer = $("#jquery_jplayer_1"),
		inmyview_trackName = $("#jp_container_1 .track-name"),
		inmyview_playState = $("#jp_container_1 .play-state"),
		inmyview_extraPlayInfo = $("#jp_container_1 .extra-play-info");

	// Some options
	var	inmyview_play_first = false, // If true, will attempt to auto-play the default track on page loads. No effect on mobile devices, like iOS.
		inmyview_auto_play = true, // If true, when a track is selected, it will auto-play.
		inmyview_text_playing = "Now playing", // Text when playing
		inmyview_text_selected = "Click to listen"; // Text when not playing

	// A flag to capture the first track
	var inmyview_first_track = true;

	// Initialize the play state text
	inmyview_playState.text(inmyview_text_selected);

	$("#inmyview-nowplaying").hide();

	function showInMyViewNowPlaying()
	{
		$("#inmyview-message").fadeOut(function(){
			$("#inmyview-nowplaying").fadeIn();
		});
	}

	// Instance jPlayer
	inmyview_jPlayer.jPlayer({
		ready: function () {
			$("#jp_container_1 .track-default").click();
		},
		timeupdate: function(event) {
			inmyview_extraPlayInfo.text(parseInt(event.jPlayer.status.currentPercentAbsolute, 10) + "%");
		},
		play: function(event) {
			$(this).jPlayer("pauseOthers"); // pause all players except this one.
			inmyview_playState.text(inmyview_text_playing);
		},
		pause: function(event) {
			inmyview_playState.text(inmyview_text_selected);
		},
		ended: function(event) {
			inmyview_playState.text(inmyview_text_selected);
		},
		swfPath: "js",
		cssSelectorAncestor: "#jp_container_1",
		supplied: "mp3",
		wmode: "window"
	});

	// Create click handlers for the different tracks
	$("#jp_container_1 .track").click(function(e) {
		inmyview_trackName.text($(this).text());
		
		inmyview_jPlayer.jPlayer("setMedia", {
			mp3: $(this).attr("href")
		});
		if((inmyview_play_first && inmyview_first_track) || (inmyview_auto_play && !inmyview_first_track)) {
			inmyview_jPlayer.jPlayer("play");
			showInMyViewNowPlaying();
		}
		inmyview_first_track = false;
		$(this).blur();
		return false;
	});
	
}); 

 
























