/*
 HTML5 MP3 Player
 Version: 1.0.5
 (c) 2011 DMXzone.com
 @build 07-06-2011 12:17:47
*/
(function(d,h){var i=function(){var c=!1,a=navigator,b=a.plugins,e,d=window.ActiveXObject;if(b&&b.length)(a=a.mimeTypes)&&a["application/x-shockwave-flash"]&&a["application/x-shockwave-flash"].enabledPlugin&&a["application/x-shockwave-flash"].enabledPlugin.description&&(c=!0);else if(typeof d!=="undefined"){try{e=new d("ShockwaveFlash.ShockwaveFlash")}catch(g){}c=!!e}return c}();h.debugMode=!1;h.useConsole=!0;h.useFlashBlock=navigator.userAgent.toLowerCase().search("(android|blackberry|palm|series60|windows ce)")>
-1?!0:!1;h.flashVersion=9;h.flashLoadTimeout=3E3;h.useHTML5Audio=!i;h.html5Test=/^(probably|maybe)$/i;h.flash9Options.usePeakData=!0;CLS_PEAK_LEFT="dmxHTML5MP3PlayerPeakLeft";CLS_PEAK_LEFT_V="dmxHTML5MP3PlayerPeakLeftV";CLS_PEAK_LEFT_BAR="dmxHTML5MP3PlayerPeakLeftBar";CLS_PEAK_RIGHT="dmxHTML5MP3PlayerPeakRight";CLS_PEAK_RIGHT_V="dmxHTML5MP3PlayerPeakRightV";CLS_PEAK_RIGHT_BAR="dmxHTML5MP3PlayerPeakRightBar";d.fn.dmxHTML5MP3Player=function(c){var a=typeof c=="string",b=Array.prototype.slice.call(arguments,
1);if(a&&c.substring(0,1)=="_")return this;return this.each(function(){var e=d.data(this,"dmxHTML5MP3Player");!e&&!a&&d.data(this,"dmxHTML5MP3Player",new d.dmxHTML5MP3Player(this,c))._init();e&&a&&d.isFunction(e[c])&&e[c].apply(e,b)})};d.dmxHTML5MP3Player=function(c,a){this.element=d(c);this.options=d.extend({},a);this.sound=null;this.sounds={}};d.dmxHTML5MP3Player.defaults={swfPath:"",autoNext:!0,autoPlay:!1,loop:!0,volume:100,pan:0,playlist:[],shuffle:!1,onPlay:null,onPause:null,onStop:null,onPrevious:null,
onNext:null,onUpdate:null,onChange:null};d.dmxHTML5MP3Player._config={version:"1.0.3"};d.dmxHTML5MP3Player._diag={isReady:!1,isPlaying:!1,isMuted:!1,index:-1};d.dmxHTML5MP3Player.count=0;d.dmxHTML5MP3Player.timeFormat={showHour:!1,showMin:!0,showSec:!0,padHour:!1,padMin:!0,padSec:!0,sepHour:":",sepMin:":",sepSec:""};d.dmxHTML5MP3Player.convertTime=function(c){var a=d.dmxHTML5MP3Player.timeFormat,b=new Date(c),e=b.getUTCHours(),c=b.getUTCMinutes(),b=b.getUTCSeconds(),e=a.padHour&&e<10?"0"+e:e,c=a.padMin&&
c<10?"0"+c:c,b=a.padSec&&b<10?"0"+b:b;return(a.showHour?e+a.sepHour:"")+(a.showMin?c+a.sepMin:"")+(a.showSec?b+a.sepSec:"")};d.dmxHTML5MP3Player.prototype={_init:function(){var c,a=this,b=this.element,e=function(b){return function(c){c.preventDefault();a[b].apply(a)}};c=this.config=d.extend({},d.dmxHTML5MP3Player.defaults,this.options,d.dmxHTML5MP3Player._config);c.diag=d.extend({},d.dmxHTML5MP3Player._diag);this.element.data("dmxHTML5MP3Player.config",c);d.dmxHTML5MP3Player.count++;c.id="dmxHTML5MP3Player"+
d.dmxHTML5MP3Player.count;c.sound={volume:c.volume,pan:c.pan,onfinish:function(){b.find(".dmxHTML5MP3PlayerPositionBar").width("0%");c.autoNext&&a.next.apply(a)},onid3:function(){a._updateInfo.apply(a)},onstop:function(){b.find(".dmxHTML5MP3PlayerPositionBar").width("0%");b.find(".dmxHTML5MP3PlayerPositionHandle").css("left",0);a._updateInfo.apply(a)},onload:function(c){c?b.find(".dmxHTML5MP3PlayerLoadBar").width("100%"):console&&console.log&&console.log("Error loading sound: "+this.url);a._updateInfo.apply(a)},
whileloading:function(){var c=this.bytesTotal,c=c>0?100*this.bytesLoaded/c:0;b.find(".dmxHTML5MP3PlayerLoadBar").width(c+"%");a._updateInfo.apply(a)},whileplaying:function(){var c=this.loaded?this.duration:this.durationEstimate,c=c>0?100*this.position/c:0;b.find(".dmxHTML5MP3PlayerPositionBar").width(c+"%");b.find(".dmxHTML5MP3PlayerPositionHandle").css("left",c+"%");b.find("."+CLS_PEAK_LEFT+" ."+CLS_PEAK_LEFT_BAR).width(this.peakData.left*100+"%");b.find("."+CLS_PEAK_RIGHT+" ."+CLS_PEAK_RIGHT_BAR).width(this.peakData.right*
100+"%");b.find("."+CLS_PEAK_LEFT_V+" ."+CLS_PEAK_LEFT_BAR).height(this.peakData.left*100+"%");b.find("."+CLS_PEAK_RIGHT_V+" ."+CLS_PEAK_RIGHT_BAR).height(this.peakData.right*100+"%");b.trigger("dmxHTML5MP3Player.playing",[this]);a._updateInfo.apply(a)}};b.find(".dmxHTML5MP3PlayerInfo").each(function(){d(this).data("dmxHTML5MP3Player.tpl",d(this).html())});b.find(".dmxHTML5MP3PlayerPositionSlider").mousedown(function(c){var b=this;a.setPosition2(Math.max(0,Math.min(1,(c.pageX-d(b).offset().left)/
d(b).width())));d(document).bind("mousemove.dmxHTML5MP3Player",function(c){a.setPosition2(Math.max(0,Math.min(1,(c.pageX-d(b).offset().left)/d(b).width())))}).bind("mouseup.dmxHTML5MP3Player",function(c){d(document).unbind(".dmxHTML5MP3Player");a.setPosition2(Math.max(0,Math.min(1,(c.pageX-d(b).offset().left)/d(b).width())))})});b.find(".dmxHTML5MP3PlayerVolumeSlider").click(function(b){b=Math.round((b.pageX-d(this).offset().left)/d(this).width()*100);a.setVolume.apply(a,[b])});b.find(".dmxHTML5MP3PlayerVolumeSliderV").click(function(b){b=
100-Math.round((b.pageY-d(this).offset().top)/d(this).height()*100);a.setVolume.apply(a,[b])});b.find(".dmxHTML5MP3PlayerVolumeBar").width(c.volume+"%");a.config.loop&&b.find(".dmxHTML5MP3PlayerBtnRepeat").addClass("dmxHTML5MP3PlayerActive");a.config.loop&&b.find(".dmxHTML5MP3PlayerBtnRepeat").addClass("dmxHTML5MP3PlayerActive");b.find(".dmxHTML5MP3PlayerBtnPlay").click(e("play"));b.find(".dmxHTML5MP3PlayerBtnStop").click(e("stop"));b.find(".dmxHTML5MP3PlayerBtnPause").click(e("pause"));b.find(".dmxHTML5MP3PlayerBtnPrev").click(e("previous"));
b.find(".dmxHTML5MP3PlayerBtnNext").click(e("next"));b.find(".dmxHTML5MP3PlayerBtnMute").click(e("toggleMute"));b.find(".dmxHTML5MP3PlayerBtnShuffle").click(function(c){c.preventDefault();a.config.shuffle=!a.config.shuffle;a.config.shuffle?b.find(".dmxHTML5MP3PlayerBtnShuffle").addClass("dmxHTML5MP3PlayerActive"):b.find(".dmxHTML5MP3PlayerBtnShuffle").removeClass("dmxHTML5MP3PlayerActive")});b.find(".dmxHTML5MP3PlayerBtnRepeat").click(function(c){c.preventDefault();a.config.loop=!a.config.loop;a.config.loop?
b.find(".dmxHTML5MP3PlayerBtnRepeat").addClass("dmxHTML5MP3PlayerActive"):b.find(".dmxHTML5MP3PlayerBtnRepeat").removeClass("dmxHTML5MP3PlayerActive")});b.find(".dmxHTML5MP3PlayerBtnPlayPause").click(e("togglePause"));b.find(".dmxHTML5MP3PlayerBtnPlaylist").click(function(a){a.preventDefault();b.find(".dmxHTML5MP3PlayerPlaylist").slideToggle()});this.element.bind("dmxHTML5MP3Player.play",function(){a.element.find(".dmxHTML5MP3PlayerPlaying").removeClass("dmxHTML5MP3PlayerPlaying");a.element.find(".dmxHTML5MP3PlayerBtnPlayPause").addClass("dmxHTML5MP3PlayerPlaying");
a.element.find(".dmxHTML5MP3PlayerCurrent").addClass("dmxHTML5MP3PlayerPlaying")}).bind("dmxHTML5MP3Player.pause",function(){a.element.find(".dmxHTML5MP3PlayerPlaying").removeClass("dmxHTML5MP3PlayerPlaying")}).bind("dmxHTML5MP3Player.stop",function(){a.element.find(".dmxHTML5MP3PlayerPlaying").removeClass("dmxHTML5MP3PlayerPlaying")});var f=b.find(".dmxHTML5MP3PlayerPlayPause");f.length>0&&(f.find(".dmxHTML5MP3PlayerBtnPause").hide(),this.element.bind("dmxHTML5MP3Player.play",function(){f.find(".dmxHTML5MP3PlayerBtnPlay").hide();
f.find(".dmxHTML5MP3PlayerBtnPause").show()}).bind("dmxHTML5MP3Player.pause",function(){f.find(".dmxHTML5MP3PlayerBtnPlay").show();f.find(".dmxHTML5MP3PlayerBtnPause").hide()}).bind("dmxHTML5MP3Player.stop",function(){f.find(".dmxHTML5MP3PlayerBtnPlay").show();f.find(".dmxHTML5MP3PlayerBtnPause").hide()}));this.config.onPlay&&b.bind("dmxHTML5MP3Player.play",function(){if(typeof a.config.onPlay=="string"){var b=a;a.query&&(b=a.element.find(a.query).get(a.config.diag.index));(new Function(a._parse.call(a,
a.config.onPlay))).call(b)}else a.config.onPlay.call(a)});this.config.onPause&&b.bind("dmxHTML5MP3Player.pause",function(){if(typeof a.config.onPause=="string"){var b=a;a.query&&(b=a.element.find(a.query).get(a.config.diag.index));(new Function(a._parse.call(a,a.config.onPause))).call(b)}else a.config.onPause.call(a)});this.config.onStop&&b.bind("dmxHTML5MP3Player.stop",function(){if(typeof a.config.onStop=="string"){var b=a;a.query&&(b=a.element.find(a.query).get(a.config.diag.index));(new Function(a._parse.call(a,
a.config.onStop))).call(b)}else a.config.onStop.call(a)});this.element.bind("dmxHTML5MP3Player.mute",function(a,b){b?d(this).find(".dmxHTML5MP3PlayerBtnMute").addClass("dmxHTML5MP3PlayerActive"):d(this).find(".dmxHTML5MP3PlayerBtnMute").removeClass("dmxHTML5MP3PlayerActive")});this.element.bind("dmxHTML5MP3Player.volume",function(a,c){b.find(".dmxHTML5MP3PlayerVolumeSlider .dmxHTML5MP3PlayerVolumeBar").width(c+"%");b.find(".dmxHTML5MP3PlayerVolumeSlider .dmxHTML5MP3PlayerVolumeHandle").css("left",
c+"%");b.find(".dmxHTML5MP3PlayerVolumeSliderV .dmxHTML5MP3PlayerVolumeBar").height(c+"%");b.find(".dmxHTML5MP3PlayerVolumeSliderV .dmxHTML5MP3PlayerVolumeHandle").css("bottom",c+"%");b.find(".dmxHTML5MP3PlayerVolume").removeClass("dmxHTML5MP3PlayerVolumeMute dmxHTML5MP3PlayerVolumeLow dmxHTML5MP3PlayerVolumeMed dmxHTML5MP3PlayerVolumeHigh");c>80?b.find(".dmxHTML5MP3PlayerVolume").addClass("dmxHTML5MP3PlayerVolumeHigh"):c>40?b.find(".dmxHTML5MP3PlayerVolume").addClass("dmxHTML5MP3PlayerVolumeMed"):
c>0?b.find(".dmxHTML5MP3PlayerVolume").addClass("dmxHTML5MP3PlayerVolumeLow"):b.find(".dmxHTML5MP3PlayerVolume").addClass("dmxHTML5MP3PlayerVolumeMute")});this._updateInfo();var g=!1,j=!1,k=this.config.diag;this.hasSpryRegion()?Spry.Data.Region.addObserver(this._spryRegion,{onPostUpdate:function(){g=!0;j&&!k.ready&&a._ready.apply(a)}}):g=!0;h.onready(function(){j=!0;g&&!k.ready&&a._ready.apply(a)});h.ontimeout(function(){!i&&!h.hasHTML5?alert("Your browser does not support HTML5/Flash to play the audio!"):
alert('SoundManager 2 failed to initialize! Likely causes: Loading "soundmanager2_flash9.swf" may have failed (and/or Flash is not present?), Flash blocked or JS-Flash security error.')})},_ready:function(){var c,a=this,b=this.config,e=b.diag,f=b.playlist;if(typeof f=="string")this.query=f,b.playlist=[],this.element.find(f).each(function(c){b.playlist.push(this.href);d(this).click(function(b){b.preventDefault();c!=a.config.diag.index?a._setSound(c,!0):a.togglePause()})});f=b.playlist;if(f.length>
0){for(var g=0;g<f.length;g++)c=f[g],c in this.sounds||(this.sounds[c]=h.createSound({id:b.id+"_"+g,url:c,volume:b.volume}));this._setSound(0,b.autoPlay)}e.isReady=!0;this.element.trigger("dmxHTML5MP3Player.ready")},hasSpryRegion:function(){if(typeof Spry!="undefined"&&Spry.Data&&Spry.Data.regionsArray)for(var c in this.isEmptyObject(Spry.Data.regionsArray)&&Spry.Data.initRegions(),Spry.Data.regionsArray)if(this.element.find("#"+c).length>0)return this._spryRegion=c,!0;return!1},isEmptyObject:function(c){for(var a in c)return!1;
return!0},mute:function(){this._mute(!0)},next:function(){var c,a=this.sound,b=this.config,e=b.diag,d=b.playlist.length;if(d>1&&(c=b.shuffle?Math.floor(Math.random()*d):e.index+1,c>=d&&b.loop&&(c=0),c<d&&(a&&a.stop(),this._setSound(c,e.isPlaying),b.onNext)))if(typeof b.onNext=="string")c=this,this.query&&(c=this.element.find(this.query).get(e.index)),(new Function(this._parse(b.onNext))).call(c);else b.onNext()},pause:function(){var c=this.sound;c&&c.pause();this.element.find(".dmxHTML5MP3PlayerBtnPlay").removeClass("dmxHTML5MP3PlayerActive");
this.config.diag.isPlaying=!1;this.element.trigger("dmxHTML5MP3Player.pause")},play:function(c){c!=null&&c>=0&&c<this.config.playlist.length?this._setSound(c,!0):this.config.diag.isPlaying||this._play()},previous:function(){var c,a=this.sound,b=this.config,e=b.diag,d=b.playlist.length;if(d>1&&(c=b.shuffle?Math.floor(Math.random()*d):e.index-1,c<0&&b.loop&&(c=d-1),c>=0&&(a&&a.stop(),this._setSound(c,e.isPlaying),b.onPrevious)))if(typeof b.onPrevious=="string")c=this,this.query&&(c=this.element.find(this.query).get(e.index)),
(new Function(this._parse(b.onPrevious))).call(c);else b.onPrevious()},setPan:function(c){var a=this.sound,b=this.config.sound.pan,b=Math.max(-100,Math.min(100,c));a&&a.setPan(b);this.element.trigger("dmxHTML5MP3Player.pan",[b])},setPosition:function(c){var a=this.sound;a&&a.setPosition(c)},setPosition2:function(c){var a=this.sound,b=a.loaded?a.duration:a.durationEstimate;a.playState!=0&&a&&b>0&&a.setPosition(c*b)},setVolume:function(c){var a=this.sound,b=this.config.sound.volume,b=this.config.sound.volume=
Math.max(0,Math.min(100,c));a&&a.setVolume(b);this._updateInfo();this.element.trigger("dmxHTML5MP3Player.volume",[b])},stop:function(){var c=this.sound;c&&c.stop();this.element.find(".dmxHTML5MP3PlayerBtnPlay").removeClass("dmxHTML5MP3PlayerActive");this.config.diag.isPlaying=!1;this.element.trigger("dmxHTML5MP3Player.stop")},toggleMute:function(){this._mute(!this.config.diag.isMuted)},togglePause:function(){this.sound&&(this.config.diag.isPlaying?this.pause():this.play())},unmute:function(){this._mute(!1)},
_mute:function(c){var a=this.sound;c?a&&a.mute():a&&a.unmute();this.config.diag.isMuted=c;this._updateInfo();this.element.trigger("dmxHTML5MP3Player.mute",[c]);this.element.trigger("dmxHTML5MP3Player.volume",[c?0:this.config.sound.volume])},_play:function(){var c=this.sound,a=this.config;if(c)c.paused?c.resume():c.play(a.sound),a.diag.isPlaying=!0,this.element.trigger("dmxHTML5MP3Player.play"),this.element.find(".dmxHTML5MP3PlayerBtnPlay").addClass("dmxHTML5MP3PlayerActive")},_setSound:function(c,
a){var b=this.sound,d=this.config,f=d.diag,g=this.element;b&&b.stop();b&&!b.loaded&&b.unload();f.index=c;b=this.sound=this.sounds[d.playlist[c]];b.setVolume(f.volume);this._mute(f.isMuted);var h=b.bytesTotal||0,b=h>0?100*b.bytesLoaded/h:0;g.find(".dmxHTML5MP3PlayerLoadBar").width(b+"%");g.find(".dmxHTML5MP3PlayerPositionBar").width("0%");this._updateInfo();this.query&&g.find(this.query).removeClass("dmxHTML5MP3PlayerCurrent").eq(c).addClass("dmxHTML5MP3PlayerCurrent");a&&this._play();g.trigger("dmxHTML5MP3Player.change");
if(d.onChange)if(typeof d.onChange=="string")g=this,this.query&&(g=this.element.find(this.query).get(f.index)),(new Function(this._parse(d.onChange))).call(g);else d.onChange()},_updateInfo:function(){var c=this;this.element.find(".dmxHTML5MP3PlayerInfo").each(function(){d(this).html(c._parse.call(c,d(this).data("dmxHTML5MP3Player.tpl")))});if(this.config.onUpdate)if(typeof this.config.onUpdate=="string"){var a=this;this.query&&(a=this.element.find(this.query).get(this.config.diag.index));(new Function(this._parse(this.config.onUpdate))).call(a)}else this.config.onUpdate()},
_parse:function(c){var a=this.config,b=a.diag,a=a.sound,e=this.sound,f=d.dmxHTML5MP3Player.convertTime,g=this._getTitle();g||(g="");return c.replace(/##index##/g,b.index).replace(/##nr##/g,b.index+1).replace(/##title##/g,g.replace(/'/g,"\\'").replace(/"/g,'\\"'.replace(/([\n\r\t])/g,"\\$1"))).replace(/##time##/g,f(e?e.position:0)).replace(/##remaining##/g,f(e?e.duration-e.position:0)).replace(/##duration##/g,f(e?e.duration:0)).replace(/##position##/g,e?this._perc(e.position,e.duration):0).replace(/##volume##/g,
b.isMuted?0:a.volume).replace(/##pan##/g,a.pan).replace(/##peakLeft##/g,h.features.peakData?e?e.peakData.left:0:0).replace(/##peakRight##/g,h.features.peakData?e?e.peakData.right:0:0)},_perc:function(c,a){return Math.round(100*c/a)||0},_getTitle:function(){var c=this.sound;if(this.query){var a=this.element.find(this.query).eq(this.config.diag.index);if(a.attr("title")!="")return a.attr("title");if(a.text()!="")return a.text()}return c?c.id3.title||c.id3.TIT2||c.url.substring(c.url.lastIndexOf("/")+
1):"No sound loaded..."}}})(jQuery,soundManager);

