$(window).load(function(){
		$("a.embeddedPlayer").each(function(){
			var MP3URL=$(this).attr("href");
			var Controls=this;
			var Flash=false;
			var FlashHooked=false;
			var FlashObj;
			var PlayerKey="EP_"+Math.round(Math.random()*1000);
			var AudioPlayer=$('<audio preload><source src="'+MP3URL+'"/></audio>'); 
			AudioPlayer.insertBefore(this);
			
			$(this).addClass("playerControlUnsupported");
			$(this).attr("id",PlayerKey);
			
			try {
				AudioPlayer.get(0).canPlayType("audio/test");//unsupported browsers stop here!
			} catch (exc) {
				Flash=true;
			}
			
			if (!Flash && AudioPlayer.get(0).canPlayType("audio/mp3")==""){
				Flash=true;
			}
			
			if (Flash){
				
				FlashObj=$('<object class="embeddedPlayerFlash" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0"><param name="movie" value="http://s.learnnavi.org/js/niftyplayer.swf?file='+encodeURIComponent(MP3URL)+'" /><param name="AllowScriptAccess" value="always" /><embed allowScriptAccess="always" src="http://s.learnnavi.org/js/niftyplayer.swf?file='+encodeURIComponent(MP3URL)+'" class="embeddedPlayerFlash" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed></object>').get(0);
				
				if (typeof FlashObj.SetVariable=='undefined') {
					FlashObj=$("embed",$(FlashObj)).get(0);
				}
				
				$(FlashObj).insertAfter(this);
				
			}
			
			$(this).click(function(e){
				
				if (!FlashHooked && Flash){
					FlashObj.SetVariable("onSongOver", "resetPlayer('"+PlayerKey+"')");FlashHooked=true;
				}
				if (this.playing==true) {
					if (!Flash){
						AudioPlayer.get(0).pause();
						AudioPlayer.get(0).currentTime=0;
					} else {
						FlashObj.TCallLabel('/','stop');
					}
					$(this).removeClass("playerActive");
					this.playing=false;
				} else {
					if (!Flash){
						AudioPlayer.get(0).play();
					} else {
						FlashObj.TCallLabel('/','play');

					}
					$(this).addClass("playerActive");
					this.playing=true;
				}
				
				e.stopPropagation();
				e.preventDefault();
				return false;
			});
			AudioPlayer.bind("ended",function(){
				$(Controls).removeClass("playerActive");
				Controls.playing=false;
			});
			
			$(this).addClass("playerControl");
		});
	});
	
	function resetPlayer(key){
		$("#"+key).removeClass("playerActive");
		$("#"+key).get(0).playing=false;
	}


