/* sound.js by Stefan Bleilevens | last update: 2010-03-29 */



jQuery(document).ready(function(){

	var playItem = 0;

	var myPlayList = [
		/*{name:"Lena Meyer-Landrut - Satellite",mp3:"/files/satellite.mp3",ogg:"/files/satellite.ogg"},*/
		{name:"Breathe (Radio Mix)",mp3:"/files/breathe-radio-mix.mp3",ogg:"/files/breathe-radio-mix.ogg"}
	];

	// Local copy of jQuery selectors, for performance.
	var jpPlayTime = jQuery("#jplayer_play_time");
	var jpTotalTime = jQuery("#jplayer_total_time");
	var jpStatus = jQuery("#demo_status"); // For displaying information about jPlayer's status in the demo page

	jQuery("#jquery_jplayer").jPlayer({
		ready: function() {
			displayPlayList();
			playListInit(true); // Parameter is a boolean for autoplay.
			//demoInstanceInfo(this.element, jQuery("#demo_info")); // This displays information about jPlayer's configuration in the demo page
		},
		oggSupport: false
	})
	.jPlayer("onProgressChange", function(loadPercent, playedPercentRelative, playedPercentAbsolute, playedTime, totalTime) {
		jpPlayTime.text(jQuery.jPlayer.convertTime(playedTime));
		jpTotalTime.text(jQuery.jPlayer.convertTime(totalTime));

		//demoStatusInfo(this.element, jpStatus); // This displays information about jPlayer's status in the demo page
	})
	.jPlayer("onSoundComplete", function() {
		playListNext();
	});

	jQuery("#jplayer_previous").click( function() {
		playListPrev();
		return false;
	});

	jQuery("#jplayer_next").click( function() {
		playListNext();
		return false;
	});

	function displayPlayList() {
		for (i=0; i < myPlayList.length; i++) {
			jQuery("#jplayer_playlist ul").append("<li id='jplayer_playlist_item_"+i+"'>"+ myPlayList[i].name +"</li>");
			jQuery("#jplayer_playlist_item_"+i).data( "index", i ).click( function() {
				var index = jQuery(this).data("index");
				if (playItem != index) {
					playListChange( index );
				} else {
					jQuery("#jquery_jplayer").jPlayer("play");
				}
			});
		}
	}

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

	function playListConfig( index ) {
		jQuery("#jplayer_playlist_item_"+playItem).removeClass("jplayer_playlist_current");
		jQuery("#jplayer_playlist_item_"+index).addClass("jplayer_playlist_current");
		playItem = index;
		jQuery("#jquery_jplayer").jPlayer("setFile", myPlayList[playItem].mp3, myPlayList[playItem].ogg);
	}

	function playListChange( index ) {
		playListConfig( index );
		jQuery("#jquery_jplayer").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 );
	}
	
	
	jQuery('ul.jp-controls li').hover(function(){
		jQuery(this).css('background-position','0px -9px');
		 },function(){
			jQuery(this).css('background-position','0px 0px');														 
		});
});


