/* In Textpattern, first install jnm_audio plugin (version 0.3), 
     then go to Admin - plugins, click the jnm_audio plugin to edit it,
     and replace the ENTIRE contents of the plugin with the code below. */

function jnm_audio($atts, $thing='') {
   $plugindir='plugins'; // Directory where plugin files reside
   $audiodir='audio';    // Directory where audio files reside
   extract(lAtts(array(
      'loop' => 'no',
      'autostart' => 'no',
      'audio' => '',
      'fileid' => 0,
      'filename' => '',
      'url' => '',
      'title' => 'Podcast'
   ),$atts));

   // Nothing to touch below this line

   global $permlink_mode;

   static $playerid=1;

   $plugindir=hu.$plugindir;

	 if (!empty($fileid) || !empty($filename)) {
	    if ($fileid=='.')
	        $fileid=parse($thing);
	    if ($filename=='.')
          $filename=parse($thing);
      $where = (!empty($fileid) && $fileid != 0)? "id='$fileid'" : ((!empty($filename))? "filename='$filename'" : '');
			$thisfile = fileDownloadFetchInfo($where);
			$url = hu.'files/'.$thisfile['filename'];
			/* $url= ($permlink_mode == 'messy') ?
					hu.'index.php?s=file_download&amp;id='.$thisfile['id']:
					hu.gTxt('file_download').'/'.$thisfile['id']; */
	 }
	 else if (!empty($audio) && $audio!='') {
	    if ($audio=='.')
          $audio=parse($thing);
      $url=hu.$audiodir.'/'.$audio;
   }
   else if ($url=='.') {
       $url=parse($thing);
   }

   $output='';

   /* if ($playerid==1) {
     $output="<script type=\"text/javascript\" src=\"$plugindir/audio-player.js\"></script>";
   } */

/*   $object= <<< END
<object type="application/x-shockwave-flash" data="$plugindir/player.swf" id="audioplayer$playerid" height="24" width="290"><param name="movie" value="$plugindir/player.swf"/><param name="FlashVars" value="playerID=$playerid&amp;bg=$bgcolor&amp;leftbg=$leftbgcolor&amp;lefticon=$lefticoncolor&amp;rightbg=$rightbgcolor&amp;rightbghover=$rightbghovercolor&amp;righticon=$righticoncolor&amp;righticonhover=$righticonhovercolor&amp;text=$textcolor&amp;slider=$slidercolor&amp;track=$trackcolor&amp;border=$bordercolor&amp;loader=$loadercolor&amp;loop=$loop&amp;autostart=$autostart&amp;soundFile=$url"/><param name="quality" value="high"/><param name="menu" value="false"/><param name="wmode" value="transparent"/></object>
END;
*/
   $object= <<< END
        <div style="width: 292px; margin: 0 auto"><p id="audioplayer$playerid"><audio id="audio$playerid" controls preload="none" style="width:290px;"><source src="$url"></audio></p></div>  
        <script type="text/javascript">  
        AudioPlayer.embed("audioplayer$playerid", {soundFile: "$url", animation: "no", titles: "$title", rightbg: "AABA16", righticon: "FFFFFF", rightbghover: "BCCE18", righticonhover: "FFFFFF" });  
        </script>
END;

   $output = $output.$object;
   $playerid++;

   return $output;
}

function jad_bytestomb($atts, $thing='') {
   extract(lAtts(array(
      'bytes' => '1024'
   ),$atts));
  
  return number_format($bytes / 1048576, 2) . ' MB';
}