(function ($) {$.fn.initPlayer = function(options) {
  		var defaults = {
  			autoPlay: true,
  			ready: function() {
  				playListInit(options.autoPlay); // Parameter is a boolean for autoplay.
  			},
  			oggSupport: false,
  			playlist: [],
  			swfPath: "/javascripts"
  		};
  		var options = $.extend(defaults, options);
  		return this.each(function() {
  				var obj = $(this);
  				$(this).data("playList.list", options.playlist)
  				$(this).jPlayer(options)
  				.jPlayerId("play", "play")
  				.jPlayerId("pause", "pause")
  				.jPlayerId("loadBar", "player-loading-progress")
  				.jPlayerId("playBar", "player-play-progress")
  				.onSoundComplete( function() {
  					$(this).trigger("playList.next")
  				})
					.onProgressChange(function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
						return
					})
  				.bind("playList.next", function() {
  					var playItem = $(this).data("playList.currentItem")
  					var index = (playItem+1 < options.playlist.length) ? playItem+1 : 0;
  					playListChange( index )
  				})
  				.bind("playList.previous", function() {
  					var playItem = $(this).data("playList.currentItem")
  					var index = (playItem-1 >= 0) ? playItem-1 : options.playlist.length-1;
  					playListChange( index )
  				})
  				.bind("playList.change", function(e, index) {
  					playListChange(index);
  				})				
  				$("#prev").click( function() {
  					$("#jplayer").trigger("playList.previous");
  					return false;
  				});
  				$("#next").click( function() {
  					$("#jplayer").trigger("playList.next");
  					return false;
  				});
  			}
  		);		
  		function playListInit(autoplay) {
  			$("#jplayer").data("playList.currentItem", 0)
  			if(autoplay) {
  				playListChange( $("#jplayer").data("playList.currentItem") );
  			} else {
  				playListConfig( $("#jplayer").data("playList.currentItem") );
  			}
  		};

  		function playListConfig( index ) {
  			var current = $("#jplayer").data("playList.list")[index];
  			$("#jplayer").data("playList.currentItem", index);
  			$("#player-title").text(current.name);
  			$("#jplayer").setFile(current.mp3);
  		}

  		function playListChange( index ) {
  			playListConfig( index );
  			$("#jplayer").play();
  		}



}
}
)(jQuery)