
	var currentProgramId = 0;
	
	var myListener = new Object();
	var isPlaying = false;
	myListener.onInit = function()
   	{		           	
   		//_addEventListener(document.getElementById("playerslider"), "mousedown", _sliderDown, false);
   		//_addEventListener(document, "mousemove", _sliderMove, false);
   		//_addEventListener(document, "mouseup", _sliderUp, false);
   	};
   	/**
   	 * Update
   	 */
   	myListener.onUpdate = function()
   	{	   		   		
   		isPlaying = this.isPlaying;
      		var url = this.url;
      		var volume = this.volume;
      		var position = this.position;
       	var duration = this.duration;

       	isPlaying = (isPlaying == "true");
      	
   	};
	var sliderPressed = false;
	function _getFlashObject()
	{   
		return document.getElementById("myFlash");
	}

	
	
	
	/**
	 * public functions
	 */
   var latestImgId = "";
   var currentHtml5AudioElement = null;
   
   function playHtml5Big(progid, imgId) {	
	  
	   if(latestImgId != imgId && document.getElementById(latestImgId) != null){			   
		   document.getElementById(latestImgId).style.background = "url(/images/buttons/provplay.png) no-repeat";
	   }
	   
	   
	   
	   if(currentHtml5AudioElement != null){
		   currentHtml5AudioElement.pause();
	   }
	   
	   document.getElementById(imgId).style.background = "url(/images/buttons/provpause.png) no-repeat";
	  	  
	   
	   
	   if(progid == currentProgramId){		   
		   currentProgramId = 0;		  
		   document.getElementById(imgId+progid).pause();
		   document.getElementById(imgId).style.background = "url(/images/buttons/provlyssnastorplay.png) no-repeat";
		   return;
	   }
	   
	 
	   html ='<audio id="'+imgId+progid+'" preload >'; 
	   html +='<source src="http://www.storytel.se/mp3?programId='+progid+'&startposition=0&ct=true" />';
	  	<!-- now include flash fall back -->
	   html +='</audio>';
	   
	 
	   var ni = document.getElementById('audiodiv');
	   var newdiv = document.createElement('div');
	   newdiv.innerHTML = html;
	   ni.appendChild(newdiv);
	   
	   document.getElementById(imgId).style.background = "url(/images/buttons/lyssnanustorpause.png) no-repeat";		   	 
	   document.getElementById(imgId+progid).play();  
	   currentHtml5AudioElement = document.getElementById(imgId+progid);
       currentProgramId = progid;	  
   }
   
   function play(progid, imgId) {	
	
	   /*
	var audioTagSupport = !!(document.createElement('audio').canPlayType);
	   
	   if(audioTagSupport){		
		   alert("xxxxxxxxx4444");
		   Html5Play(progid, imgId);
		   return;
	   }
	   */

	   
	   if(navigator.userAgent.indexOf("iPad") != -1 || navigator.userAgent.indexOf("iPod") != -1 || navigator.userAgent.indexOf("iPhone") != -1){		  		   
		   Html5Play(progid, imgId);
		   return;
	   }
	   
	  
	   if(latestImgId != imgId && document.getElementById(latestImgId) != null){	
		 
		 if(document.getElementById(latestImgId).style.background.indexOf('small') != -1){			 
			 document.getElementById(latestImgId).style.background = "url(/images/buttons/smallplay2.png) no-repeat";			 
		 }else{
		   document.getElementById(latestImgId).style.background = "url(/images/buttons/provplay.png) no-repeat";
		 }
	   }
	   
	   document.getElementById(imgId).style.background = "url(/images/buttons/provpause.png) no-repeat";
	   latestImgId = imgId;
	 
	   if(progid == currentProgramId){
		  
		   currentProgramId = 0;
		   stop();		
		   document.getElementById(imgId).style.background = "url(/images/buttons/provplay.png) no-repeat";
		   return;
	   }
	   
		  //alert(_getFlashObject());
	       _getFlashObject().SetVariable("method:setUrl", "http://www.storytel.se/mp3?programId="+progid+"&startposition=0");
	       _getFlashObject().SetVariable("method:play", "");
	       _getFlashObject().SetVariable("enabled", "true");
	   
	  /*html ='<object  type="application/x-shockwave-flash" data="scripts/player_mp3_sf.swf" width="1" height="1">';
	  html +='<param name="movie" value="scripts/player_mp3_sf.swf" />';	
	  html +='<param name="FlashVars" value="mp3=http%3A//www.storytel.se/mp3%3FprogramId%3D1%26startposition%3D0&amp;autoplay=1" />';				 			
	  html +='</object>';
	   
	 var ni = document.getElementById('audiodiv');
	   var newdiv = document.createElement('div');
	   newdiv.innerHTML = html;
	   ni.appendChild(newdiv);
	   */
       currentProgramId = progid;
   }
   
  
   
   function Html5Play(progid, imgId) {	   
	   
	  
	 
	   /*
	    * <audio id="playerHTML5<%= book.getId() %>" preload="none" autobuffer="false"> 
	  	<source src="http://www.storytel.se/mp3?programId=<%= book.getId() %>&startposition=0" />
	  	<!-- now include flash fall back -->
		</audio>
	    */
	   
	  
	   	  	  
	   if(currentHtml5AudioElement != null){
		   currentHtml5AudioElement.pause();
	   }
	   
	   if(latestImgId != imgId && document.getElementById(latestImgId) != null){	
		 
		 if(document.getElementById(latestImgId).style.background.indexOf('small') != -1){			 
			 document.getElementById(latestImgId).style.background = "url(/images/buttons/smallplay2.png) no-repeat";			 
		 }else{
		   document.getElementById(latestImgId).style.background = "url(/images/buttons/provplay.png) no-repeat";
		 }
	   }
	  
	   document.getElementById(imgId).style.background = "url(/images/buttons/provpause.png) no-repeat";
	   latestImgId = imgId;
	  
	   if(progid == currentProgramId){		  
		   currentProgramId = 0;
		   document.getElementById(imgId+progid).pause();
		   document.getElementById(imgId).style.background = "url(/images/buttons/provplay.png) no-repeat";
		   return;
	   }	   	  
	   
	   
	  
	   
	   html ='<audio id="'+imgId+progid+'" preload >'; 
	   html +='<source src="http://www.storytel.se/mp3?programId='+progid+'&startposition=0&ct=true" />';
	  	<!-- now include flash fall back -->
	   html +='</audio>';
	   
	 
	   var ni = document.getElementById('audiodiv');
	   var newdiv = document.createElement('div');
	   newdiv.innerHTML = html;
	   ni.appendChild(newdiv);
	   
	   document.getElementById(imgId+progid).play();
	   currentHtml5AudioElement = document.getElementById(imgId+progid);
       currentProgramId = progid;
   }
   
   function playBig(progid, imgId) {
	  
	   /*
	   var audioTagSupport = !!(document.createElement('audio').canPlayType);
	   if(audioTagSupport){
		   playHtml5Big(progid, imgId);
		   return;
	   }
	   */
	  
	   
	   
	   if(navigator.userAgent.indexOf("iPad") != -1 || navigator.userAgent.indexOf("iPod") != -1 || navigator.userAgent.indexOf("iPhone") != -1){		  
		   playHtml5Big(progid, imgId);
		   return;
	   }
	   
	   
	   

	   if(latestImgId != imgId && document.getElementById(latestImgId) != null){			   
		   document.getElementById(latestImgId).style.background = "url(/images/buttons/provplay.png) no-repeat";
	   }
	   
	   document.getElementById(imgId).style.background = "url(/images/buttons/provpause.png) no-repeat";
	  
	  
	   if(progid == currentProgramId){		   
		   currentProgramId = 0;
		   stop();		
		   document.getElementById(imgId).style.background = "url(/images/buttons/provlyssnastorplay.png) no-repeat";
		   return;
	   }
	   
	   document.getElementById(imgId).style.background = "url(/images/buttons/lyssnanustorpause.png) no-repeat";
       _getFlashObject().SetVariable("method:setUrl", "http://www.storytel.se/mp3?programId="+progid+"&startposition=0");
       _getFlashObject().SetVariable("method:play", "");
       _getFlashObject().SetVariable("enabled", "true");	  
       currentProgramId = progid;
       
   
   }
   
   function playSmall(progid, imgId) {	   
	
	   if(navigator.userAgent.indexOf("iPad") != -1 || navigator.userAgent.indexOf("iPod") != -1 || navigator.userAgent.indexOf("iPhone") != -1){		 
		   playSmallHtml5(progid, imgId);
		   return;
	   }
	   if(latestImgId != imgId && document.getElementById(latestImgId) != null){	
		   if(document.getElementById(latestImgId).style.background.indexOf('prov') != -1){			 
				 document.getElementById(latestImgId).style.background = "url(/images/buttons/provplay.png) no-repeat";			 
			 }else{
		   document.getElementById(latestImgId).style.background = "url(/images/buttons/smallplay2.png) no-repeat";
			 }
	   }
	   latestImgId = imgId;
	   if(progid == currentProgramId){		   
		   currentProgramId = 0;
		   stop();		
		   document.getElementById(imgId).style.background = "url(/images/buttons/smallplay2.png) no-repeat";
		   return;
	   }
	   
	   document.getElementById(imgId).style.background = "url(/images/buttons/smallpause2.png) no-repeat";
       _getFlashObject().SetVariable("method:setUrl", "http://www.storytel.se/mp3?programId="+progid+"&startposition=0");
       _getFlashObject().SetVariable("method:play", "");
       _getFlashObject().SetVariable("enabled", "true");	  
       currentProgramId = progid;
   }
   
   function playSmallHtml5(progid, imgId) {	   
	   
	   if(currentHtml5AudioElement != null){
		   currentHtml5AudioElement.pause();
	   }
	   
	   if(latestImgId != imgId && document.getElementById(latestImgId) != null){	
		   if(document.getElementById(latestImgId).style.background.indexOf('prov') != -1){			 
				 document.getElementById(latestImgId).style.background = "url(/images/buttons/provplay.png) no-repeat";			 
			 }else{
		   document.getElementById(latestImgId).style.background = "url(/images/buttons/smallplay2.png) no-repeat";
			 }
	   }
	   latestImgId = imgId;
	   if(progid == currentProgramId){		   
		   currentProgramId = 0;
		   document.getElementById(imgId+progid).pause();
		   document.getElementById(imgId).style.background = "url(/images/buttons/smallplay2.png) no-repeat";
		   return;
	   }
	   
	   document.getElementById(imgId).style.background = "url(/images/buttons/smallpause2.png) no-repeat";
	  
	   html ='<audio id="'+imgId+progid+'" preload >'; 
	   html +='<source src="http://www.storytel.se/mp3?programId='+progid+'&startposition=0&ct=true" />';
	  	<!-- now include flash fall back -->
	   html +='</audio>';
	   
	   var ni = document.getElementById('audiodiv'+progid);
	   var newdiv = document.createElement('div');
	   newdiv.innerHTML = html;
	   ni.appendChild(newdiv);
	   
	   document.getElementById(imgId+progid).play();	  
       currentProgramId = progid;
       currentHtml5AudioElement = document.getElementById(imgId+progid);
   }
   
   
   function playVoice(progid, imgId) {	   
	   
	   if(latestImgId != imgId && document.getElementById(latestImgId) != null){	
		   document.getElementById(latestImgId).style.background = "url(/images/buttons/provplay.png) no-repeat";			
	   }
	   latestImgId = imgId;
	   if(progid == currentProgramId){		   
		   currentProgramId = 0;
		   stop();		
		   document.getElementById(imgId).style.background = "url(/images/buttons/provplay.png) no-repeat";
		   return;
	   }
	   
	   document.getElementById(imgId).style.background = "url(/images/buttons/provpause.png) no-repeat";
       _getFlashObject().SetVariable("method:setUrl", "/storytel_voice/samples/"+progid+".mp3");
       _getFlashObject().SetVariable("method:play", "");
       _getFlashObject().SetVariable("enabled", "true");	  
       currentProgramId = progid;
   }
   
   function pause() {	   
       _getFlashObject().SetVariable("method:pause", "");
   }
   function stop() {
       _getFlashObject().SetVariable("method:stop", "");
   }







