summaryrefslogtreecommitdiffstats
path: root/Processing-js/libs/inc
diff options
context:
space:
mode:
Diffstat (limited to 'Processing-js/libs/inc')
-rw-r--r--Processing-js/libs/inc/Base64.js67
-rwxr-xr-xProcessing-js/libs/inc/SoundManager2/license.txt29
-rwxr-xr-xProcessing-js/libs/inc/SoundManager2/script/soundmanager2-jsmin.js104
-rwxr-xr-xProcessing-js/libs/inc/SoundManager2/script/soundmanager2-nodebug-jsmin.js77
-rwxr-xr-xProcessing-js/libs/inc/SoundManager2/script/soundmanager2-nodebug.js2377
-rwxr-xr-xProcessing-js/libs/inc/SoundManager2/script/soundmanager2.js5019
-rwxr-xr-xProcessing-js/libs/inc/SoundManager2/swf/soundmanager2.swfbin0 -> 2850 bytes
-rwxr-xr-xProcessing-js/libs/inc/SoundManager2/swf/soundmanager2_debug.swfbin0 -> 3280 bytes
-rwxr-xr-xProcessing-js/libs/inc/SoundManager2/swf/soundmanager2_flash9.swfbin0 -> 8682 bytes
-rwxr-xr-xProcessing-js/libs/inc/SoundManager2/swf/soundmanager2_flash9_debug.swfbin0 -> 16806 bytes
-rwxr-xr-xProcessing-js/libs/inc/SoundManager2/swf/soundmanager2_flash_xdomain.zipbin0 -> 32404 bytes
-rw-r--r--Processing-js/libs/inc/WebMIDIAPI.js421
-rw-r--r--Processing-js/libs/inc/base64binary.js80
-rw-r--r--Processing-js/libs/inc/jasmid/LICENSE24
-rw-r--r--Processing-js/libs/inc/jasmid/midifile.js238
-rw-r--r--Processing-js/libs/inc/jasmid/replayer.js96
-rw-r--r--Processing-js/libs/inc/jasmid/stream.js69
17 files changed, 8601 insertions, 0 deletions
diff --git a/Processing-js/libs/inc/Base64.js b/Processing-js/libs/inc/Base64.js
new file mode 100644
index 0000000..7c1ef07
--- /dev/null
+++ b/Processing-js/libs/inc/Base64.js
@@ -0,0 +1,67 @@
+// http://ntt.cc/2008/01/19/base64-encoder-decoder-with-javascript.html
+
+// window.atob and window.btoa
+
+(function (window) {
+
+ var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
+
+ window.btoa || (window.btoa = function encode64(input) {
+ input = escape(input);
+ var output = "";
+ var chr1, chr2, chr3 = "";
+ var enc1, enc2, enc3, enc4 = "";
+ var i = 0;
+ do {
+ chr1 = input.charCodeAt(i++);
+ chr2 = input.charCodeAt(i++);
+ chr3 = input.charCodeAt(i++);
+ enc1 = chr1 >> 2;
+ enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
+ enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
+ enc4 = chr3 & 63;
+ if (isNaN(chr2)) {
+ enc3 = enc4 = 64;
+ } else if (isNaN(chr3)) {
+ enc4 = 64;
+ }
+ output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4);
+ chr1 = chr2 = chr3 = "";
+ enc1 = enc2 = enc3 = enc4 = "";
+ } while (i < input.length);
+ return output;
+ });
+
+ window.atob || (window.atob = function(input) {
+ var output = "";
+ var chr1, chr2, chr3 = "";
+ var enc1, enc2, enc3, enc4 = "";
+ var i = 0;
+ // remove all characters that are not A-Z, a-z, 0-9, +, /, or =
+ var base64test = /[^A-Za-z0-9\+\/\=]/g;
+ if (base64test.exec(input)) {
+ alert("There were invalid base64 characters in the input text.\n" + "Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\n" + "Expect errors in decoding.");
+ }
+ input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
+ do {
+ enc1 = keyStr.indexOf(input.charAt(i++));
+ enc2 = keyStr.indexOf(input.charAt(i++));
+ enc3 = keyStr.indexOf(input.charAt(i++));
+ enc4 = keyStr.indexOf(input.charAt(i++));
+ chr1 = (enc1 << 2) | (enc2 >> 4);
+ chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
+ chr3 = ((enc3 & 3) << 6) | enc4;
+ output = output + String.fromCharCode(chr1);
+ if (enc3 != 64) {
+ output = output + String.fromCharCode(chr2);
+ }
+ if (enc4 != 64) {
+ output = output + String.fromCharCode(chr3);
+ }
+ chr1 = chr2 = chr3 = "";
+ enc1 = enc2 = enc3 = enc4 = "";
+ } while (i < input.length);
+ return unescape(output);
+ });
+
+}(this)); \ No newline at end of file
diff --git a/Processing-js/libs/inc/SoundManager2/license.txt b/Processing-js/libs/inc/SoundManager2/license.txt
new file mode 100755
index 0000000..1a17182
--- /dev/null
+++ b/Processing-js/libs/inc/SoundManager2/license.txt
@@ -0,0 +1,29 @@
+Software License Agreement (BSD License)
+
+Copyright (c) 2007, Scott Schiller (schillmania.com)
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification,
+are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice, this
+ list of conditions and the following disclaimer in the documentation and/or
+ other materials provided with the distribution.
+
+* Neither the name of schillmania.com nor the names of its contributors may be
+ used to endorse or promote products derived from this software without
+ specific prior written permission from schillmania.com.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file
diff --git a/Processing-js/libs/inc/SoundManager2/script/soundmanager2-jsmin.js b/Processing-js/libs/inc/SoundManager2/script/soundmanager2-jsmin.js
new file mode 100755
index 0000000..e8b14ae
--- /dev/null
+++ b/Processing-js/libs/inc/SoundManager2/script/soundmanager2-jsmin.js
@@ -0,0 +1,104 @@
+/** @license
+
+
+ SoundManager 2: JavaScript Sound for the Web
+ ----------------------------------------------
+ http://schillmania.com/projects/soundmanager2/
+
+ Copyright (c) 2007, Scott Schiller. All rights reserved.
+ Code provided under the BSD License:
+ http://schillmania.com/projects/soundmanager2/license.txt
+
+ V2.97a.20111220
+*/
+(function(G){function W(W,la){function l(b){return function(a){var d=this._t;return!d||!d._a?(d&&d.sID?c._wD(k+"ignoring "+a.type+": "+d.sID):c._wD(k+"ignoring "+a.type),null):b.call(this,a)}}this.flashVersion=8;this.debugMode=!0;this.debugFlash=!1;this.consoleOnly=this.useConsole=!0;this.waitForWindowLoad=!1;this.bgColor="#ffffff";this.useHighPerformance=!1;this.html5PollingInterval=this.flashPollingInterval=null;this.flashLoadTimeout=1E3;this.wmode=null;this.allowScriptAccess="always";this.useFlashBlock=
+!1;this.useHTML5Audio=!0;this.html5Test=/^(probably|maybe)$/i;this.preferFlash=!0;this.noSWFCache=!1;this.audioFormats={mp3:{type:['audio/mpeg; codecs="mp3"',"audio/mpeg","audio/mp3","audio/MPA","audio/mpa-robust"],required:!0},mp4:{related:["aac","m4a"],type:['audio/mp4; codecs="mp4a.40.2"',"audio/aac","audio/x-m4a","audio/MP4A-LATM","audio/mpeg4-generic"],required:!1},ogg:{type:["audio/ogg; codecs=vorbis"],required:!1},wav:{type:['audio/wav; codecs="1"',"audio/wav","audio/wave","audio/x-wav"],required:!1}};
+this.defaultOptions={autoLoad:!1,autoPlay:!1,from:null,loops:1,onid3:null,onload:null,whileloading:null,onplay:null,onpause:null,onresume:null,whileplaying:null,onposition:null,onstop:null,onfailure:null,onfinish:null,multiShot:!0,multiShotEvents:!1,position:null,pan:0,stream:!0,to:null,type:null,usePolicyFile:!1,volume:100};this.flash9Options={isMovieStar:null,usePeakData:!1,useWaveformData:!1,useEQData:!1,onbufferchange:null,ondataerror:null};this.movieStarOptions={bufferTime:3,serverURL:null,onconnect:null,
+duration:null};this.movieID="sm2-container";this.id=la||"sm2movie";this.debugID="soundmanager-debug";this.debugURLParam=/([#?&])debug=1/i;this.versionNumber="V2.97a.20111220";this.movieURL=this.version=null;this.url=W||null;this.altURL=null;this.enabled=this.swfLoaded=!1;this.oMC=null;this.sounds={};this.soundIDs=[];this.didFlashBlock=this.muted=!1;this.filePattern=null;this.filePatterns={flash8:/\.mp3(\?.*)?$/i,flash9:/\.mp3(\?.*)?$/i};this.features={buffering:!1,peakData:!1,waveformData:!1,eqData:!1,
+movieStar:!1};this.sandbox={type:null,types:{remote:"remote (domain-based) rules",localWithFile:"local with file access (no internet access)",localWithNetwork:"local with network (internet access only, no local access)",localTrusted:"local, trusted (local+internet access)"},description:null,noRemote:null,noLocal:null};var ma;try{ma="undefined"!==typeof Audio&&"undefined"!==typeof(new Audio).canPlayType}catch(fb){ma=!1}this.hasHTML5=ma;this.html5={usingFlash:null};this.flash={};this.ignoreFlash=this.html5Only=
+!1;var Ea,c=this,i=null,k="HTML5::",u,p=navigator.userAgent,j=G,O=j.location.href.toString(),h=document,na,X,m,B=[],oa=!0,w,P=!1,Q=!1,n=!1,y=!1,Y=!1,o,Za=0,R,v,pa,H,I,Z,Fa,qa,E,$,aa,J,ra,sa,ba,ca,K,Ga,ta,$a=["log","info","warn","error"],Ha,da,Ia,S=null,ua=null,q,va,L,Ja,ea,fa,wa,s,ga=!1,xa=!1,Ka,La,Ma,ha=0,T=null,ia,z=null,Na,ja,U,C,ya,za,Oa,r,Pa=Array.prototype.slice,F=!1,t,ka,Qa,A,Ra,Aa=p.match(/(ipad|iphone|ipod)/i),ab=p.match(/firefox/i),bb=p.match(/droid/i),D=p.match(/msie/i),cb=p.match(/webkit/i),
+V=p.match(/safari/i)&&!p.match(/chrome/i),db=p.match(/opera/i),Ba=p.match(/(mobile|pre\/|xoom)/i)||Aa,Ca=!O.match(/usehtml5audio/i)&&!O.match(/sm2\-ignorebadua/i)&&V&&!p.match(/silk/i)&&p.match(/OS X 10_6_([3-7])/i),Sa="undefined"!==typeof console&&"undefined"!==typeof console.log,Da="undefined"!==typeof h.hasFocus?h.hasFocus():null,M=V&&"undefined"===typeof h.hasFocus,Ta=!M,Ua=/(mp3|mp4|mpa)/i,N=h.location?h.location.protocol.match(/http/i):null,Va=!N?"http://":"",Wa=/^\s*audio\/(?:x-)?(?:mpeg4|aac|flv|mov|mp4||m4v|m4a|mp4v|3gp|3g2)\s*(?:$|;)/i,
+Xa="mpeg4,aac,flv,mov,mp4,m4v,f4v,m4a,mp4v,3gp,3g2".split(","),eb=RegExp("\\.("+Xa.join("|")+")(\\?.*)?$","i");this.mimePattern=/^\s*audio\/(?:x-)?(?:mp(?:eg|3))\s*(?:$|;)/i;this.useAltURL=!N;this._global_a=null;if(Ba&&(c.useHTML5Audio=!0,c.preferFlash=!1,Aa))F=c.ignoreFlash=!0;this.supported=this.ok=function(){return z?n&&!y:c.useHTML5Audio&&c.hasHTML5};this.getMovie=function(c){return u(c)||h[c]||j[c]};this.createSound=function(b){function a(){f=ea(f);c.sounds[e.id]=new Ea(e);c.soundIDs.push(e.id);
+return c.sounds[e.id]}var d,f=null,e=d=null;d="soundManager.createSound(): "+q(!n?"notReady":"notOK");if(!n||!c.ok())return wa(d),!1;2===arguments.length&&(b={id:arguments[0],url:arguments[1]});f=v(b);f.url=ia(f.url);e=f;e.id.toString().charAt(0).match(/^[0-9]$/)&&c._wD("soundManager.createSound(): "+q("badID",e.id),2);c._wD("soundManager.createSound(): "+e.id+" ("+e.url+")",1);if(s(e.id,!0))return c._wD("soundManager.createSound(): "+e.id+" exists",1),c.sounds[e.id];if(ja(e))d=a(),c._wD("Loading sound "+
+e.id+" via HTML5"),d._setup_html5(e);else{if(8<m){if(null===e.isMovieStar)e.isMovieStar=e.serverURL||(e.type?e.type.match(Wa):!1)||e.url.match(eb);e.isMovieStar&&c._wD("soundManager.createSound(): using MovieStar handling");if(e.isMovieStar){if(e.usePeakData)o("noPeak"),e.usePeakData=!1;1<e.loops&&o("noNSLoop")}}e=fa(e,"soundManager.createSound(): ");d=a();if(8===m)i._createSound(e.id,e.loops||1,e.usePolicyFile);else if(i._createSound(e.id,e.url,e.usePeakData,e.useWaveformData,e.useEQData,e.isMovieStar,
+e.isMovieStar?e.bufferTime:!1,e.loops||1,e.serverURL,e.duration||null,e.autoPlay,!0,e.autoLoad,e.usePolicyFile),!e.serverURL)d.connected=!0,e.onconnect&&e.onconnect.apply(d);!e.serverURL&&(e.autoLoad||e.autoPlay)&&d.load(e)}!e.serverURL&&e.autoPlay&&d.play();return d};this.destroySound=function(b,a){if(!s(b))return!1;var d=c.sounds[b],f;d._iO={};d.stop();d.unload();for(f=0;f<c.soundIDs.length;f++)if(c.soundIDs[f]===b){c.soundIDs.splice(f,1);break}a||d.destruct(!0);delete c.sounds[b];return!0};this.load=
+function(b,a){return!s(b)?!1:c.sounds[b].load(a)};this.unload=function(b){return!s(b)?!1:c.sounds[b].unload()};this.onposition=this.onPosition=function(b,a,d,f){return!s(b)?!1:c.sounds[b].onposition(a,d,f)};this.clearOnPosition=function(b,a,d){return!s(b)?!1:c.sounds[b].clearOnPosition(a,d)};this.start=this.play=function(b,a){if(!n||!c.ok())return wa("soundManager.play(): "+q(!n?"notReady":"notOK")),!1;if(!s(b)){a instanceof Object||(a={url:a});return a&&a.url?(c._wD('soundManager.play(): attempting to create "'+
+b+'"',1),a.id=b,c.createSound(a).play()):!1}return c.sounds[b].play(a)};this.setPosition=function(b,a){return!s(b)?!1:c.sounds[b].setPosition(a)};this.stop=function(b){if(!s(b))return!1;c._wD("soundManager.stop("+b+")",1);return c.sounds[b].stop()};this.stopAll=function(){var b;c._wD("soundManager.stopAll()",1);for(b in c.sounds)c.sounds.hasOwnProperty(b)&&c.sounds[b].stop()};this.pause=function(b){return!s(b)?!1:c.sounds[b].pause()};this.pauseAll=function(){var b;for(b=c.soundIDs.length;b--;)c.sounds[c.soundIDs[b]].pause()};
+this.resume=function(b){return!s(b)?!1:c.sounds[b].resume()};this.resumeAll=function(){var b;for(b=c.soundIDs.length;b--;)c.sounds[c.soundIDs[b]].resume()};this.togglePause=function(b){return!s(b)?!1:c.sounds[b].togglePause()};this.setPan=function(b,a){return!s(b)?!1:c.sounds[b].setPan(a)};this.setVolume=function(b,a){return!s(b)?!1:c.sounds[b].setVolume(a)};this.mute=function(b){var a=0;"string"!==typeof b&&(b=null);if(b){if(!s(b))return!1;c._wD('soundManager.mute(): Muting "'+b+'"');return c.sounds[b].mute()}c._wD("soundManager.mute(): Muting all sounds");
+for(a=c.soundIDs.length;a--;)c.sounds[c.soundIDs[a]].mute();return c.muted=!0};this.muteAll=function(){c.mute()};this.unmute=function(b){"string"!==typeof b&&(b=null);if(b){if(!s(b))return!1;c._wD('soundManager.unmute(): Unmuting "'+b+'"');return c.sounds[b].unmute()}c._wD("soundManager.unmute(): Unmuting all sounds");for(b=c.soundIDs.length;b--;)c.sounds[c.soundIDs[b]].unmute();c.muted=!1;return!0};this.unmuteAll=function(){c.unmute()};this.toggleMute=function(b){return!s(b)?!1:c.sounds[b].toggleMute()};
+this.getMemoryUse=function(){var c=0;i&&8!==m&&(c=parseInt(i._getMemoryUse(),10));return c};this.disable=function(b){var a;"undefined"===typeof b&&(b=!1);if(y)return!1;y=!0;o("shutdown",1);for(a=c.soundIDs.length;a--;)Ha(c.sounds[c.soundIDs[a]]);R(b);r.remove(j,"load",I);return!0};this.canPlayMIME=function(b){var a;c.hasHTML5&&(a=U({type:b}));return!z||a?a:b?!!(8<m&&b.match(Wa)||b.match(c.mimePattern)):null};this.canPlayURL=function(b){var a;c.hasHTML5&&(a=U({url:b}));return!z||a?a:b?!!b.match(c.filePattern):
+null};this.canPlayLink=function(b){return"undefined"!==typeof b.type&&b.type&&c.canPlayMIME(b.type)?!0:c.canPlayURL(b.href)};this.getSoundById=function(b,a){if(!b)throw Error("soundManager.getSoundById(): sID is null/undefined");var d=c.sounds[b];!d&&!a&&c._wD('"'+b+'" is an invalid sound ID.',2);return d};this.onready=function(b,a){if(b&&b instanceof Function)return n&&c._wD(q("queue","onready")),a||(a=j),pa("onready",b,a),H(),!0;throw q("needFunction","onready");};this.ontimeout=function(b,a){if(b&&
+b instanceof Function)return n&&c._wD(q("queue","ontimeout")),a||(a=j),pa("ontimeout",b,a),H({type:"ontimeout"}),!0;throw q("needFunction","ontimeout");};this._wD=this._writeDebug=function(b,a,d){var f,e;if(!c.debugMode)return!1;"undefined"!==typeof d&&d&&(b=b+" | "+(new Date).getTime());if(Sa&&c.useConsole){d=$a[a];if("undefined"!==typeof console[d])console[d](b);else console.log(b);if(c.consoleOnly)return!0}try{f=u("soundmanager-debug");if(!f)return!1;e=h.createElement("div");if(0===++Za%2)e.className=
+"sm2-alt";a="undefined"===typeof a?0:parseInt(a,10);e.appendChild(h.createTextNode(b));if(a){if(2<=a)e.style.fontWeight="bold";if(3===a)e.style.color="#ff3333"}f.insertBefore(e,f.firstChild)}catch(i){}return!0};this._debug=function(){var b,a;o("currentObj",1);for(b=0,a=c.soundIDs.length;b<a;b++)c.sounds[c.soundIDs[b]]._debug()};this.reboot=function(){c._wD("soundManager.reboot()");c.soundIDs.length&&c._wD("Destroying "+c.soundIDs.length+" SMSound objects...");var b,a;for(b=c.soundIDs.length;b--;)c.sounds[c.soundIDs[b]].destruct();
+try{if(D)ua=i.innerHTML;S=i.parentNode.removeChild(i);c._wD("Flash movie removed.")}catch(d){o("badRemove",2)}ua=S=z=null;c.enabled=sa=n=ga=xa=P=Q=y=c.swfLoaded=!1;c.soundIDs=c.sounds=[];i=null;for(b in B)if(B.hasOwnProperty(b))for(a=B[b].length;a--;)B[b][a].fired=!1;c._wD("soundManager: Rebooting...");j.setTimeout(c.beginDelayedInit,20)};this.getMoviePercent=function(){return i&&"undefined"!==typeof i.PercentLoaded?i.PercentLoaded():null};this.beginDelayedInit=function(){Y=!0;J();setTimeout(function(){if(xa)return!1;
+ca();aa();return xa=!0},20);Z()};this.destruct=function(){c._wD("soundManager.destruct()");c.disable(!0)};Ea=function(b){var a=this,d,f,e,h,g,Ya,j=!1,x=[],l=0,n,r,p=null,t=null,u=null;this.sID=b.id;this.url=b.url;this._iO=this.instanceOptions=this.options=v(b);this.pan=this.options.pan;this.volume=this.options.volume;this.isHTML5=!1;this._a=null;this.id3={};this._debug=function(){if(c.debugMode){var b=null,e=[],d,f;for(b in a.options)null!==a.options[b]&&(a.options[b]instanceof Function?(d=a.options[b].toString(),
+d=d.replace(/\s\s+/g," "),f=d.indexOf("{"),e.push(" "+b+": {"+d.substr(f+1,Math.min(Math.max(d.indexOf("\n")-1,64),64)).replace(/\n/g,"")+"... }")):e.push(" "+b+": "+a.options[b]));c._wD("SMSound() merged options: {\n"+e.join(", \n")+"\n}")}};this._debug();this.load=function(b){var d=null;if("undefined"!==typeof b)a._iO=v(b,a.options),a.instanceOptions=a._iO;else if(b=a.options,a._iO=b,a.instanceOptions=a._iO,p&&p!==a.url)o("manURL"),a._iO.url=a.url,a.url=null;if(!a._iO.url)a._iO.url=a.url;a._iO.url=
+ia(a._iO.url);c._wD("SMSound.load(): "+a._iO.url,1);if(a._iO.url===a.url&&0!==a.readyState&&2!==a.readyState)return o("onURL",1),3===a.readyState&&a._iO.onload&&a._iO.onload.apply(a,[!!a.duration]),a;b=a._iO;p=a.url;a.loaded=!1;a.readyState=1;a.playState=0;if(ja(b))d=a._setup_html5(b),d._called_load?c._wD(k+"ignoring request to load again: "+a.sID):(c._wD(k+"load: "+a.sID),a._html5_canplay=!1,a._a.autobuffer="auto",a._a.preload="auto",d.load(),d._called_load=!0,b.autoPlay&&a.play());else try{a.isHTML5=
+!1,a._iO=fa(ea(b)),b=a._iO,8===m?i._load(a.sID,b.url,b.stream,b.autoPlay,b.whileloading?1:0,b.loops||1,b.usePolicyFile):i._load(a.sID,b.url,!!b.stream,!!b.autoPlay,b.loops||1,!!b.autoLoad,b.usePolicyFile)}catch(e){o("smError",2),w("onload",!1),K({type:"SMSOUND_LOAD_JS_EXCEPTION",fatal:!0})}return a};this.unload=function(){0!==a.readyState&&(c._wD('SMSound.unload(): "'+a.sID+'"'),a.isHTML5?(h(),a._a&&(a._a.pause(),ya(a._a))):8===m?i._unload(a.sID,"about:blank"):i._unload(a.sID),d());return a};this.destruct=
+function(b){c._wD('SMSound.destruct(): "'+a.sID+'"');if(a.isHTML5){if(h(),a._a)a._a.pause(),ya(a._a),F||e(),a._a._t=null,a._a=null}else a._iO.onfailure=null,i._destroySound(a.sID);b||c.destroySound(a.sID,!0)};this.start=this.play=function(b,d){var e,d=void 0===d?!0:d;b||(b={});a._iO=v(b,a._iO);a._iO=v(a._iO,a.options);a._iO.url=ia(a._iO.url);a.instanceOptions=a._iO;if(a._iO.serverURL&&!a.connected)return a.getAutoPlay()||(c._wD("SMSound.play(): Netstream not connected yet - setting autoPlay"),a.setAutoPlay(!0)),
+a;ja(a._iO)&&(a._setup_html5(a._iO),g());if(1===a.playState&&!a.paused)if(e=a._iO.multiShot)c._wD('SMSound.play(): "'+a.sID+'" already playing (multi-shot)',1);else return c._wD('SMSound.play(): "'+a.sID+'" already playing (one-shot)',1),a;if(a.loaded)c._wD('SMSound.play(): "'+a.sID+'"');else if(0===a.readyState){c._wD('SMSound.play(): Attempting to load "'+a.sID+'"',1);if(!a.isHTML5)a._iO.autoPlay=!0;a.load(a._iO)}else{if(2===a.readyState)return c._wD('SMSound.play(): Could not load "'+a.sID+'" - exiting',
+2),a;c._wD('SMSound.play(): "'+a.sID+'" is loading - attempting to play..',1)}if(!a.isHTML5&&9===m&&0<a.position&&a.position===a.duration)c._wD('SMSound.play(): "'+a.sID+'": Sound at end, resetting to position:0'),b.position=0;if(a.paused&&a.position&&0<a.position)c._wD('SMSound.play(): "'+a.sID+'" is resuming from paused state',1),a.resume();else{a._iO=v(b,a._iO);if(null!==a._iO.from&&null!==a._iO.to&&0===a.instanceCount&&0===a.playState&&!a._iO.serverURL){e=function(){a._iO=v(b,a._iO);a.play(a._iO)};
+if(a.isHTML5&&!a._html5_canplay)return c._wD('SMSound.play(): Beginning load of "'+a.sID+'" for from/to case'),a.load({_oncanplay:e}),!1;if(!a.isHTML5&&!a.loaded&&(!a.readyState||2!==a.readyState))return c._wD('SMSound.play(): Preloading "'+a.sID+'" for from/to case'),a.load({onload:e}),!1;a._iO=r()}c._wD('SMSound.play(): "'+a.sID+'" is starting to play');(!a.instanceCount||a._iO.multiShotEvents||!a.isHTML5&&8<m&&!a.getAutoPlay())&&a.instanceCount++;0===a.playState&&a._iO.onposition&&Ya(a);a.playState=
+1;a.paused=!1;a.position="undefined"!==typeof a._iO.position&&!isNaN(a._iO.position)?a._iO.position:0;if(!a.isHTML5)a._iO=fa(ea(a._iO));a._iO.onplay&&d&&(a._iO.onplay.apply(a),j=!0);a.setVolume(a._iO.volume,!0);a.setPan(a._iO.pan,!0);a.isHTML5?(g(),e=a._setup_html5(),a.setPosition(a._iO.position),e.play()):i._start(a.sID,a._iO.loops||1,9===m?a._iO.position:a._iO.position/1E3)}return a};this.stop=function(c){var b=a._iO;if(1===a.playState){a._onbufferchange(0);a._resetOnPosition(0);a.paused=!1;if(!a.isHTML5)a.playState=
+0;n();b.to&&a.clearOnPosition(b.to);if(a.isHTML5){if(a._a)c=a.position,a.setPosition(0),a.position=c,a._a.pause(),a.playState=0,a._onTimer(),h()}else i._stop(a.sID,c),b.serverURL&&a.unload();a.instanceCount=0;a._iO={};b.onstop&&b.onstop.apply(a)}return a};this.setAutoPlay=function(b){c._wD("sound "+a.sID+" turned autoplay "+(b?"on":"off"));a._iO.autoPlay=b;a.isHTML5||(i._setAutoPlay(a.sID,b),b&&!a.instanceCount&&1===a.readyState&&(a.instanceCount++,c._wD("sound "+a.sID+" incremented instance count to "+
+a.instanceCount)))};this.getAutoPlay=function(){return a._iO.autoPlay};this.setPosition=function(b){void 0===b&&(b=0);var d=a.isHTML5?Math.max(b,0):Math.min(a.duration||a._iO.duration,Math.max(b,0));a.position=d;b=a.position/1E3;a._resetOnPosition(a.position);a._iO.position=d;if(a.isHTML5){if(a._a)if(a._html5_canplay){if(a._a.currentTime!==b){c._wD("setPosition("+b+"): setting position");try{a._a.currentTime=b,(0===a.playState||a.paused)&&a._a.pause()}catch(e){c._wD("setPosition("+b+"): setting position failed: "+
+e.message,2)}}}else c._wD("setPosition("+b+"): delaying, sound not ready")}else b=9===m?a.position:b,a.readyState&&2!==a.readyState&&i._setPosition(a.sID,b,a.paused||!a.playState);a.isHTML5&&a.paused&&a._onTimer(!0);return a};this.pause=function(b){if(a.paused||0===a.playState&&1!==a.readyState)return a;c._wD("SMSound.pause()");a.paused=!0;a.isHTML5?(a._setup_html5().pause(),h()):(b||void 0===b)&&i._pause(a.sID);a._iO.onpause&&a._iO.onpause.apply(a);return a};this.resume=function(){var b=a._iO;if(!a.paused)return a;
+c._wD("SMSound.resume()");a.paused=!1;a.playState=1;a.isHTML5?(a._setup_html5().play(),g()):(b.isMovieStar&&!b.serverURL&&a.setPosition(a.position),i._pause(a.sID));j&&b.onplay?(b.onplay.apply(a),j=!0):b.onresume&&b.onresume.apply(a);return a};this.togglePause=function(){c._wD("SMSound.togglePause()");if(0===a.playState)return a.play({position:9===m&&!a.isHTML5?a.position:a.position/1E3}),a;a.paused?a.resume():a.pause();return a};this.setPan=function(b,c){"undefined"===typeof b&&(b=0);"undefined"===
+typeof c&&(c=!1);a.isHTML5||i._setPan(a.sID,b);a._iO.pan=b;if(!c)a.pan=b,a.options.pan=b;return a};this.setVolume=function(b,d){"undefined"===typeof b&&(b=100);"undefined"===typeof d&&(d=!1);if(a.isHTML5){if(a._a)a._a.volume=Math.max(0,Math.min(1,b/100))}else i._setVolume(a.sID,c.muted&&!a.muted||a.muted?0:b);a._iO.volume=b;if(!d)a.volume=b,a.options.volume=b;return a};this.mute=function(){a.muted=!0;if(a.isHTML5){if(a._a)a._a.muted=!0}else i._setVolume(a.sID,0);return a};this.unmute=function(){a.muted=
+!1;var b="undefined"!==typeof a._iO.volume;if(a.isHTML5){if(a._a)a._a.muted=!1}else i._setVolume(a.sID,b?a._iO.volume:a.options.volume);return a};this.toggleMute=function(){return a.muted?a.unmute():a.mute()};this.onposition=this.onPosition=function(b,c,d){x.push({position:b,method:c,scope:"undefined"!==typeof d?d:a,fired:!1});return a};this.clearOnPosition=function(a,b){var c,a=parseInt(a,10);if(isNaN(a))return!1;for(c=0;c<x.length;c++)if(a===x[c].position&&(!b||b===x[c].method))x[c].fired&&l--,
+x.splice(c,1)};this._processOnPosition=function(){var b,c;b=x.length;if(!b||!a.playState||l>=b)return!1;for(;b--;)if(c=x[b],!c.fired&&a.position>=c.position)c.fired=!0,l++,c.method.apply(c.scope,[c.position]);return!0};this._resetOnPosition=function(a){var b,c;b=x.length;if(!b)return!1;for(;b--;)if(c=x[b],c.fired&&a<=c.position)c.fired=!1,l--;return!0};r=function(){var b=a._iO,d=b.from,e=b.to,f,g;g=function(){c._wD(a.sID+': "to" time of '+e+" reached.");a.clearOnPosition(e,g);a.stop()};f=function(){c._wD(a.sID+
+': playing "from" '+d);if(null!==e&&!isNaN(e))a.onPosition(e,g)};if(null!==d&&!isNaN(d))b.position=d,b.multiShot=!1,f();return b};Ya=function(){var b=a._iO.onposition;if(b)for(var c in b)if(b.hasOwnProperty(c))a.onPosition(parseInt(c,10),b[c])};n=function(){var b=a._iO.onposition;if(b)for(var c in b)b.hasOwnProperty(c)&&a.clearOnPosition(parseInt(c,10))};g=function(){a.isHTML5&&Ka(a)};h=function(){a.isHTML5&&La(a)};d=function(){x=[];l=0;j=!1;a._hasTimer=null;a._a=null;a._html5_canplay=!1;a.bytesLoaded=
+null;a.bytesTotal=null;a.duration=a._iO&&a._iO.duration?a._iO.duration:null;a.durationEstimate=null;a.eqData=[];a.eqData.left=[];a.eqData.right=[];a.failures=0;a.isBuffering=!1;a.instanceOptions={};a.instanceCount=0;a.loaded=!1;a.metadata={};a.readyState=0;a.muted=!1;a.paused=!1;a.peakData={left:0,right:0};a.waveformData={left:[],right:[]};a.playState=0;a.position=null};d();this._onTimer=function(b){var c,d=!1,e={};if(a._hasTimer||b){if(a._a&&(b||(0<a.playState||1===a.readyState)&&!a.paused)){c=a._get_html5_duration();
+if(c!==t)t=c,a.duration=c,d=!0;a.durationEstimate=a.duration;c=1E3*a._a.currentTime||0;c!==u&&(u=c,d=!0);(d||b)&&a._whileplaying(c,e,e,e,e);return d}return!1}};this._get_html5_duration=function(){var b=a._iO,c=a._a?1E3*a._a.duration:b?b.duration:void 0;return c&&!isNaN(c)&&Infinity!==c?c:b?b.duration:null};this._setup_html5=function(b){var b=v(a._iO,b),e=decodeURI,g=F?c._global_a:a._a,h=e(b.url),i=g&&g._t?g._t.instanceOptions:null;if(g){if(g._t&&(!F&&h===e(p)||F&&i.url===b.url&&(!p||p===i.url)))return g;
+c._wD("setting new URL on existing object: "+h+(p?", old URL: "+p:""));F&&g._t&&g._t.playState&&b.url!==i.url&&g._t.stop();d();g.src=b.url;p=a.url=b.url;g._called_load=!1}else{c._wD("creating HTML5 Audio() element with URL: "+h);g=new Audio(b.url);g._called_load=!1;if(bb)g._called_load=!0;if(F)c._global_a=g}a.isHTML5=!0;a._a=g;g._t=a;f();g.loop=1<b.loops?"loop":"";b.autoLoad||b.autoPlay?a.load():(g.autobuffer=!1,g.preload="none");g.loop=1<b.loops?"loop":"";return g};f=function(){if(a._a._added_events)return!1;
+var b;c._wD(k+"adding event listeners: "+a.sID);a._a._added_events=!0;for(b in A)A.hasOwnProperty(b)&&a._a&&a._a.addEventListener(b,A[b],!1);return!0};e=function(){var b;c._wD(k+"removing event listeners: "+a.sID);a._a._added_events=!1;for(b in A)A.hasOwnProperty(b)&&a._a&&a._a.removeEventListener(b,A[b],!1)};this._onload=function(b){var d,b=!!b;c._wD(d+'"'+a.sID+'"'+(b?" loaded.":" failed to load? - "+a.url),b?1:2);d="SMSound._onload(): ";!b&&!a.isHTML5&&(!0===c.sandbox.noRemote&&c._wD(d+q("noNet"),
+1),!0===c.sandbox.noLocal&&c._wD(d+q("noLocal"),1));a.loaded=b;a.readyState=b?3:2;a._onbufferchange(0);a._iO.onload&&a._iO.onload.apply(a,[b]);return!0};this._onbufferchange=function(b){if(0===a.playState||b&&a.isBuffering||!b&&!a.isBuffering)return!1;a.isBuffering=1===b;a._iO.onbufferchange&&(c._wD("SMSound._onbufferchange(): "+b),a._iO.onbufferchange.apply(a));return!0};this._onsuspend=function(){a._iO.onsuspend&&(c._wD("SMSound._onsuspend()"),a._iO.onsuspend.apply(a));return!0};this._onfailure=
+function(b,d,e){a.failures++;c._wD('SMSound._onfailure(): "'+a.sID+'" count '+a.failures);if(a._iO.onfailure&&1===a.failures)a._iO.onfailure(a,b,d,e);else c._wD("SMSound._onfailure(): ignoring")};this._onfinish=function(){var b=a._iO.onfinish;a._onbufferchange(0);a._resetOnPosition(0);if(a.instanceCount){a.instanceCount--;if(!a.instanceCount)n(),a.playState=0,a.paused=!1,a.instanceCount=0,a.instanceOptions={},a._iO={},h();if((!a.instanceCount||a._iO.multiShotEvents)&&b)c._wD('SMSound._onfinish(): "'+
+a.sID+'"'),b.apply(a)}};this._whileloading=function(b,c,d,e){var f=a._iO;a.bytesLoaded=b;a.bytesTotal=c;a.duration=Math.floor(d);a.bufferLength=e;if(f.isMovieStar)a.durationEstimate=a.duration;else if(a.durationEstimate=f.duration?a.duration>f.duration?a.duration:f.duration:parseInt(a.bytesTotal/a.bytesLoaded*a.duration,10),void 0===a.durationEstimate)a.durationEstimate=a.duration;3!==a.readyState&&f.whileloading&&f.whileloading.apply(a)};this._whileplaying=function(b,c,d,e,f){var g=a._iO;if(isNaN(b)||
+null===b)return!1;a.position=b;a._processOnPosition();if(!a.isHTML5&&8<m){if(g.usePeakData&&"undefined"!==typeof c&&c)a.peakData={left:c.leftPeak,right:c.rightPeak};if(g.useWaveformData&&"undefined"!==typeof d&&d)a.waveformData={left:d.split(","),right:e.split(",")};if(g.useEQData&&"undefined"!==typeof f&&f&&f.leftEQ&&(b=f.leftEQ.split(","),a.eqData=b,a.eqData.left=b,"undefined"!==typeof f.rightEQ&&f.rightEQ))a.eqData.right=f.rightEQ.split(",")}1===a.playState&&(!a.isHTML5&&8===m&&!a.position&&a.isBuffering&&
+a._onbufferchange(0),g.whileplaying&&g.whileplaying.apply(a));return!0};this._onmetadata=function(b,d){c._wD('SMSound._onmetadata(): "'+this.sID+'" metadata received.');var e={},f,g;for(f=0,g=b.length;f<g;f++)e[b[f]]=d[f];a.metadata=e;a._iO.onmetadata&&a._iO.onmetadata.apply(a)};this._onid3=function(b,d){c._wD('SMSound._onid3(): "'+this.sID+'" ID3 data received.');var e=[],f,g;for(f=0,g=b.length;f<g;f++)e[b[f]]=d[f];a.id3=v(a.id3,e);a._iO.onid3&&a._iO.onid3.apply(a)};this._onconnect=function(b){b=
+1===b;c._wD('SMSound._onconnect(): "'+a.sID+'"'+(b?" connected.":" failed to connect? - "+a.url),b?1:2);if(a.connected=b)a.failures=0,s(a.sID)&&(a.getAutoPlay()?a.play(void 0,a.getAutoPlay()):a._iO.autoLoad&&a.load()),a._iO.onconnect&&a._iO.onconnect.apply(a,[b])};this._ondataerror=function(b){0<a.playState&&(c._wD("SMSound._ondataerror(): "+b),a._iO.ondataerror&&a._iO.ondataerror.apply(a))}};ba=function(){return h.body||h._docElement||h.getElementsByTagName("div")[0]};u=function(b){return h.getElementById(b)};
+v=function(b,a){var d={},f,e;for(f in b)b.hasOwnProperty(f)&&(d[f]=b[f]);f="undefined"===typeof a?c.defaultOptions:a;for(e in f)f.hasOwnProperty(e)&&"undefined"===typeof d[e]&&(d[e]=f[e]);return d};r=function(){function b(a){var a=Pa.call(a),b=a.length;c?(a[1]="on"+a[1],3<b&&a.pop()):3===b&&a.push(!1);return a}function a(a,b){var g=a.shift(),h=[f[b]];if(c)g[h](a[0],a[1]);else g[h].apply(g,a)}var c=j.attachEvent,f={add:c?"attachEvent":"addEventListener",remove:c?"detachEvent":"removeEventListener"};
+return{add:function(){a(b(arguments),"add")},remove:function(){a(b(arguments),"remove")}}}();A={abort:l(function(){c._wD(k+"abort: "+this._t.sID)}),canplay:l(function(){var b=this._t;if(b._html5_canplay)return!0;b._html5_canplay=!0;c._wD(k+"canplay: "+b.sID+", "+b.url);b._onbufferchange(0);var a=!isNaN(b.position)?b.position/1E3:null;if(b.position&&this.currentTime!==a){c._wD(k+"canplay: setting position to "+a);try{this.currentTime=a}catch(d){c._wD(k+"setting position failed: "+d.message,2)}}b._iO._oncanplay&&
+b._iO._oncanplay()}),load:l(function(){var b=this._t;b.loaded||(b._onbufferchange(0),b._whileloading(b.bytesTotal,b.bytesTotal,b._get_html5_duration()),b._onload(!0))}),emptied:l(function(){c._wD(k+"emptied: "+this._t.sID)}),ended:l(function(){var b=this._t;c._wD(k+"ended: "+b.sID);b._onfinish()}),error:l(function(){c._wD(k+"error: "+this.error.code);this._t._onload(!1)}),loadeddata:l(function(){var b=this._t,a=b.bytesTotal||1;c._wD(k+"loadeddata: "+this._t.sID);if(!b._loaded&&!V)b.duration=b._get_html5_duration(),
+b._whileloading(a,a,b._get_html5_duration()),b._onload(!0)}),loadedmetadata:l(function(){c._wD(k+"loadedmetadata: "+this._t.sID)}),loadstart:l(function(){c._wD(k+"loadstart: "+this._t.sID);this._t._onbufferchange(1)}),play:l(function(){c._wD(k+"play: "+this._t.sID+", "+this._t.url);this._t._onbufferchange(0)}),playing:l(function(){c._wD(k+"playing: "+this._t.sID);this._t._onbufferchange(0)}),progress:l(function(b){var a=this._t;if(a.loaded)return!1;var d,f,e;e=0;var h="progress"===b.type;f=b.target.buffered;
+var g=b.loaded||0,i=b.total||1;if(f&&f.length){for(d=f.length;d--;)e=f.end(d)-f.start(d);g=e/b.target.duration;if(h&&1<f.length){e=[];f=f.length;for(d=0;d<f;d++)e.push(b.target.buffered.start(d)+"-"+b.target.buffered.end(d));c._wD(k+"progress: timeRanges: "+e.join(", "))}h&&!isNaN(g)&&c._wD(k+"progress: "+a.sID+": "+Math.floor(100*g)+"% loaded")}isNaN(g)||(a._onbufferchange(0),a._whileloading(g,i,a._get_html5_duration()),g&&i&&g===i&&A.load.call(this,b))}),ratechange:l(function(){c._wD(k+"ratechange: "+
+this._t.sID)}),suspend:l(function(b){var a=this._t;c._wD(k+"suspend: "+a.sID);A.progress.call(this,b);a._onsuspend()}),stalled:l(function(){c._wD(k+"stalled: "+this._t.sID)}),timeupdate:l(function(){this._t._onTimer()}),waiting:l(function(){var b=this._t;c._wD(k+"waiting: "+b.sID);b._onbufferchange(1)})};ja=function(b){return!b.serverURL&&(b.type?U({type:b.type}):U({url:b.url})||c.html5Only)};ya=function(b){if(b)b.src=ab?"":"about:blank"};U=function(b){function a(a){return c.preferFlash&&t&&!c.ignoreFlash&&
+"undefined"!==typeof c.flash[a]&&c.flash[a]}if(!c.useHTML5Audio||!c.hasHTML5)return!1;var d=b.url||null,b=b.type||null,f=c.audioFormats,e;if(b&&"undefined"!==c.html5[b])return c.html5[b]&&!a(b);if(!C){C=[];for(e in f)f.hasOwnProperty(e)&&(C.push(e),f[e].related&&(C=C.concat(f[e].related)));C=RegExp("\\.("+C.join("|")+")(\\?.*)?$","i")}e=d?d.toLowerCase().match(C):null;if(!e||!e.length)if(b)d=b.indexOf(";"),e=(-1!==d?b.substr(0,d):b).substr(6);else return!1;else e=e[1];if(e&&"undefined"!==typeof c.html5[e])return c.html5[e]&&
+!a(e);b="audio/"+e;d=c.html5.canPlayType({type:b});return(c.html5[e]=d)&&c.html5[b]&&!a(b)};Oa=function(){function b(b){var d,e,f=!1;if(!a||"function"!==typeof a.canPlayType)return!1;if(b instanceof Array){for(d=0,e=b.length;d<e&&!f;d++)if(c.html5[b[d]]||a.canPlayType(b[d]).match(c.html5Test))f=!0,c.html5[b[d]]=!0,c.flash[b[d]]=!(!c.preferFlash||!t||!b[d].match(Ua));return f}b=a&&"function"===typeof a.canPlayType?a.canPlayType(b):!1;return!(!b||!b.match(c.html5Test))}if(!c.useHTML5Audio||"undefined"===
+typeof Audio)return!1;var a="undefined"!==typeof Audio?db?new Audio(null):new Audio:null,d,f={},e,h;e=c.audioFormats;for(d in e)if(e.hasOwnProperty(d)&&(f[d]=b(e[d].type),f["audio/"+d]=f[d],c.flash[d]=c.preferFlash&&!c.ignoreFlash&&d.match(Ua)?!0:!1,e[d]&&e[d].related))for(h=e[d].related.length;h--;)f["audio/"+e[d].related[h]]=f[d],c.html5[e[d].related[h]]=f[d],c.flash[e[d].related[h]]=f[d];f.canPlayType=a?b:null;c.html5=v(c.html5,f);return!0};$={notReady:"Not loaded yet - wait for soundManager.onload()/onready()",
+notOK:"Audio support is not available.",domError:"soundManager::createMovie(): appendChild/innerHTML call failed. DOM not ready or other error.",spcWmode:"soundManager::createMovie(): Removing wmode, preventing known SWF loading issue(s)",swf404:"soundManager: Verify that %s is a valid path.",tryDebug:"Try soundManager.debugFlash = true for more security details (output goes to SWF.)",checkSWF:"See SWF output for more debug info.",localFail:"soundManager: Non-HTTP page ("+h.location.protocol+" URL?) Review Flash player security settings for this special case:\nhttp://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html\nMay need to add/allow path, eg. c:/sm2/ or /users/me/sm2/",
+waitFocus:"soundManager: Special case: Waiting for focus-related event..",waitImpatient:"soundManager: Getting impatient, still waiting for Flash%s...",waitForever:"soundManager: Waiting indefinitely for Flash (will recover if unblocked)...",needFunction:"soundManager: Function object expected for %s",badID:'Warning: Sound ID "%s" should be a string, starting with a non-numeric character',currentObj:"--- soundManager._debug(): Current sound objects ---",waitEI:"soundManager::initMovie(): Waiting for ExternalInterface call from Flash..",
+waitOnload:"soundManager: Waiting for window.onload()",docLoaded:"soundManager: Document already loaded",onload:"soundManager::initComplete(): calling soundManager.onload()",onloadOK:"soundManager.onload() complete",init:"soundManager::init()",didInit:"soundManager::init(): Already called?",flashJS:"soundManager: Attempting to call Flash from JS..",secNote:"Flash security note: Network/internet URLs will not load due to security restrictions. Access can be configured via Flash Player Global Security Settings Page: http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html",
+badRemove:"Warning: Failed to remove flash movie.",noPeak:"Warning: peakData features unsupported for movieStar formats",shutdown:"soundManager.disable(): Shutting down",queue:"soundManager: Queueing %s handler",smFail:"soundManager: Failed to initialise.",smError:"SMSound.load(): Exception: JS-Flash communication failed, or JS error.",fbTimeout:"No flash response, applying .swf_timedout CSS..",fbLoaded:"Flash loaded",fbHandler:"soundManager::flashBlockHandler()",manURL:"SMSound.load(): Using manually-assigned URL",
+onURL:"soundManager.load(): current URL already assigned.",badFV:'soundManager.flashVersion must be 8 or 9. "%s" is invalid. Reverting to %s.',as2loop:"Note: Setting stream:false so looping can work (flash 8 limitation)",noNSLoop:"Note: Looping not implemented for MovieStar formats",needfl9:"Note: Switching to flash 9, required for MP4 formats.",mfTimeout:"Setting flashLoadTimeout = 0 (infinite) for off-screen, mobile flash case",mfOn:"mobileFlash::enabling on-screen flash repositioning",policy:"Enabling usePolicyFile for data access"};
+q=function(){var b=Pa.call(arguments),a=b.shift(),a=$&&$[a]?$[a]:"",c,f;if(a&&b&&b.length)for(c=0,f=b.length;c<f;c++)a=a.replace("%s",b[c]);return a};ea=function(b){if(8===m&&1<b.loops&&b.stream)o("as2loop"),b.stream=!1;return b};fa=function(b,a){if(b&&!b.usePolicyFile&&(b.onid3||b.usePeakData||b.useWaveformData||b.useEQData))c._wD((a||"")+q("policy")),b.usePolicyFile=!0;return b};wa=function(b){"undefined"!==typeof console&&"undefined"!==typeof console.warn?console.warn(b):c._wD(b)};na=function(){return!1};
+Ha=function(b){for(var a in b)b.hasOwnProperty(a)&&"function"===typeof b[a]&&(b[a]=na)};da=function(b){"undefined"===typeof b&&(b=!1);if(y||b)o("smFail",2),c.disable(b)};Ia=function(b){var a=null;if(b)if(b.match(/\.swf(\?.*)?$/i)){if(a=b.substr(b.toLowerCase().lastIndexOf(".swf?")+4))return b}else b.lastIndexOf("/")!==b.length-1&&(b+="/");b=(b&&-1!==b.lastIndexOf("/")?b.substr(0,b.lastIndexOf("/")+1):"./")+c.movieURL;c.noSWFCache&&(b+="?ts="+(new Date).getTime());return b};qa=function(){m=parseInt(c.flashVersion,
+10);if(8!==m&&9!==m)c._wD(q("badFV",m,8)),c.flashVersion=m=8;var b=c.debugMode||c.debugFlash?"_debug.swf":".swf";if(c.useHTML5Audio&&!c.html5Only&&c.audioFormats.mp4.required&&9>m)c._wD(q("needfl9")),c.flashVersion=m=9;c.version=c.versionNumber+(c.html5Only?" (HTML5-only mode)":9===m?" (AS3/Flash 9)":" (AS2/Flash 8)");8<m?(c.defaultOptions=v(c.defaultOptions,c.flash9Options),c.features.buffering=!0,c.defaultOptions=v(c.defaultOptions,c.movieStarOptions),c.filePatterns.flash9=RegExp("\\.(mp3|"+Xa.join("|")+
+")(\\?.*)?$","i"),c.features.movieStar=!0):c.features.movieStar=!1;c.filePattern=c.filePatterns[8!==m?"flash9":"flash8"];c.movieURL=(8===m?"soundmanager2.swf":"soundmanager2_flash9.swf").replace(".swf",b);c.features.peakData=c.features.waveformData=c.features.eqData=8<m};Ga=function(b,a){if(!i)return!1;i._setPolling(b,a)};ta=function(){if(c.debugURLParam.test(O))c.debugMode=!0;if(u(c.debugID))return!1;var b,a,d,f;if(c.debugMode&&!u(c.debugID)&&(!Sa||!c.useConsole||!c.consoleOnly)){b=h.createElement("div");
+b.id=c.debugID+"-toggle";a={position:"fixed",bottom:"0px",right:"0px",width:"1.2em",height:"1.2em",lineHeight:"1.2em",margin:"2px",textAlign:"center",border:"1px solid #999",cursor:"pointer",background:"#fff",color:"#333",zIndex:10001};b.appendChild(h.createTextNode("-"));b.onclick=Ja;b.title="Toggle SM2 debug console";if(p.match(/msie 6/i))b.style.position="absolute",b.style.cursor="hand";for(f in a)a.hasOwnProperty(f)&&(b.style[f]=a[f]);a=h.createElement("div");a.id=c.debugID;a.style.display=c.debugMode?
+"block":"none";if(c.debugMode&&!u(b.id)){try{d=ba(),d.appendChild(b)}catch(e){throw Error(q("domError")+" \n"+e.toString());}d.appendChild(a)}}};s=this.getSoundById;o=function(b,a){return b?c._wD(q(b),a):""};if(O.indexOf("sm2-debug=alert")+1&&c.debugMode)c._wD=function(b){G.alert(b)};Ja=function(){var b=u(c.debugID),a=u(c.debugID+"-toggle");if(!b)return!1;oa?(a.innerHTML="+",b.style.display="none"):(a.innerHTML="-",b.style.display="block");oa=!oa};w=function(b,a,c){if("undefined"!==typeof sm2Debugger)try{sm2Debugger.handleEvent(b,
+a,c)}catch(f){}return!0};L=function(){var b=[];c.debugMode&&b.push("sm2_debug");c.debugFlash&&b.push("flash_debug");c.useHighPerformance&&b.push("high_performance");return b.join(" ")};va=function(){var b=q("fbHandler"),a=c.getMoviePercent(),d={type:"FLASHBLOCK"};if(c.html5Only)return!1;if(c.ok()){if(c.didFlashBlock&&c._wD(b+": Unblocked"),c.oMC)c.oMC.className=[L(),"movieContainer","swf_loaded"+(c.didFlashBlock?" swf_unblocked":"")].join(" ")}else{if(z)c.oMC.className=L()+" movieContainer "+(null===
+a?"swf_timedout":"swf_error"),c._wD(b+": "+q("fbTimeout")+(a?" ("+q("fbLoaded")+")":""));c.didFlashBlock=!0;H({type:"ontimeout",ignoreInit:!0,error:d});K(d)}};pa=function(b,a,c){"undefined"===typeof B[b]&&(B[b]=[]);B[b].push({method:a,scope:c||null,fired:!1})};H=function(b){b||(b={type:"onready"});if(!n&&b&&!b.ignoreInit||"ontimeout"===b.type&&c.ok())return!1;var a={success:b&&b.ignoreInit?c.ok():!y},d=b&&b.type?B[b.type]||[]:[],f=[],e,h=[a],g=z&&c.useFlashBlock&&!c.ok();if(b.error)h[0].error=b.error;
+for(a=0,e=d.length;a<e;a++)!0!==d[a].fired&&f.push(d[a]);if(f.length){c._wD("soundManager: Firing "+f.length+" "+b.type+"() item"+(1===f.length?"":"s"));for(a=0,e=f.length;a<e;a++)if(f[a].scope?f[a].method.apply(f[a].scope,h):f[a].method.apply(this,h),!g)f[a].fired=!0}return!0};I=function(){j.setTimeout(function(){c.useFlashBlock&&va();H();c.onload instanceof Function&&(o("onload",1),c.onload.apply(j),o("onloadOK",1));c.waitForWindowLoad&&r.add(j,"load",I)},1)};ka=function(){if(void 0!==t)return t;
+var b=!1,a=navigator,c=a.plugins,f,e=j.ActiveXObject;if(c&&c.length)(a=a.mimeTypes)&&a["application/x-shockwave-flash"]&&a["application/x-shockwave-flash"].enabledPlugin&&a["application/x-shockwave-flash"].enabledPlugin.description&&(b=!0);else if("undefined"!==typeof e){try{f=new e("ShockwaveFlash.ShockwaveFlash")}catch(h){}b=!!f}return t=b};Na=function(){var b,a;if(Aa&&p.match(/os (1|2|3_0|3_1)/i)){c.hasHTML5=!1;c.html5Only=!0;if(c.oMC)c.oMC.style.display="none";return!1}if(c.useHTML5Audio){if(!c.html5||
+!c.html5.canPlayType)return c._wD("SoundManager: No HTML5 Audio() support detected."),c.hasHTML5=!1,!0;c.hasHTML5=!0;if(Ca&&(c._wD("soundManager::Note: Buggy HTML5 Audio in Safari on this OS X release, see https://bugs.webkit.org/show_bug.cgi?id=32159 - "+(!t?" would use flash fallback for MP3/MP4, but none detected.":"will use flash fallback for MP3/MP4, if available"),1),ka()))return!0}else return!0;for(a in c.audioFormats)if(c.audioFormats.hasOwnProperty(a)&&(c.audioFormats[a].required&&!c.html5.canPlayType(c.audioFormats[a].type)||
+c.flash[a]||c.flash[c.audioFormats[a].type]))b=!0;c.ignoreFlash&&(b=!1);c.html5Only=c.hasHTML5&&c.useHTML5Audio&&!b;return!c.html5Only};ia=function(b){var a,d,f=0;if(b instanceof Array){for(a=0,d=b.length;a<d;a++)if(b[a]instanceof Object){if(c.canPlayMIME(b[a].type)){f=a;break}}else if(c.canPlayURL(b[a])){f=a;break}if(b[f].url)b[f]=b[f].url;return b[f]}return b};Ka=function(b){if(!b._hasTimer)b._hasTimer=!0,!Ba&&c.html5PollingInterval&&(null===T&&0===ha&&(T=G.setInterval(Ma,c.html5PollingInterval)),
+ha++)};La=function(b){if(b._hasTimer)b._hasTimer=!1,!Ba&&c.html5PollingInterval&&ha--};Ma=function(){var b;if(null!==T&&!ha)return G.clearInterval(T),T=null,!1;for(b=c.soundIDs.length;b--;)c.sounds[c.soundIDs[b]].isHTML5&&c.sounds[c.soundIDs[b]]._hasTimer&&c.sounds[c.soundIDs[b]]._onTimer()};K=function(b){b="undefined"!==typeof b?b:{};c.onerror instanceof Function&&c.onerror.apply(j,[{type:"undefined"!==typeof b.type?b.type:null}]);"undefined"!==typeof b.fatal&&b.fatal&&c.disable()};Qa=function(){if(!Ca||
+!ka())return!1;var b=c.audioFormats,a,d;for(d in b)if(b.hasOwnProperty(d)&&("mp3"===d||"mp4"===d))if(c._wD("soundManager: Using flash fallback for "+d+" format"),c.html5[d]=!1,b[d]&&b[d].related)for(a=b[d].related.length;a--;)c.html5[b[d].related[a]]=!1};this._setSandboxType=function(b){var a=c.sandbox;a.type=b;a.description=a.types["undefined"!==typeof a.types[b]?b:"unknown"];c._wD("Flash security sandbox type: "+a.type);if("localWithFile"===a.type)a.noRemote=!0,a.noLocal=!1,o("secNote",2);else if("localWithNetwork"===
+a.type)a.noRemote=!1,a.noLocal=!0;else if("localTrusted"===a.type)a.noRemote=!1,a.noLocal=!1};this._externalInterfaceOK=function(b,a){if(c.swfLoaded)return!1;var d,f=(new Date).getTime();c._wD("soundManager::externalInterfaceOK()"+(b?" (~"+(f-b)+" ms)":""));w("swf",!0);w("flashtojs",!0);c.swfLoaded=!0;M=!1;Ca&&Qa();if(!a||a.replace(/\+dev/i,"")!==c.versionNumber.replace(/\+dev/i,""))return d='soundManager: Fatal: JavaScript file build "'+c.versionNumber+'" does not match Flash SWF build "'+a+'" at '+
+c.url+". Ensure both are up-to-date.",setTimeout(function(){throw Error(d);},0),!1;D?setTimeout(X,100):X()};ca=function(b,a){function d(){c._wD("-- SoundManager 2 "+c.version+(!c.html5Only&&c.useHTML5Audio?c.hasHTML5?" + HTML5 audio":", no HTML5 audio support":"")+(!c.html5Only?(c.useHighPerformance?", high performance mode, ":", ")+((c.flashPollingInterval?"custom ("+c.flashPollingInterval+"ms)":"normal")+" polling")+(c.wmode?", wmode: "+c.wmode:"")+(c.debugFlash?", flash debug mode":"")+(c.useFlashBlock?
+", flashBlock mode":""):"")+" --",1)}function f(a,b){return'<param name="'+a+'" value="'+b+'" />'}if(P&&Q)return!1;if(c.html5Only)return qa(),d(),c.oMC=u(c.movieID),X(),Q=P=!0,!1;var e=a||c.url,i=c.altURL||e,g;g=ba();var j,m,k=L(),l,n=null,n=(n=h.getElementsByTagName("html")[0])&&n.dir&&n.dir.match(/rtl/i),b="undefined"===typeof b?c.id:b;qa();c.url=Ia(N?e:i);a=c.url;c.wmode=!c.wmode&&c.useHighPerformance?"transparent":c.wmode;if(null!==c.wmode&&(p.match(/msie 8/i)||!D&&!c.useHighPerformance)&&navigator.platform.match(/win32|win64/i))o("spcWmode"),
+c.wmode=null;g={name:b,id:b,src:a,width:"auto",height:"auto",quality:"high",allowScriptAccess:c.allowScriptAccess,bgcolor:c.bgColor,pluginspage:Va+"www.macromedia.com/go/getflashplayer",title:"JS/Flash audio component (SoundManager 2)",type:"application/x-shockwave-flash",wmode:c.wmode,hasPriority:"true"};if(c.debugFlash)g.FlashVars="debug=1";c.wmode||delete g.wmode;if(D)e=h.createElement("div"),m=['<object id="'+b+'" data="'+a+'" type="'+g.type+'" title="'+g.title+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="'+
+Va+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="'+g.width+'" height="'+g.height+'">',f("movie",a),f("AllowScriptAccess",c.allowScriptAccess),f("quality",g.quality),c.wmode?f("wmode",c.wmode):"",f("bgcolor",c.bgColor),f("hasPriority","true"),c.debugFlash?f("FlashVars",g.FlashVars):"","</object>"].join("");else for(j in e=h.createElement("embed"),g)g.hasOwnProperty(j)&&e.setAttribute(j,g[j]);ta();k=L();if(g=ba())if(c.oMC=u(c.movieID)||h.createElement("div"),
+c.oMC.id){l=c.oMC.className;c.oMC.className=(l?l+" ":"movieContainer")+(k?" "+k:"");c.oMC.appendChild(e);if(D)j=c.oMC.appendChild(h.createElement("div")),j.className="sm2-object-box",j.innerHTML=m;Q=!0}else{c.oMC.id=c.movieID;c.oMC.className="movieContainer "+k;j=k=null;if(!c.useFlashBlock)if(c.useHighPerformance)k={position:"fixed",width:"8px",height:"8px",bottom:"0px",left:"0px",overflow:"hidden"};else if(k={position:"absolute",width:"6px",height:"6px",top:"-9999px",left:"-9999px"},n)k.left=Math.abs(parseInt(k.left,
+10))+"px";if(cb)c.oMC.style.zIndex=1E4;if(!c.debugFlash)for(l in k)k.hasOwnProperty(l)&&(c.oMC.style[l]=k[l]);try{D||c.oMC.appendChild(e);g.appendChild(c.oMC);if(D)j=c.oMC.appendChild(h.createElement("div")),j.className="sm2-object-box",j.innerHTML=m;Q=!0}catch(r){throw Error(q("domError")+" \n"+r.toString());}}P=!0;d();c._wD("soundManager::createMovie(): Trying to load "+a+(!N&&c.altURL?" (alternate URL)":""),1);return!0};aa=function(){if(c.html5Only)return ca(),!1;if(i)return!1;i=c.getMovie(c.id);
+if(!i)S?(D?c.oMC.innerHTML=ua:c.oMC.appendChild(S),S=null,P=!0):ca(c.id,c.url),i=c.getMovie(c.id);i&&o("waitEI");c.oninitmovie instanceof Function&&setTimeout(c.oninitmovie,1);return!0};Z=function(){setTimeout(Fa,1E3)};Fa=function(){if(ga)return!1;ga=!0;r.remove(j,"load",Z);if(M&&!Da)return o("waitFocus"),!1;var b;n||(b=c.getMoviePercent(),c._wD(q("waitImpatient",100===b?" (SWF loaded)":0<b?" (SWF "+b+"% loaded)":"")));setTimeout(function(){b=c.getMoviePercent();n||(c._wD("soundManager: No Flash response within expected time.\nLikely causes: "+
+(0===b?"Loading "+c.movieURL+" may have failed (and/or Flash "+m+"+ not present?), ":"")+"Flash blocked or JS-Flash security error."+(c.debugFlash?" "+q("checkSWF"):""),2),!N&&b&&(o("localFail",2),c.debugFlash||o("tryDebug",2)),0===b&&c._wD(q("swf404",c.url)),w("flashtojs",!1,": Timed out"+N?" (Check flash security or flash blockers)":" (No plugin/missing SWF?)"));!n&&Ta&&(null===b?c.useFlashBlock||0===c.flashLoadTimeout?(c.useFlashBlock&&va(),o("waitForever")):da(!0):0===c.flashLoadTimeout?o("waitForever"):
+da(!0))},c.flashLoadTimeout)};E=function(){function b(){r.remove(j,"focus",E);r.remove(j,"load",E)}if(Da||!M)return b(),!0;Da=Ta=!0;c._wD("soundManager::handleFocus()");V&&M&&r.remove(j,"mousemove",E);ga=!1;b();return!0};Ra=function(){var b,a=[];if(c.useHTML5Audio&&c.hasHTML5){for(b in c.audioFormats)c.audioFormats.hasOwnProperty(b)&&a.push(b+": "+c.html5[b]+(!c.html5[b]&&t&&c.flash[b]?" (using flash)":c.preferFlash&&c.flash[b]&&t?" (preferring flash)":!c.html5[b]?" ("+(c.audioFormats[b].required?
+"required, ":"")+"and no flash support)":""));c._wD("-- SoundManager 2: HTML5 support tests ("+c.html5Test+"): "+a.join(", ")+" --",1)}};R=function(b){if(n)return!1;if(c.html5Only)return c._wD("-- SoundManager 2: loaded --"),n=!0,I(),w("onload",!0),!0;var a;if(!c.useFlashBlock||!c.flashLoadTimeout||c.getMoviePercent())n=!0,y&&(a={type:!t&&z?"NO_FLASH":"INIT_TIMEOUT"});c._wD("-- SoundManager 2 "+(y?"failed to load":"loaded")+" ("+(y?"security/load error":"OK")+") --",1);if(y||b){if(c.useFlashBlock&&
+c.oMC)c.oMC.className=L()+" "+(null===c.getMoviePercent()?"swf_timedout":"swf_error");H({type:"ontimeout",error:a});w("onload",!1);K(a);return!1}w("onload",!0);if(c.waitForWindowLoad&&!Y)return o("waitOnload"),r.add(j,"load",I),!1;c.waitForWindowLoad&&Y&&o("docLoaded");I();return!0};X=function(){o("init");if(n)return o("didInit"),!1;if(c.html5Only){if(!n)r.remove(j,"load",c.beginDelayedInit),c.enabled=!0,R();return!0}aa();try{o("flashJS"),i._externalInterfaceTest(!1),Ga(!0,c.flashPollingInterval||
+(c.useHighPerformance?10:50)),c.debugMode||i._disableDebug(),c.enabled=!0,w("jstoflash",!0),c.html5Only||r.add(j,"unload",na)}catch(b){return c._wD("js/flash exception: "+b.toString()),w("jstoflash",!1),K({type:"JS_TO_FLASH_EXCEPTION",fatal:!0}),da(!0),R(),!1}R();r.remove(j,"load",c.beginDelayedInit);return!0};J=function(){if(sa)return!1;sa=!0;ta();var b=O.toLowerCase(),a=null,a=null,d="undefined"!==typeof console&&"undefined"!==typeof console.log;if(-1!==b.indexOf("sm2-usehtml5audio="))a="1"===b.charAt(b.indexOf("sm2-usehtml5audio=")+
+18),d&&console.log((a?"Enabling ":"Disabling ")+"useHTML5Audio via URL parameter"),c.useHTML5Audio=a;if(-1!==b.indexOf("sm2-preferflash="))a="1"===b.charAt(b.indexOf("sm2-preferflash=")+16),d&&console.log((a?"Enabling ":"Disabling ")+"preferFlash via URL parameter"),c.preferFlash=a;if(!t&&c.hasHTML5)c._wD("SoundManager: No Flash detected"+(!c.useHTML5Audio?", enabling HTML5.":". Trying HTML5-only mode.")),c.useHTML5Audio=!0,c.preferFlash=!1;Oa();c.html5.usingFlash=Na();z=c.html5.usingFlash;Ra();if(!t&&
+z)c._wD("SoundManager: Fatal error: Flash is needed to play some required formats, but is not available."),c.flashLoadTimeout=1;h.removeEventListener&&h.removeEventListener("DOMContentLoaded",J,!1);aa();return!0};za=function(){"complete"===h.readyState&&(J(),h.detachEvent("onreadystatechange",za));return!0};ra=function(){Y=!0;r.remove(j,"load",ra)};ka();r.add(j,"focus",E);r.add(j,"load",E);r.add(j,"load",Z);r.add(j,"load",ra);V&&M&&r.add(j,"mousemove",E);h.addEventListener?h.addEventListener("DOMContentLoaded",
+J,!1):h.attachEvent?h.attachEvent("onreadystatechange",za):(w("onload",!1),K({type:"NO_DOM2_EVENTS",fatal:!0}));"complete"===h.readyState&&setTimeout(J,100)}var la=null;if("undefined"===typeof SM2_DEFER||!SM2_DEFER)la=new W;G.SoundManager=W;G.soundManager=la})(window); \ No newline at end of file
diff --git a/Processing-js/libs/inc/SoundManager2/script/soundmanager2-nodebug-jsmin.js b/Processing-js/libs/inc/SoundManager2/script/soundmanager2-nodebug-jsmin.js
new file mode 100755
index 0000000..f829d2c
--- /dev/null
+++ b/Processing-js/libs/inc/SoundManager2/script/soundmanager2-nodebug-jsmin.js
@@ -0,0 +1,77 @@
+/** @license
+ *
+ * SoundManager 2: JavaScript Sound for the Web
+ * ----------------------------------------------
+ * http://schillmania.com/projects/soundmanager2/
+ *
+ * Copyright (c) 2007, Scott Schiller. All rights reserved.
+ * Code provided under the BSD License:
+ * http://schillmania.com/projects/soundmanager2/license.txt
+ *
+ * V2.97a.20111220
+ */
+(function(J){function R(R,ea){function l(b){return function(a){var c=this._t;return!c||!c._a?null:b.call(this,a)}}this.flashVersion=8;this.debugFlash=this.debugMode=!1;this.consoleOnly=this.useConsole=!0;this.waitForWindowLoad=!1;this.bgColor="#ffffff";this.useHighPerformance=!1;this.html5PollingInterval=this.flashPollingInterval=null;this.flashLoadTimeout=1E3;this.wmode=null;this.allowScriptAccess="always";this.useFlashBlock=!1;this.useHTML5Audio=!0;this.html5Test=/^(probably|maybe)$/i;this.preferFlash=
+!0;this.noSWFCache=!1;this.audioFormats={mp3:{type:['audio/mpeg; codecs="mp3"',"audio/mpeg","audio/mp3","audio/MPA","audio/mpa-robust"],required:!0},mp4:{related:["aac","m4a"],type:['audio/mp4; codecs="mp4a.40.2"',"audio/aac","audio/x-m4a","audio/MP4A-LATM","audio/mpeg4-generic"],required:!1},ogg:{type:["audio/ogg; codecs=vorbis"],required:!1},wav:{type:['audio/wav; codecs="1"',"audio/wav","audio/wave","audio/x-wav"],required:!1}};this.defaultOptions={autoLoad:!1,autoPlay:!1,from:null,loops:1,onid3:null,
+onload:null,whileloading:null,onplay:null,onpause:null,onresume:null,whileplaying:null,onposition:null,onstop:null,onfailure:null,onfinish:null,multiShot:!0,multiShotEvents:!1,position:null,pan:0,stream:!0,to:null,type:null,usePolicyFile:!1,volume:100};this.flash9Options={isMovieStar:null,usePeakData:!1,useWaveformData:!1,useEQData:!1,onbufferchange:null,ondataerror:null};this.movieStarOptions={bufferTime:3,serverURL:null,onconnect:null,duration:null};this.movieID="sm2-container";this.id=ea||"sm2movie";
+this.debugID="soundmanager-debug";this.debugURLParam=/([#?&])debug=1/i;this.versionNumber="V2.97a.20111220";this.movieURL=this.version=null;this.url=R||null;this.altURL=null;this.enabled=this.swfLoaded=!1;this.oMC=null;this.sounds={};this.soundIDs=[];this.didFlashBlock=this.muted=!1;this.filePattern=null;this.filePatterns={flash8:/\.mp3(\?.*)?$/i,flash9:/\.mp3(\?.*)?$/i};this.features={buffering:!1,peakData:!1,waveformData:!1,eqData:!1,movieStar:!1};this.sandbox={};var fa;try{fa="undefined"!==typeof Audio&&
+"undefined"!==typeof(new Audio).canPlayType}catch(Xa){fa=!1}this.hasHTML5=fa;this.html5={usingFlash:null};this.flash={};this.ignoreFlash=this.html5Only=!1;var Aa,c=this,h=null,S,p=navigator.userAgent,j=J,ga=j.location.href.toString(),k=document,ha,T,i,v=[],K=!1,L=!1,m=!1,w=!1,ia=!1,M,q,ja,C,D,U,Ba,ka,A,V,E,la,ma,na,W,F,Ca,oa,Da,X,Ea,N=null,pa=null,G,qa,H,Y,Z,ra,o,$=!1,sa=!1,Fa,Ga,Ha,aa=0,O=null,ba,s=null,Ia,ca,P,x,ta,ua,Ja,n,Ra=Array.prototype.slice,B=!1,r,da,Ka,u,La,va=p.match(/(ipad|iphone|ipod)/i),
+Sa=p.match(/firefox/i),Ta=p.match(/droid/i),y=p.match(/msie/i),Ua=p.match(/webkit/i),Q=p.match(/safari/i)&&!p.match(/chrome/i),Va=p.match(/opera/i),wa=p.match(/(mobile|pre\/|xoom)/i)||va,xa=!ga.match(/usehtml5audio/i)&&!ga.match(/sm2\-ignorebadua/i)&&Q&&!p.match(/silk/i)&&p.match(/OS X 10_6_([3-7])/i),ya="undefined"!==typeof k.hasFocus?k.hasFocus():null,I=Q&&"undefined"===typeof k.hasFocus,Ma=!I,Na=/(mp3|mp4|mpa)/i,za=k.location?k.location.protocol.match(/http/i):null,Oa=!za?"http://":"",Pa=/^\s*audio\/(?:x-)?(?:mpeg4|aac|flv|mov|mp4||m4v|m4a|mp4v|3gp|3g2)\s*(?:$|;)/i,
+Qa="mpeg4,aac,flv,mov,mp4,m4v,f4v,m4a,mp4v,3gp,3g2".split(","),Wa=RegExp("\\.("+Qa.join("|")+")(\\?.*)?$","i");this.mimePattern=/^\s*audio\/(?:x-)?(?:mp(?:eg|3))\s*(?:$|;)/i;this.useAltURL=!za;this._global_a=null;if(wa&&(c.useHTML5Audio=!0,c.preferFlash=!1,va))B=c.ignoreFlash=!0;this.supported=this.ok=function(){return s?m&&!w:c.useHTML5Audio&&c.hasHTML5};this.getMovie=function(b){return S(b)||k[b]||j[b]};this.createSound=function(b){function a(){e=Y(e);c.sounds[d.id]=new Aa(d);c.soundIDs.push(d.id);
+return c.sounds[d.id]}var e=null,f=null,d=null;if(!m||!c.ok())return ra(void 0),!1;2===arguments.length&&(b={id:arguments[0],url:arguments[1]});e=q(b);e.url=ba(e.url);d=e;if(o(d.id,!0))return c.sounds[d.id];if(ca(d))f=a(),f._setup_html5(d);else{if(8<i){if(null===d.isMovieStar)d.isMovieStar=d.serverURL||(d.type?d.type.match(Pa):!1)||d.url.match(Wa);if(d.isMovieStar&&d.usePeakData)d.usePeakData=!1}d=Z(d,void 0);f=a();if(8===i)h._createSound(d.id,d.loops||1,d.usePolicyFile);else if(h._createSound(d.id,
+d.url,d.usePeakData,d.useWaveformData,d.useEQData,d.isMovieStar,d.isMovieStar?d.bufferTime:!1,d.loops||1,d.serverURL,d.duration||null,d.autoPlay,!0,d.autoLoad,d.usePolicyFile),!d.serverURL)f.connected=!0,d.onconnect&&d.onconnect.apply(f);!d.serverURL&&(d.autoLoad||d.autoPlay)&&f.load(d)}!d.serverURL&&d.autoPlay&&f.play();return f};this.destroySound=function(b,a){if(!o(b))return!1;var e=c.sounds[b],f;e._iO={};e.stop();e.unload();for(f=0;f<c.soundIDs.length;f++)if(c.soundIDs[f]===b){c.soundIDs.splice(f,
+1);break}a||e.destruct(!0);delete c.sounds[b];return!0};this.load=function(b,a){return!o(b)?!1:c.sounds[b].load(a)};this.unload=function(b){return!o(b)?!1:c.sounds[b].unload()};this.onposition=this.onPosition=function(b,a,e,f){return!o(b)?!1:c.sounds[b].onposition(a,e,f)};this.clearOnPosition=function(b,a,e){return!o(b)?!1:c.sounds[b].clearOnPosition(a,e)};this.start=this.play=function(b,a){if(!m||!c.ok())return ra("soundManager.play(): "+G(!m?"notReady":"notOK")),!1;if(!o(b)){a instanceof Object||
+(a={url:a});return a&&a.url?(a.id=b,c.createSound(a).play()):!1}return c.sounds[b].play(a)};this.setPosition=function(b,a){return!o(b)?!1:c.sounds[b].setPosition(a)};this.stop=function(b){return!o(b)?!1:c.sounds[b].stop()};this.stopAll=function(){for(var b in c.sounds)c.sounds.hasOwnProperty(b)&&c.sounds[b].stop()};this.pause=function(b){return!o(b)?!1:c.sounds[b].pause()};this.pauseAll=function(){var b;for(b=c.soundIDs.length;b--;)c.sounds[c.soundIDs[b]].pause()};this.resume=function(b){return!o(b)?
+!1:c.sounds[b].resume()};this.resumeAll=function(){var b;for(b=c.soundIDs.length;b--;)c.sounds[c.soundIDs[b]].resume()};this.togglePause=function(b){return!o(b)?!1:c.sounds[b].togglePause()};this.setPan=function(b,a){return!o(b)?!1:c.sounds[b].setPan(a)};this.setVolume=function(b,a){return!o(b)?!1:c.sounds[b].setVolume(a)};this.mute=function(b){var a=0;"string"!==typeof b&&(b=null);if(b)return!o(b)?!1:c.sounds[b].mute();for(a=c.soundIDs.length;a--;)c.sounds[c.soundIDs[a]].mute();return c.muted=!0};
+this.muteAll=function(){c.mute()};this.unmute=function(b){"string"!==typeof b&&(b=null);if(b)return!o(b)?!1:c.sounds[b].unmute();for(b=c.soundIDs.length;b--;)c.sounds[c.soundIDs[b]].unmute();c.muted=!1;return!0};this.unmuteAll=function(){c.unmute()};this.toggleMute=function(b){return!o(b)?!1:c.sounds[b].toggleMute()};this.getMemoryUse=function(){var b=0;h&&8!==i&&(b=parseInt(h._getMemoryUse(),10));return b};this.disable=function(b){var a;"undefined"===typeof b&&(b=!1);if(w)return!1;w=!0;for(a=c.soundIDs.length;a--;)Da(c.sounds[c.soundIDs[a]]);
+M(b);n.remove(j,"load",D);return!0};this.canPlayMIME=function(b){var a;c.hasHTML5&&(a=P({type:b}));return!s||a?a:b?!!(8<i&&b.match(Pa)||b.match(c.mimePattern)):null};this.canPlayURL=function(b){var a;c.hasHTML5&&(a=P({url:b}));return!s||a?a:b?!!b.match(c.filePattern):null};this.canPlayLink=function(b){return"undefined"!==typeof b.type&&b.type&&c.canPlayMIME(b.type)?!0:c.canPlayURL(b.href)};this.getSoundById=function(b){if(!b)throw Error("soundManager.getSoundById(): sID is null/undefined");return c.sounds[b]};
+this.onready=function(b,a){if(b&&b instanceof Function)return a||(a=j),ja("onready",b,a),C(),!0;throw G("needFunction","onready");};this.ontimeout=function(b,a){if(b&&b instanceof Function)return a||(a=j),ja("ontimeout",b,a),C({type:"ontimeout"}),!0;throw G("needFunction","ontimeout");};this._wD=this._writeDebug=function(){return!0};this._debug=function(){};this.reboot=function(){var b,a;for(b=c.soundIDs.length;b--;)c.sounds[c.soundIDs[b]].destruct();try{if(y)pa=h.innerHTML;N=h.parentNode.removeChild(h)}catch(e){}pa=
+N=s=null;c.enabled=ma=m=$=sa=K=L=w=c.swfLoaded=!1;c.soundIDs=c.sounds=[];h=null;for(b in v)if(v.hasOwnProperty(b))for(a=v[b].length;a--;)v[b][a].fired=!1;j.setTimeout(c.beginDelayedInit,20)};this.getMoviePercent=function(){return h&&"undefined"!==typeof h.PercentLoaded?h.PercentLoaded():null};this.beginDelayedInit=function(){ia=!0;E();setTimeout(function(){if(sa)return!1;W();V();return sa=!0},20);U()};this.destruct=function(){c.disable(!0)};Aa=function(b){var a=this,e,f,d,g,z,j,k=!1,t=[],l=0,n,p,
+m=null,r=null,s=null;this.sID=b.id;this.url=b.url;this._iO=this.instanceOptions=this.options=q(b);this.pan=this.options.pan;this.volume=this.options.volume;this.isHTML5=!1;this._a=null;this.id3={};this._debug=function(){};this.load=function(b){var c=null;if("undefined"!==typeof b)a._iO=q(b,a.options),a.instanceOptions=a._iO;else if(b=a.options,a._iO=b,a.instanceOptions=a._iO,m&&m!==a.url)a._iO.url=a.url,a.url=null;if(!a._iO.url)a._iO.url=a.url;a._iO.url=ba(a._iO.url);if(a._iO.url===a.url&&0!==a.readyState&&
+2!==a.readyState)return 3===a.readyState&&a._iO.onload&&a._iO.onload.apply(a,[!!a.duration]),a;b=a._iO;m=a.url;a.loaded=!1;a.readyState=1;a.playState=0;if(ca(b)){if(c=a._setup_html5(b),!c._called_load)a._html5_canplay=!1,a._a.autobuffer="auto",a._a.preload="auto",c.load(),c._called_load=!0,b.autoPlay&&a.play()}else try{a.isHTML5=!1,a._iO=Z(Y(b)),b=a._iO,8===i?h._load(a.sID,b.url,b.stream,b.autoPlay,b.whileloading?1:0,b.loops||1,b.usePolicyFile):h._load(a.sID,b.url,!!b.stream,!!b.autoPlay,b.loops||
+1,!!b.autoLoad,b.usePolicyFile)}catch(d){F({type:"SMSOUND_LOAD_JS_EXCEPTION",fatal:!0})}return a};this.unload=function(){0!==a.readyState&&(a.isHTML5?(g(),a._a&&(a._a.pause(),ta(a._a))):8===i?h._unload(a.sID,"about:blank"):h._unload(a.sID),e());return a};this.destruct=function(b){if(a.isHTML5){if(g(),a._a)a._a.pause(),ta(a._a),B||d(),a._a._t=null,a._a=null}else a._iO.onfailure=null,h._destroySound(a.sID);b||c.destroySound(a.sID,!0)};this.start=this.play=function(b,c){var d,c=void 0===c?!0:c;b||(b=
+{});a._iO=q(b,a._iO);a._iO=q(a._iO,a.options);a._iO.url=ba(a._iO.url);a.instanceOptions=a._iO;if(a._iO.serverURL&&!a.connected)return a.getAutoPlay()||a.setAutoPlay(!0),a;ca(a._iO)&&(a._setup_html5(a._iO),z());if(1===a.playState&&!a.paused&&(d=a._iO.multiShot,!d))return a;if(!a.loaded)if(0===a.readyState){if(!a.isHTML5)a._iO.autoPlay=!0;a.load(a._iO)}else if(2===a.readyState)return a;if(!a.isHTML5&&9===i&&0<a.position&&a.position===a.duration)b.position=0;if(a.paused&&a.position&&0<a.position)a.resume();
+else{a._iO=q(b,a._iO);if(null!==a._iO.from&&null!==a._iO.to&&0===a.instanceCount&&0===a.playState&&!a._iO.serverURL){d=function(){a._iO=q(b,a._iO);a.play(a._iO)};if(a.isHTML5&&!a._html5_canplay)return a.load({_oncanplay:d}),!1;if(!a.isHTML5&&!a.loaded&&(!a.readyState||2!==a.readyState))return a.load({onload:d}),!1;a._iO=p()}(!a.instanceCount||a._iO.multiShotEvents||!a.isHTML5&&8<i&&!a.getAutoPlay())&&a.instanceCount++;0===a.playState&&a._iO.onposition&&j(a);a.playState=1;a.paused=!1;a.position="undefined"!==
+typeof a._iO.position&&!isNaN(a._iO.position)?a._iO.position:0;if(!a.isHTML5)a._iO=Z(Y(a._iO));a._iO.onplay&&c&&(a._iO.onplay.apply(a),k=!0);a.setVolume(a._iO.volume,!0);a.setPan(a._iO.pan,!0);a.isHTML5?(z(),d=a._setup_html5(),a.setPosition(a._iO.position),d.play()):h._start(a.sID,a._iO.loops||1,9===i?a._iO.position:a._iO.position/1E3)}return a};this.stop=function(b){var c=a._iO;if(1===a.playState){a._onbufferchange(0);a._resetOnPosition(0);a.paused=!1;if(!a.isHTML5)a.playState=0;n();c.to&&a.clearOnPosition(c.to);
+if(a.isHTML5){if(a._a)b=a.position,a.setPosition(0),a.position=b,a._a.pause(),a.playState=0,a._onTimer(),g()}else h._stop(a.sID,b),c.serverURL&&a.unload();a.instanceCount=0;a._iO={};c.onstop&&c.onstop.apply(a)}return a};this.setAutoPlay=function(b){a._iO.autoPlay=b;a.isHTML5||(h._setAutoPlay(a.sID,b),b&&!a.instanceCount&&1===a.readyState&&a.instanceCount++)};this.getAutoPlay=function(){return a._iO.autoPlay};this.setPosition=function(b){void 0===b&&(b=0);var c=a.isHTML5?Math.max(b,0):Math.min(a.duration||
+a._iO.duration,Math.max(b,0));a.position=c;b=a.position/1E3;a._resetOnPosition(a.position);a._iO.position=c;if(a.isHTML5){if(a._a&&a._html5_canplay&&a._a.currentTime!==b)try{a._a.currentTime=b,(0===a.playState||a.paused)&&a._a.pause()}catch(d){}}else b=9===i?a.position:b,a.readyState&&2!==a.readyState&&h._setPosition(a.sID,b,a.paused||!a.playState);a.isHTML5&&a.paused&&a._onTimer(!0);return a};this.pause=function(b){if(a.paused||0===a.playState&&1!==a.readyState)return a;a.paused=!0;a.isHTML5?(a._setup_html5().pause(),
+g()):(b||void 0===b)&&h._pause(a.sID);a._iO.onpause&&a._iO.onpause.apply(a);return a};this.resume=function(){var b=a._iO;if(!a.paused)return a;a.paused=!1;a.playState=1;a.isHTML5?(a._setup_html5().play(),z()):(b.isMovieStar&&!b.serverURL&&a.setPosition(a.position),h._pause(a.sID));k&&b.onplay?(b.onplay.apply(a),k=!0):b.onresume&&b.onresume.apply(a);return a};this.togglePause=function(){if(0===a.playState)return a.play({position:9===i&&!a.isHTML5?a.position:a.position/1E3}),a;a.paused?a.resume():a.pause();
+return a};this.setPan=function(b,c){"undefined"===typeof b&&(b=0);"undefined"===typeof c&&(c=!1);a.isHTML5||h._setPan(a.sID,b);a._iO.pan=b;if(!c)a.pan=b,a.options.pan=b;return a};this.setVolume=function(b,d){"undefined"===typeof b&&(b=100);"undefined"===typeof d&&(d=!1);if(a.isHTML5){if(a._a)a._a.volume=Math.max(0,Math.min(1,b/100))}else h._setVolume(a.sID,c.muted&&!a.muted||a.muted?0:b);a._iO.volume=b;if(!d)a.volume=b,a.options.volume=b;return a};this.mute=function(){a.muted=!0;if(a.isHTML5){if(a._a)a._a.muted=
+!0}else h._setVolume(a.sID,0);return a};this.unmute=function(){a.muted=!1;var b="undefined"!==typeof a._iO.volume;if(a.isHTML5){if(a._a)a._a.muted=!1}else h._setVolume(a.sID,b?a._iO.volume:a.options.volume);return a};this.toggleMute=function(){return a.muted?a.unmute():a.mute()};this.onposition=this.onPosition=function(b,c,d){t.push({position:b,method:c,scope:"undefined"!==typeof d?d:a,fired:!1});return a};this.clearOnPosition=function(a,b){var c,a=parseInt(a,10);if(isNaN(a))return!1;for(c=0;c<t.length;c++)if(a===
+t[c].position&&(!b||b===t[c].method))t[c].fired&&l--,t.splice(c,1)};this._processOnPosition=function(){var b,c;b=t.length;if(!b||!a.playState||l>=b)return!1;for(;b--;)if(c=t[b],!c.fired&&a.position>=c.position)c.fired=!0,l++,c.method.apply(c.scope,[c.position]);return!0};this._resetOnPosition=function(a){var b,c;b=t.length;if(!b)return!1;for(;b--;)if(c=t[b],c.fired&&a<=c.position)c.fired=!1,l--;return!0};p=function(){var b=a._iO,c=b.from,d=b.to,e,f;f=function(){a.clearOnPosition(d,f);a.stop()};e=
+function(){if(null!==d&&!isNaN(d))a.onPosition(d,f)};if(null!==c&&!isNaN(c))b.position=c,b.multiShot=!1,e();return b};j=function(){var b=a._iO.onposition;if(b)for(var c in b)if(b.hasOwnProperty(c))a.onPosition(parseInt(c,10),b[c])};n=function(){var b=a._iO.onposition;if(b)for(var c in b)b.hasOwnProperty(c)&&a.clearOnPosition(parseInt(c,10))};z=function(){a.isHTML5&&Fa(a)};g=function(){a.isHTML5&&Ga(a)};e=function(){t=[];l=0;k=!1;a._hasTimer=null;a._a=null;a._html5_canplay=!1;a.bytesLoaded=null;a.bytesTotal=
+null;a.duration=a._iO&&a._iO.duration?a._iO.duration:null;a.durationEstimate=null;a.eqData=[];a.eqData.left=[];a.eqData.right=[];a.failures=0;a.isBuffering=!1;a.instanceOptions={};a.instanceCount=0;a.loaded=!1;a.metadata={};a.readyState=0;a.muted=!1;a.paused=!1;a.peakData={left:0,right:0};a.waveformData={left:[],right:[]};a.playState=0;a.position=null};e();this._onTimer=function(b){var c,d=!1,e={};if(a._hasTimer||b){if(a._a&&(b||(0<a.playState||1===a.readyState)&&!a.paused)){c=a._get_html5_duration();
+if(c!==r)r=c,a.duration=c,d=!0;a.durationEstimate=a.duration;c=1E3*a._a.currentTime||0;c!==s&&(s=c,d=!0);(d||b)&&a._whileplaying(c,e,e,e,e);return d}return!1}};this._get_html5_duration=function(){var b=a._iO,c=a._a?1E3*a._a.duration:b?b.duration:void 0;return c&&!isNaN(c)&&Infinity!==c?c:b?b.duration:null};this._setup_html5=function(b){var b=q(a._iO,b),d=decodeURI,g=B?c._global_a:a._a,h=d(b.url),z=g&&g._t?g._t.instanceOptions:null;if(g){if(g._t&&(!B&&h===d(m)||B&&z.url===b.url&&(!m||m===z.url)))return g;
+B&&g._t&&g._t.playState&&b.url!==z.url&&g._t.stop();e();g.src=b.url;m=a.url=b.url;g._called_load=!1}else{g=new Audio(b.url);g._called_load=!1;if(Ta)g._called_load=!0;if(B)c._global_a=g}a.isHTML5=!0;a._a=g;g._t=a;f();g.loop=1<b.loops?"loop":"";b.autoLoad||b.autoPlay?a.load():(g.autobuffer=!1,g.preload="none");g.loop=1<b.loops?"loop":"";return g};f=function(){if(a._a._added_events)return!1;var b;a._a._added_events=!0;for(b in u)u.hasOwnProperty(b)&&a._a&&a._a.addEventListener(b,u[b],!1);return!0};d=
+function(){var b;a._a._added_events=!1;for(b in u)u.hasOwnProperty(b)&&a._a&&a._a.removeEventListener(b,u[b],!1)};this._onload=function(b){b=!!b;a.loaded=b;a.readyState=b?3:2;a._onbufferchange(0);a._iO.onload&&a._iO.onload.apply(a,[b]);return!0};this._onbufferchange=function(b){if(0===a.playState||b&&a.isBuffering||!b&&!a.isBuffering)return!1;a.isBuffering=1===b;a._iO.onbufferchange&&a._iO.onbufferchange.apply(a);return!0};this._onsuspend=function(){a._iO.onsuspend&&a._iO.onsuspend.apply(a);return!0};
+this._onfailure=function(b,c,d){a.failures++;if(a._iO.onfailure&&1===a.failures)a._iO.onfailure(a,b,c,d)};this._onfinish=function(){var b=a._iO.onfinish;a._onbufferchange(0);a._resetOnPosition(0);if(a.instanceCount){a.instanceCount--;if(!a.instanceCount)n(),a.playState=0,a.paused=!1,a.instanceCount=0,a.instanceOptions={},a._iO={},g();(!a.instanceCount||a._iO.multiShotEvents)&&b&&b.apply(a)}};this._whileloading=function(b,c,d,e){var f=a._iO;a.bytesLoaded=b;a.bytesTotal=c;a.duration=Math.floor(d);a.bufferLength=
+e;if(f.isMovieStar)a.durationEstimate=a.duration;else if(a.durationEstimate=f.duration?a.duration>f.duration?a.duration:f.duration:parseInt(a.bytesTotal/a.bytesLoaded*a.duration,10),void 0===a.durationEstimate)a.durationEstimate=a.duration;3!==a.readyState&&f.whileloading&&f.whileloading.apply(a)};this._whileplaying=function(b,c,d,e,f){var g=a._iO;if(isNaN(b)||null===b)return!1;a.position=b;a._processOnPosition();if(!a.isHTML5&&8<i){if(g.usePeakData&&"undefined"!==typeof c&&c)a.peakData={left:c.leftPeak,
+right:c.rightPeak};if(g.useWaveformData&&"undefined"!==typeof d&&d)a.waveformData={left:d.split(","),right:e.split(",")};if(g.useEQData&&"undefined"!==typeof f&&f&&f.leftEQ&&(b=f.leftEQ.split(","),a.eqData=b,a.eqData.left=b,"undefined"!==typeof f.rightEQ&&f.rightEQ))a.eqData.right=f.rightEQ.split(",")}1===a.playState&&(!a.isHTML5&&8===i&&!a.position&&a.isBuffering&&a._onbufferchange(0),g.whileplaying&&g.whileplaying.apply(a));return!0};this._onmetadata=function(b,c){var d={},e,f;for(e=0,f=b.length;e<
+f;e++)d[b[e]]=c[e];a.metadata=d;a._iO.onmetadata&&a._iO.onmetadata.apply(a)};this._onid3=function(b,c){var d=[],e,f;for(e=0,f=b.length;e<f;e++)d[b[e]]=c[e];a.id3=q(a.id3,d);a._iO.onid3&&a._iO.onid3.apply(a)};this._onconnect=function(b){b=1===b;if(a.connected=b)a.failures=0,o(a.sID)&&(a.getAutoPlay()?a.play(void 0,a.getAutoPlay()):a._iO.autoLoad&&a.load()),a._iO.onconnect&&a._iO.onconnect.apply(a,[b])};this._ondataerror=function(){0<a.playState&&a._iO.ondataerror&&a._iO.ondataerror.apply(a)}};na=function(){return k.body||
+k._docElement||k.getElementsByTagName("div")[0]};S=function(b){return k.getElementById(b)};q=function(b,a){var e={},f,d;for(f in b)b.hasOwnProperty(f)&&(e[f]=b[f]);f="undefined"===typeof a?c.defaultOptions:a;for(d in f)f.hasOwnProperty(d)&&"undefined"===typeof e[d]&&(e[d]=f[d]);return e};n=function(){function b(a){var a=Ra.call(a),b=a.length;c?(a[1]="on"+a[1],3<b&&a.pop()):3===b&&a.push(!1);return a}function a(a,b){var h=a.shift(),k=[f[b]];if(c)h[k](a[0],a[1]);else h[k].apply(h,a)}var c=j.attachEvent,
+f={add:c?"attachEvent":"addEventListener",remove:c?"detachEvent":"removeEventListener"};return{add:function(){a(b(arguments),"add")},remove:function(){a(b(arguments),"remove")}}}();u={abort:l(function(){}),canplay:l(function(){var b=this._t;if(b._html5_canplay)return!0;b._html5_canplay=!0;b._onbufferchange(0);var a=!isNaN(b.position)?b.position/1E3:null;if(b.position&&this.currentTime!==a)try{this.currentTime=a}catch(c){}b._iO._oncanplay&&b._iO._oncanplay()}),load:l(function(){var b=this._t;b.loaded||
+(b._onbufferchange(0),b._whileloading(b.bytesTotal,b.bytesTotal,b._get_html5_duration()),b._onload(!0))}),emptied:l(function(){}),ended:l(function(){this._t._onfinish()}),error:l(function(){this._t._onload(!1)}),loadeddata:l(function(){var b=this._t,a=b.bytesTotal||1;if(!b._loaded&&!Q)b.duration=b._get_html5_duration(),b._whileloading(a,a,b._get_html5_duration()),b._onload(!0)}),loadedmetadata:l(function(){}),loadstart:l(function(){this._t._onbufferchange(1)}),play:l(function(){this._t._onbufferchange(0)}),
+playing:l(function(){this._t._onbufferchange(0)}),progress:l(function(b){var a=this._t;if(a.loaded)return!1;var c,f=0,d=b.target.buffered;c=b.loaded||0;var g=b.total||1;if(d&&d.length){for(c=d.length;c--;)f=d.end(c)-d.start(c);c=f/b.target.duration}isNaN(c)||(a._onbufferchange(0),a._whileloading(c,g,a._get_html5_duration()),c&&g&&c===g&&u.load.call(this,b))}),ratechange:l(function(){}),suspend:l(function(b){var a=this._t;u.progress.call(this,b);a._onsuspend()}),stalled:l(function(){}),timeupdate:l(function(){this._t._onTimer()}),
+waiting:l(function(){this._t._onbufferchange(1)})};ca=function(b){return!b.serverURL&&(b.type?P({type:b.type}):P({url:b.url})||c.html5Only)};ta=function(b){if(b)b.src=Sa?"":"about:blank"};P=function(b){function a(a){return c.preferFlash&&r&&!c.ignoreFlash&&"undefined"!==typeof c.flash[a]&&c.flash[a]}if(!c.useHTML5Audio||!c.hasHTML5)return!1;var e=b.url||null,b=b.type||null,f=c.audioFormats,d;if(b&&"undefined"!==c.html5[b])return c.html5[b]&&!a(b);if(!x){x=[];for(d in f)f.hasOwnProperty(d)&&(x.push(d),
+f[d].related&&(x=x.concat(f[d].related)));x=RegExp("\\.("+x.join("|")+")(\\?.*)?$","i")}d=e?e.toLowerCase().match(x):null;if(!d||!d.length)if(b)e=b.indexOf(";"),d=(-1!==e?b.substr(0,e):b).substr(6);else return!1;else d=d[1];if(d&&"undefined"!==typeof c.html5[d])return c.html5[d]&&!a(d);b="audio/"+d;e=c.html5.canPlayType({type:b});return(c.html5[d]=e)&&c.html5[b]&&!a(b)};Ja=function(){function b(b){var d,e,f=!1;if(!a||"function"!==typeof a.canPlayType)return!1;if(b instanceof Array){for(d=0,e=b.length;d<
+e&&!f;d++)if(c.html5[b[d]]||a.canPlayType(b[d]).match(c.html5Test))f=!0,c.html5[b[d]]=!0,c.flash[b[d]]=!(!c.preferFlash||!r||!b[d].match(Na));return f}b=a&&"function"===typeof a.canPlayType?a.canPlayType(b):!1;return!(!b||!b.match(c.html5Test))}if(!c.useHTML5Audio||"undefined"===typeof Audio)return!1;var a="undefined"!==typeof Audio?Va?new Audio(null):new Audio:null,e,f={},d,g;d=c.audioFormats;for(e in d)if(d.hasOwnProperty(e)&&(f[e]=b(d[e].type),f["audio/"+e]=f[e],c.flash[e]=c.preferFlash&&!c.ignoreFlash&&
+e.match(Na)?!0:!1,d[e]&&d[e].related))for(g=d[e].related.length;g--;)f["audio/"+d[e].related[g]]=f[e],c.html5[d[e].related[g]]=f[e],c.flash[d[e].related[g]]=f[e];f.canPlayType=a?b:null;c.html5=q(c.html5,f);return!0};G=function(){};Y=function(b){if(8===i&&1<b.loops&&b.stream)b.stream=!1;return b};Z=function(b){if(b&&!b.usePolicyFile&&(b.onid3||b.usePeakData||b.useWaveformData||b.useEQData))b.usePolicyFile=!0;return b};ra=function(){};ha=function(){return!1};Da=function(b){for(var a in b)b.hasOwnProperty(a)&&
+"function"===typeof b[a]&&(b[a]=ha)};X=function(b){"undefined"===typeof b&&(b=!1);(w||b)&&c.disable(b)};Ea=function(b){var a=null;if(b)if(b.match(/\.swf(\?.*)?$/i)){if(a=b.substr(b.toLowerCase().lastIndexOf(".swf?")+4))return b}else b.lastIndexOf("/")!==b.length-1&&(b+="/");b=(b&&-1!==b.lastIndexOf("/")?b.substr(0,b.lastIndexOf("/")+1):"./")+c.movieURL;c.noSWFCache&&(b+="?ts="+(new Date).getTime());return b};ka=function(){i=parseInt(c.flashVersion,10);if(8!==i&&9!==i)c.flashVersion=i=8;var b=c.debugMode||
+c.debugFlash?"_debug.swf":".swf";if(c.useHTML5Audio&&!c.html5Only&&c.audioFormats.mp4.required&&9>i)c.flashVersion=i=9;c.version=c.versionNumber+(c.html5Only?" (HTML5-only mode)":9===i?" (AS3/Flash 9)":" (AS2/Flash 8)");8<i?(c.defaultOptions=q(c.defaultOptions,c.flash9Options),c.features.buffering=!0,c.defaultOptions=q(c.defaultOptions,c.movieStarOptions),c.filePatterns.flash9=RegExp("\\.(mp3|"+Qa.join("|")+")(\\?.*)?$","i"),c.features.movieStar=!0):c.features.movieStar=!1;c.filePattern=c.filePatterns[8!==
+i?"flash9":"flash8"];c.movieURL=(8===i?"soundmanager2.swf":"soundmanager2_flash9.swf").replace(".swf",b);c.features.peakData=c.features.waveformData=c.features.eqData=8<i};Ca=function(b,a){if(!h)return!1;h._setPolling(b,a)};oa=function(){if(c.debugURLParam.test(ga))c.debugMode=!0};o=this.getSoundById;H=function(){var b=[];c.debugMode&&b.push("sm2_debug");c.debugFlash&&b.push("flash_debug");c.useHighPerformance&&b.push("high_performance");return b.join(" ")};qa=function(){G("fbHandler");var b=c.getMoviePercent(),
+a={type:"FLASHBLOCK"};if(c.html5Only)return!1;if(c.ok()){if(c.oMC)c.oMC.className=[H(),"movieContainer","swf_loaded"+(c.didFlashBlock?" swf_unblocked":"")].join(" ")}else{if(s)c.oMC.className=H()+" movieContainer "+(null===b?"swf_timedout":"swf_error");c.didFlashBlock=!0;C({type:"ontimeout",ignoreInit:!0,error:a});F(a)}};ja=function(b,a,c){"undefined"===typeof v[b]&&(v[b]=[]);v[b].push({method:a,scope:c||null,fired:!1})};C=function(b){b||(b={type:"onready"});if(!m&&b&&!b.ignoreInit||"ontimeout"===
+b.type&&c.ok())return!1;var a={success:b&&b.ignoreInit?c.ok():!w},e=b&&b.type?v[b.type]||[]:[],f=[],d,a=[a],g=s&&c.useFlashBlock&&!c.ok();if(b.error)a[0].error=b.error;for(b=0,d=e.length;b<d;b++)!0!==e[b].fired&&f.push(e[b]);if(f.length)for(b=0,d=f.length;b<d;b++)if(f[b].scope?f[b].method.apply(f[b].scope,a):f[b].method.apply(this,a),!g)f[b].fired=!0;return!0};D=function(){j.setTimeout(function(){c.useFlashBlock&&qa();C();c.onload instanceof Function&&c.onload.apply(j);c.waitForWindowLoad&&n.add(j,
+"load",D)},1)};da=function(){if(void 0!==r)return r;var b=!1,a=navigator,c=a.plugins,f,d=j.ActiveXObject;if(c&&c.length)(a=a.mimeTypes)&&a["application/x-shockwave-flash"]&&a["application/x-shockwave-flash"].enabledPlugin&&a["application/x-shockwave-flash"].enabledPlugin.description&&(b=!0);else if("undefined"!==typeof d){try{f=new d("ShockwaveFlash.ShockwaveFlash")}catch(g){}b=!!f}return r=b};Ia=function(){var b,a;if(va&&p.match(/os (1|2|3_0|3_1)/i)){c.hasHTML5=!1;c.html5Only=!0;if(c.oMC)c.oMC.style.display=
+"none";return!1}if(c.useHTML5Audio){if(!c.html5||!c.html5.canPlayType)return c.hasHTML5=!1,!0;c.hasHTML5=!0;if(xa&&da())return!0}else return!0;for(a in c.audioFormats)if(c.audioFormats.hasOwnProperty(a)&&(c.audioFormats[a].required&&!c.html5.canPlayType(c.audioFormats[a].type)||c.flash[a]||c.flash[c.audioFormats[a].type]))b=!0;c.ignoreFlash&&(b=!1);c.html5Only=c.hasHTML5&&c.useHTML5Audio&&!b;return!c.html5Only};ba=function(b){var a,e,f=0;if(b instanceof Array){for(a=0,e=b.length;a<e;a++)if(b[a]instanceof
+Object){if(c.canPlayMIME(b[a].type)){f=a;break}}else if(c.canPlayURL(b[a])){f=a;break}if(b[f].url)b[f]=b[f].url;return b[f]}return b};Fa=function(b){if(!b._hasTimer)b._hasTimer=!0,!wa&&c.html5PollingInterval&&(null===O&&0===aa&&(O=J.setInterval(Ha,c.html5PollingInterval)),aa++)};Ga=function(b){if(b._hasTimer)b._hasTimer=!1,!wa&&c.html5PollingInterval&&aa--};Ha=function(){var b;if(null!==O&&!aa)return J.clearInterval(O),O=null,!1;for(b=c.soundIDs.length;b--;)c.sounds[c.soundIDs[b]].isHTML5&&c.sounds[c.soundIDs[b]]._hasTimer&&
+c.sounds[c.soundIDs[b]]._onTimer()};F=function(b){b="undefined"!==typeof b?b:{};c.onerror instanceof Function&&c.onerror.apply(j,[{type:"undefined"!==typeof b.type?b.type:null}]);"undefined"!==typeof b.fatal&&b.fatal&&c.disable()};Ka=function(){if(!xa||!da())return!1;var b=c.audioFormats,a,e;for(e in b)if(b.hasOwnProperty(e)&&("mp3"===e||"mp4"===e))if(c.html5[e]=!1,b[e]&&b[e].related)for(a=b[e].related.length;a--;)c.html5[b[e].related[a]]=!1};this._setSandboxType=function(){};this._externalInterfaceOK=
+function(){if(c.swfLoaded)return!1;(new Date).getTime();c.swfLoaded=!0;I=!1;xa&&Ka();y?setTimeout(T,100):T()};W=function(b,a){function e(a,b){return'<param name="'+a+'" value="'+b+'" />'}if(K&&L)return!1;if(c.html5Only)return ka(),c.oMC=S(c.movieID),T(),L=K=!0,!1;var f=a||c.url,d=c.altURL||f,g;g=na();var h,j,i=H(),l,m=null,m=(m=k.getElementsByTagName("html")[0])&&m.dir&&m.dir.match(/rtl/i),b="undefined"===typeof b?c.id:b;ka();c.url=Ea(za?f:d);a=c.url;c.wmode=!c.wmode&&c.useHighPerformance?"transparent":
+c.wmode;if(null!==c.wmode&&(p.match(/msie 8/i)||!y&&!c.useHighPerformance)&&navigator.platform.match(/win32|win64/i))c.wmode=null;g={name:b,id:b,src:a,width:"auto",height:"auto",quality:"high",allowScriptAccess:c.allowScriptAccess,bgcolor:c.bgColor,pluginspage:Oa+"www.macromedia.com/go/getflashplayer",title:"JS/Flash audio component (SoundManager 2)",type:"application/x-shockwave-flash",wmode:c.wmode,hasPriority:"true"};if(c.debugFlash)g.FlashVars="debug=1";c.wmode||delete g.wmode;if(y)f=k.createElement("div"),
+j=['<object id="'+b+'" data="'+a+'" type="'+g.type+'" title="'+g.title+'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="'+Oa+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="'+g.width+'" height="'+g.height+'">',e("movie",a),e("AllowScriptAccess",c.allowScriptAccess),e("quality",g.quality),c.wmode?e("wmode",c.wmode):"",e("bgcolor",c.bgColor),e("hasPriority","true"),c.debugFlash?e("FlashVars",g.FlashVars):"","</object>"].join("");else for(h in f=
+k.createElement("embed"),g)g.hasOwnProperty(h)&&f.setAttribute(h,g[h]);oa();i=H();if(g=na())if(c.oMC=S(c.movieID)||k.createElement("div"),c.oMC.id){l=c.oMC.className;c.oMC.className=(l?l+" ":"movieContainer")+(i?" "+i:"");c.oMC.appendChild(f);if(y)h=c.oMC.appendChild(k.createElement("div")),h.className="sm2-object-box",h.innerHTML=j;L=!0}else{c.oMC.id=c.movieID;c.oMC.className="movieContainer "+i;h=i=null;if(!c.useFlashBlock)if(c.useHighPerformance)i={position:"fixed",width:"8px",height:"8px",bottom:"0px",
+left:"0px",overflow:"hidden"};else if(i={position:"absolute",width:"6px",height:"6px",top:"-9999px",left:"-9999px"},m)i.left=Math.abs(parseInt(i.left,10))+"px";if(Ua)c.oMC.style.zIndex=1E4;if(!c.debugFlash)for(l in i)i.hasOwnProperty(l)&&(c.oMC.style[l]=i[l]);try{y||c.oMC.appendChild(f);g.appendChild(c.oMC);if(y)h=c.oMC.appendChild(k.createElement("div")),h.className="sm2-object-box",h.innerHTML=j;L=!0}catch(n){throw Error(G("domError")+" \n"+n.toString());}}return K=!0};V=function(){if(c.html5Only)return W(),
+!1;if(h)return!1;h=c.getMovie(c.id);if(!h)N?(y?c.oMC.innerHTML=pa:c.oMC.appendChild(N),N=null,K=!0):W(c.id,c.url),h=c.getMovie(c.id);c.oninitmovie instanceof Function&&setTimeout(c.oninitmovie,1);return!0};U=function(){setTimeout(Ba,1E3)};Ba=function(){if($)return!1;$=!0;n.remove(j,"load",U);if(I&&!ya)return!1;var b;m||(b=c.getMoviePercent());setTimeout(function(){b=c.getMoviePercent();!m&&Ma&&(null===b?c.useFlashBlock||0===c.flashLoadTimeout?c.useFlashBlock&&qa():X(!0):0!==c.flashLoadTimeout&&X(!0))},
+c.flashLoadTimeout)};A=function(){function b(){n.remove(j,"focus",A);n.remove(j,"load",A)}if(ya||!I)return b(),!0;ya=Ma=!0;Q&&I&&n.remove(j,"mousemove",A);$=!1;b();return!0};La=function(){var b,a=[];if(c.useHTML5Audio&&c.hasHTML5)for(b in c.audioFormats)c.audioFormats.hasOwnProperty(b)&&a.push(b+": "+c.html5[b]+(!c.html5[b]&&r&&c.flash[b]?" (using flash)":c.preferFlash&&c.flash[b]&&r?" (preferring flash)":!c.html5[b]?" ("+(c.audioFormats[b].required?"required, ":"")+"and no flash support)":""))};
+M=function(b){if(m)return!1;if(c.html5Only)return m=!0,D(),!0;var a;if(!c.useFlashBlock||!c.flashLoadTimeout||c.getMoviePercent())m=!0,w&&(a={type:!r&&s?"NO_FLASH":"INIT_TIMEOUT"});if(w||b){if(c.useFlashBlock&&c.oMC)c.oMC.className=H()+" "+(null===c.getMoviePercent()?"swf_timedout":"swf_error");C({type:"ontimeout",error:a});F(a);return!1}if(c.waitForWindowLoad&&!ia)return n.add(j,"load",D),!1;D();return!0};T=function(){if(m)return!1;if(c.html5Only){if(!m)n.remove(j,"load",c.beginDelayedInit),c.enabled=
+!0,M();return!0}V();try{h._externalInterfaceTest(!1),Ca(!0,c.flashPollingInterval||(c.useHighPerformance?10:50)),c.debugMode||h._disableDebug(),c.enabled=!0,c.html5Only||n.add(j,"unload",ha)}catch(b){return F({type:"JS_TO_FLASH_EXCEPTION",fatal:!0}),X(!0),M(),!1}M();n.remove(j,"load",c.beginDelayedInit);return!0};E=function(){if(ma)return!1;ma=!0;oa();if(!r&&c.hasHTML5)c.useHTML5Audio=!0,c.preferFlash=!1;Ja();c.html5.usingFlash=Ia();s=c.html5.usingFlash;La();if(!r&&s)c.flashLoadTimeout=1;k.removeEventListener&&
+k.removeEventListener("DOMContentLoaded",E,!1);V();return!0};ua=function(){"complete"===k.readyState&&(E(),k.detachEvent("onreadystatechange",ua));return!0};la=function(){ia=!0;n.remove(j,"load",la)};da();n.add(j,"focus",A);n.add(j,"load",A);n.add(j,"load",U);n.add(j,"load",la);Q&&I&&n.add(j,"mousemove",A);k.addEventListener?k.addEventListener("DOMContentLoaded",E,!1):k.attachEvent?k.attachEvent("onreadystatechange",ua):F({type:"NO_DOM2_EVENTS",fatal:!0});"complete"===k.readyState&&setTimeout(E,100)}
+var ea=null;if("undefined"===typeof SM2_DEFER||!SM2_DEFER)ea=new R;J.SoundManager=R;J.soundManager=ea})(window); \ No newline at end of file
diff --git a/Processing-js/libs/inc/SoundManager2/script/soundmanager2-nodebug.js b/Processing-js/libs/inc/SoundManager2/script/soundmanager2-nodebug.js
new file mode 100755
index 0000000..ba81243
--- /dev/null
+++ b/Processing-js/libs/inc/SoundManager2/script/soundmanager2-nodebug.js
@@ -0,0 +1,2377 @@
+/** @license
+ *
+ * SoundManager 2: JavaScript Sound for the Web
+ * ----------------------------------------------
+ * http://schillmania.com/projects/soundmanager2/
+ *
+ * Copyright (c) 2007, Scott Schiller. All rights reserved.
+ * Code provided under the BSD License:
+ * http://schillmania.com/projects/soundmanager2/license.txt
+ *
+ * V2.97a.20111220
+ */
+
+/*global window, SM2_DEFER, sm2Debugger, console, document, navigator, setTimeout, setInterval, clearInterval, Audio */
+/* jslint regexp: true, sloppy: true, white: true, nomen: true, plusplus: true */
+
+(function(window) {
+var soundManager = null;
+function SoundManager(smURL, smID) {
+ this.flashVersion = 8;
+ this.debugMode = false;
+ this.debugFlash = false;
+ this.useConsole = true;
+ this.consoleOnly = true;
+ this.waitForWindowLoad = false;
+ this.bgColor = '#ffffff';
+ this.useHighPerformance = false;
+ this.flashPollingInterval = null;
+ this.html5PollingInterval = null;
+ this.flashLoadTimeout = 1000;
+ this.wmode = null;
+ this.allowScriptAccess = 'always';
+ this.useFlashBlock = false;
+ this.useHTML5Audio = true;
+ this.html5Test = /^(probably|maybe)$/i;
+ this.preferFlash = true;
+ this.noSWFCache = false;
+ this.audioFormats = {
+ 'mp3': {
+ 'type': ['audio/mpeg; codecs="mp3"', 'audio/mpeg', 'audio/mp3', 'audio/MPA', 'audio/mpa-robust'],
+ 'required': true
+ },
+ 'mp4': {
+ 'related': ['aac','m4a'],
+ 'type': ['audio/mp4; codecs="mp4a.40.2"', 'audio/aac', 'audio/x-m4a', 'audio/MP4A-LATM', 'audio/mpeg4-generic'],
+ 'required': false
+ },
+ 'ogg': {
+ 'type': ['audio/ogg; codecs=vorbis'],
+ 'required': false
+ },
+ 'wav': {
+ 'type': ['audio/wav; codecs="1"', 'audio/wav', 'audio/wave', 'audio/x-wav'],
+ 'required': false
+ }
+ };
+ this.defaultOptions = {
+ 'autoLoad': false,
+ 'autoPlay': false,
+ 'from': null,
+ 'loops': 1,
+ 'onid3': null,
+ 'onload': null,
+ 'whileloading': null,
+ 'onplay': null,
+ 'onpause': null,
+ 'onresume': null,
+ 'whileplaying': null,
+ 'onposition': null,
+ 'onstop': null,
+ 'onfailure': null,
+ 'onfinish': null,
+ 'multiShot': true,
+ 'multiShotEvents': false,
+ 'position': null,
+ 'pan': 0,
+ 'stream': true,
+ 'to': null,
+ 'type': null,
+ 'usePolicyFile': false,
+ 'volume': 100
+ };
+ this.flash9Options = {
+ 'isMovieStar': null,
+ 'usePeakData': false,
+ 'useWaveformData': false,
+ 'useEQData': false,
+ 'onbufferchange': null,
+ 'ondataerror': null
+ };
+ this.movieStarOptions = {
+ 'bufferTime': 3,
+ 'serverURL': null,
+ 'onconnect': null,
+ 'duration': null
+ };
+ this.movieID = 'sm2-container';
+ this.id = (smID || 'sm2movie');
+ this.debugID = 'soundmanager-debug';
+ this.debugURLParam = /([#?&])debug=1/i;
+ this.versionNumber = 'V2.97a.20111220';
+ this.version = null;
+ this.movieURL = null;
+ this.url = (smURL || null);
+ this.altURL = null;
+ this.swfLoaded = false;
+ this.enabled = false;
+ this.oMC = null;
+ this.sounds = {};
+ this.soundIDs = [];
+ this.muted = false;
+ this.didFlashBlock = false;
+ this.filePattern = null;
+ this.filePatterns = {
+ 'flash8': /\.mp3(\?.*)?$/i,
+ 'flash9': /\.mp3(\?.*)?$/i
+ };
+ this.features = {
+ 'buffering': false,
+ 'peakData': false,
+ 'waveformData': false,
+ 'eqData': false,
+ 'movieStar': false
+ };
+ this.sandbox = {
+ };
+ this.hasHTML5 = (function() {
+ try {
+ return (typeof Audio !== 'undefined' && typeof new Audio().canPlayType !== 'undefined');
+ } catch(e) {
+ return false;
+ }
+ }());
+ this.html5 = {
+ 'usingFlash': null
+ };
+ this.flash = {};
+ this.html5Only = false;
+ this.ignoreFlash = false;
+ var SMSound,
+ _s = this, _flash = null, _sm = 'soundManager', _smc = _sm+'::', _h5 = 'HTML5::', _id, _ua = navigator.userAgent, _win = window, _wl = _win.location.href.toString(), _doc = document, _doNothing, _init, _fV, _on_queue = [], _debugOpen = true, _debugTS, _didAppend = false, _appendSuccess = false, _didInit = false, _disabled = false, _windowLoaded = false, _wDS, _wdCount = 0, _initComplete, _mixin, _addOnEvent, _processOnEvents, _initUserOnload, _delayWaitForEI, _waitForEI, _setVersionInfo, _handleFocus, _strings, _initMovie, _domContentLoaded, _winOnLoad, _didDCLoaded, _getDocument, _createMovie, _catchError, _setPolling, _initDebug, _debugLevels = ['log', 'info', 'warn', 'error'], _defaultFlashVersion = 8, _disableObject, _failSafely, _normalizeMovieURL, _oRemoved = null, _oRemovedHTML = null, _str, _flashBlockHandler, _getSWFCSS, _swfCSS, _toggleDebug, _loopFix, _policyFix, _complain, _idCheck, _waitingForEI = false, _initPending = false, _smTimer, _onTimer, _startTimer, _stopTimer, _timerExecute, _h5TimerCount = 0, _h5IntervalTimer = null, _parseURL,
+ _needsFlash = null, _featureCheck, _html5OK, _html5CanPlay, _html5Ext, _html5Unload, _domContentLoadedIE, _testHTML5, _event, _slice = Array.prototype.slice, _useGlobalHTML5Audio = false, _hasFlash, _detectFlash, _badSafariFix, _html5_events, _showSupport,
+ _is_iDevice = _ua.match(/(ipad|iphone|ipod)/i), _is_firefox = _ua.match(/firefox/i), _is_android = _ua.match(/droid/i), _isIE = _ua.match(/msie/i), _isWebkit = _ua.match(/webkit/i), _isSafari = (_ua.match(/safari/i) && !_ua.match(/chrome/i)), _isOpera = (_ua.match(/opera/i)),
+ _likesHTML5 = (_ua.match(/(mobile|pre\/|xoom)/i) || _is_iDevice),
+ _isBadSafari = (!_wl.match(/usehtml5audio/i) && !_wl.match(/sm2\-ignorebadua/i) && _isSafari && !_ua.match(/silk/i) && _ua.match(/OS X 10_6_([3-7])/i)),
+ _hasConsole = (typeof console !== 'undefined' && typeof console.log !== 'undefined'), _isFocused = (typeof _doc.hasFocus !== 'undefined'?_doc.hasFocus():null), _tryInitOnFocus = (_isSafari && typeof _doc.hasFocus === 'undefined'), _okToDisable = !_tryInitOnFocus, _flashMIME = /(mp3|mp4|mpa)/i,
+ _emptyURL = 'about:blank',
+ _overHTTP = (_doc.location?_doc.location.protocol.match(/http/i):null),
+ _http = (!_overHTTP ? 'http:/'+'/' : ''),
+ _netStreamMimeTypes = /^\s*audio\/(?:x-)?(?:mpeg4|aac|flv|mov|mp4||m4v|m4a|mp4v|3gp|3g2)\s*(?:$|;)/i,
+ _netStreamTypes = ['mpeg4', 'aac', 'flv', 'mov', 'mp4', 'm4v', 'f4v', 'm4a', 'mp4v', '3gp', '3g2'],
+ _netStreamPattern = new RegExp('\\.(' + _netStreamTypes.join('|') + ')(\\?.*)?$', 'i');
+ this.mimePattern = /^\s*audio\/(?:x-)?(?:mp(?:eg|3))\s*(?:$|;)/i;
+ this.useAltURL = !_overHTTP;
+ this._global_a = null;
+ _swfCSS = {
+ 'swfBox': 'sm2-object-box',
+ 'swfDefault': 'movieContainer',
+ 'swfError': 'swf_error',
+ 'swfTimedout': 'swf_timedout',
+ 'swfLoaded': 'swf_loaded',
+ 'swfUnblocked': 'swf_unblocked',
+ 'sm2Debug': 'sm2_debug',
+ 'highPerf': 'high_performance',
+ 'flashDebug': 'flash_debug'
+ };
+ if (_likesHTML5) {
+ _s.useHTML5Audio = true;
+ _s.preferFlash = false;
+ if (_is_iDevice) {
+ _s.ignoreFlash = true;
+ _useGlobalHTML5Audio = true;
+ }
+ }
+ this.ok = function() {
+ return (_needsFlash?(_didInit && !_disabled):(_s.useHTML5Audio && _s.hasHTML5));
+ };
+ this.supported = this.ok;
+ this.getMovie = function(smID) {
+ return _id(smID) || _doc[smID] || _win[smID];
+ };
+ this.createSound = function(oOptions) {
+ var _cs, _cs_string,
+ thisOptions = null, oSound = null, _tO = null;
+ if (!_didInit || !_s.ok()) {
+ _complain(_cs_string);
+ return false;
+ }
+ if (arguments.length === 2) {
+ oOptions = {
+ 'id': arguments[0],
+ 'url': arguments[1]
+ };
+ }
+ thisOptions = _mixin(oOptions);
+ thisOptions.url = _parseURL(thisOptions.url);
+ _tO = thisOptions;
+ if (_idCheck(_tO.id, true)) {
+ return _s.sounds[_tO.id];
+ }
+ function make() {
+ thisOptions = _loopFix(thisOptions);
+ _s.sounds[_tO.id] = new SMSound(_tO);
+ _s.soundIDs.push(_tO.id);
+ return _s.sounds[_tO.id];
+ }
+ if (_html5OK(_tO)) {
+ oSound = make();
+ oSound._setup_html5(_tO);
+ } else {
+ if (_fV > 8) {
+ if (_tO.isMovieStar === null) {
+ _tO.isMovieStar = (_tO.serverURL || (_tO.type ? _tO.type.match(_netStreamMimeTypes) : false) || _tO.url.match(_netStreamPattern));
+ }
+ if (_tO.isMovieStar) {
+ if (_tO.usePeakData) {
+ _tO.usePeakData = false;
+ }
+ }
+ }
+ _tO = _policyFix(_tO, _cs);
+ oSound = make();
+ if (_fV === 8) {
+ _flash._createSound(_tO.id, _tO.loops||1, _tO.usePolicyFile);
+ } else {
+ _flash._createSound(_tO.id, _tO.url, _tO.usePeakData, _tO.useWaveformData, _tO.useEQData, _tO.isMovieStar, (_tO.isMovieStar?_tO.bufferTime:false), _tO.loops||1, _tO.serverURL, _tO.duration||null, _tO.autoPlay, true, _tO.autoLoad, _tO.usePolicyFile);
+ if (!_tO.serverURL) {
+ oSound.connected = true;
+ if (_tO.onconnect) {
+ _tO.onconnect.apply(oSound);
+ }
+ }
+ }
+ if (!_tO.serverURL && (_tO.autoLoad || _tO.autoPlay)) {
+ oSound.load(_tO);
+ }
+ }
+ if (!_tO.serverURL && _tO.autoPlay) {
+ oSound.play();
+ }
+ return oSound;
+ };
+ this.destroySound = function(sID, _bFromSound) {
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ var oS = _s.sounds[sID], i;
+ oS._iO = {};
+ oS.stop();
+ oS.unload();
+ for (i = 0; i < _s.soundIDs.length; i++) {
+ if (_s.soundIDs[i] === sID) {
+ _s.soundIDs.splice(i, 1);
+ break;
+ }
+ }
+ if (!_bFromSound) {
+ oS.destruct(true);
+ }
+ oS = null;
+ delete _s.sounds[sID];
+ return true;
+ };
+ this.load = function(sID, oOptions) {
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].load(oOptions);
+ };
+ this.unload = function(sID) {
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].unload();
+ };
+ this.onPosition = function(sID, nPosition, oMethod, oScope) {
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].onposition(nPosition, oMethod, oScope);
+ };
+ this.onposition = this.onPosition;
+ this.clearOnPosition = function(sID, nPosition, oMethod) {
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].clearOnPosition(nPosition, oMethod);
+ };
+ this.play = function(sID, oOptions) {
+ if (!_didInit || !_s.ok()) {
+ _complain(_sm+'.play(): ' + _str(!_didInit?'notReady':'notOK'));
+ return false;
+ }
+ if (!_idCheck(sID)) {
+ if (!(oOptions instanceof Object)) {
+ oOptions = {
+ url: oOptions
+ };
+ }
+ if (oOptions && oOptions.url) {
+ oOptions.id = sID;
+ return _s.createSound(oOptions).play();
+ } else {
+ return false;
+ }
+ }
+ return _s.sounds[sID].play(oOptions);
+ };
+ this.start = this.play;
+ this.setPosition = function(sID, nMsecOffset) {
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].setPosition(nMsecOffset);
+ };
+ this.stop = function(sID) {
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].stop();
+ };
+ this.stopAll = function() {
+ var oSound;
+ for (oSound in _s.sounds) {
+ if (_s.sounds.hasOwnProperty(oSound)) {
+ _s.sounds[oSound].stop();
+ }
+ }
+ };
+ this.pause = function(sID) {
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].pause();
+ };
+ this.pauseAll = function() {
+ var i;
+ for (i = _s.soundIDs.length; i--;) {
+ _s.sounds[_s.soundIDs[i]].pause();
+ }
+ };
+ this.resume = function(sID) {
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].resume();
+ };
+ this.resumeAll = function() {
+ var i;
+ for (i = _s.soundIDs.length; i--;) {
+ _s.sounds[_s.soundIDs[i]].resume();
+ }
+ };
+ this.togglePause = function(sID) {
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].togglePause();
+ };
+ this.setPan = function(sID, nPan) {
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].setPan(nPan);
+ };
+ this.setVolume = function(sID, nVol) {
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].setVolume(nVol);
+ };
+ this.mute = function(sID) {
+ var i = 0;
+ if (typeof sID !== 'string') {
+ sID = null;
+ }
+ if (!sID) {
+ for (i = _s.soundIDs.length; i--;) {
+ _s.sounds[_s.soundIDs[i]].mute();
+ }
+ _s.muted = true;
+ } else {
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].mute();
+ }
+ return true;
+ };
+ this.muteAll = function() {
+ _s.mute();
+ };
+ this.unmute = function(sID) {
+ var i;
+ if (typeof sID !== 'string') {
+ sID = null;
+ }
+ if (!sID) {
+ for (i = _s.soundIDs.length; i--;) {
+ _s.sounds[_s.soundIDs[i]].unmute();
+ }
+ _s.muted = false;
+ } else {
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].unmute();
+ }
+ return true;
+ };
+ this.unmuteAll = function() {
+ _s.unmute();
+ };
+ this.toggleMute = function(sID) {
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].toggleMute();
+ };
+ this.getMemoryUse = function() {
+ var ram = 0;
+ if (_flash && _fV !== 8) {
+ ram = parseInt(_flash._getMemoryUse(), 10);
+ }
+ return ram;
+ };
+ this.disable = function(bNoDisable) {
+ var i;
+ if (typeof bNoDisable === 'undefined') {
+ bNoDisable = false;
+ }
+ if (_disabled) {
+ return false;
+ }
+ _disabled = true;
+ for (i = _s.soundIDs.length; i--;) {
+ _disableObject(_s.sounds[_s.soundIDs[i]]);
+ }
+ _initComplete(bNoDisable);
+ _event.remove(_win, 'load', _initUserOnload);
+ return true;
+ };
+ this.canPlayMIME = function(sMIME) {
+ var result;
+ if (_s.hasHTML5) {
+ result = _html5CanPlay({type:sMIME});
+ }
+ if (!_needsFlash || result) {
+ return result;
+ } else {
+ return (sMIME ? !!((_fV > 8 ? sMIME.match(_netStreamMimeTypes) : null) || sMIME.match(_s.mimePattern)) : null);
+ }
+ };
+ this.canPlayURL = function(sURL) {
+ var result;
+ if (_s.hasHTML5) {
+ result = _html5CanPlay({url: sURL});
+ }
+ if (!_needsFlash || result) {
+ return result;
+ } else {
+ return (sURL ? !!(sURL.match(_s.filePattern)) : null);
+ }
+ };
+ this.canPlayLink = function(oLink) {
+ if (typeof oLink.type !== 'undefined' && oLink.type) {
+ if (_s.canPlayMIME(oLink.type)) {
+ return true;
+ }
+ }
+ return _s.canPlayURL(oLink.href);
+ };
+ this.getSoundById = function(sID, _suppressDebug) {
+ if (!sID) {
+ throw new Error(_sm+'.getSoundById(): sID is null/undefined');
+ }
+ var result = _s.sounds[sID];
+ return result;
+ };
+ this.onready = function(oMethod, oScope) {
+ var sType = 'onready';
+ if (oMethod && oMethod instanceof Function) {
+ if (!oScope) {
+ oScope = _win;
+ }
+ _addOnEvent(sType, oMethod, oScope);
+ _processOnEvents();
+ return true;
+ } else {
+ throw _str('needFunction', sType);
+ }
+ };
+ this.ontimeout = function(oMethod, oScope) {
+ var sType = 'ontimeout';
+ if (oMethod && oMethod instanceof Function) {
+ if (!oScope) {
+ oScope = _win;
+ }
+ _addOnEvent(sType, oMethod, oScope);
+ _processOnEvents({type:sType});
+ return true;
+ } else {
+ throw _str('needFunction', sType);
+ }
+ };
+ this._writeDebug = function(sText, sType, _bTimestamp) {
+ return true;
+ };
+ this._wD = this._writeDebug;
+ this._debug = function() {
+ };
+ this.reboot = function() {
+ var i, j;
+ for (i = _s.soundIDs.length; i--;) {
+ _s.sounds[_s.soundIDs[i]].destruct();
+ }
+ try {
+ if (_isIE) {
+ _oRemovedHTML = _flash.innerHTML;
+ }
+ _oRemoved = _flash.parentNode.removeChild(_flash);
+ } catch(e) {
+ }
+ _oRemovedHTML = _oRemoved = _needsFlash = null;
+ _s.enabled = _didDCLoaded = _didInit = _waitingForEI = _initPending = _didAppend = _appendSuccess = _disabled = _s.swfLoaded = false;
+ _s.soundIDs = _s.sounds = [];
+ _flash = null;
+ for (i in _on_queue) {
+ if (_on_queue.hasOwnProperty(i)) {
+ for (j = _on_queue[i].length; j--;) {
+ _on_queue[i][j].fired = false;
+ }
+ }
+ }
+ _win.setTimeout(_s.beginDelayedInit, 20);
+ };
+ this.getMoviePercent = function() {
+ return (_flash && typeof _flash.PercentLoaded !== 'undefined' ? _flash.PercentLoaded() : null);
+ };
+ this.beginDelayedInit = function() {
+ _windowLoaded = true;
+ _domContentLoaded();
+ setTimeout(function() {
+ if (_initPending) {
+ return false;
+ }
+ _createMovie();
+ _initMovie();
+ _initPending = true;
+ return true;
+ }, 20);
+ _delayWaitForEI();
+ };
+ this.destruct = function() {
+ _s.disable(true);
+ };
+ SMSound = function(oOptions) {
+ var _t = this, _resetProperties, _add_html5_events, _remove_html5_events, _stop_html5_timer, _start_html5_timer, _attachOnPosition, _onplay_called = false, _onPositionItems = [], _onPositionFired = 0, _detachOnPosition, _applyFromTo, _lastURL = null;
+ var _lastHTML5State = {
+ duration: null,
+ time: null
+ };
+ this.sID = oOptions.id;
+ this.url = oOptions.url;
+ this.options = _mixin(oOptions);
+ this.instanceOptions = this.options;
+ this._iO = this.instanceOptions;
+ this.pan = this.options.pan;
+ this.volume = this.options.volume;
+ this.isHTML5 = false;
+ this._a = null;
+ this.id3 = {};
+ this._debug = function() {
+ };
+ this.load = function(oOptions) {
+ var oS = null, _iO;
+ if (typeof oOptions !== 'undefined') {
+ _t._iO = _mixin(oOptions, _t.options);
+ _t.instanceOptions = _t._iO;
+ } else {
+ oOptions = _t.options;
+ _t._iO = oOptions;
+ _t.instanceOptions = _t._iO;
+ if (_lastURL && _lastURL !== _t.url) {
+ _t._iO.url = _t.url;
+ _t.url = null;
+ }
+ }
+ if (!_t._iO.url) {
+ _t._iO.url = _t.url;
+ }
+ _t._iO.url = _parseURL(_t._iO.url);
+ if (_t._iO.url === _t.url && _t.readyState !== 0 && _t.readyState !== 2) {
+ if (_t.readyState === 3 && _t._iO.onload) {
+ _t._iO.onload.apply(_t, [(!!_t.duration)]);
+ }
+ return _t;
+ }
+ _iO = _t._iO;
+ _lastURL = _t.url;
+ _t.loaded = false;
+ _t.readyState = 1;
+ _t.playState = 0;
+ if (_html5OK(_iO)) {
+ oS = _t._setup_html5(_iO);
+ if (!oS._called_load) {
+ _t._html5_canplay = false;
+ _t._a.autobuffer = 'auto';
+ _t._a.preload = 'auto';
+ oS.load();
+ oS._called_load = true;
+ if (_iO.autoPlay) {
+ _t.play();
+ }
+ } else {
+ }
+ } else {
+ try {
+ _t.isHTML5 = false;
+ _t._iO = _policyFix(_loopFix(_iO));
+ _iO = _t._iO;
+ if (_fV === 8) {
+ _flash._load(_t.sID, _iO.url, _iO.stream, _iO.autoPlay, (_iO.whileloading?1:0), _iO.loops||1, _iO.usePolicyFile);
+ } else {
+ _flash._load(_t.sID, _iO.url, !!(_iO.stream), !!(_iO.autoPlay), _iO.loops||1, !!(_iO.autoLoad), _iO.usePolicyFile);
+ }
+ } catch(e) {
+ _catchError({type:'SMSOUND_LOAD_JS_EXCEPTION', fatal:true});
+ }
+ }
+ return _t;
+ };
+ this.unload = function() {
+ if (_t.readyState !== 0) {
+ if (!_t.isHTML5) {
+ if (_fV === 8) {
+ _flash._unload(_t.sID, _emptyURL);
+ } else {
+ _flash._unload(_t.sID);
+ }
+ } else {
+ _stop_html5_timer();
+ if (_t._a) {
+ _t._a.pause();
+ _html5Unload(_t._a);
+ }
+ }
+ _resetProperties();
+ }
+ return _t;
+ };
+ this.destruct = function(_bFromSM) {
+ if (!_t.isHTML5) {
+ _t._iO.onfailure = null;
+ _flash._destroySound(_t.sID);
+ } else {
+ _stop_html5_timer();
+ if (_t._a) {
+ _t._a.pause();
+ _html5Unload(_t._a);
+ if (!_useGlobalHTML5Audio) {
+ _remove_html5_events();
+ }
+ _t._a._t = null;
+ _t._a = null;
+ }
+ }
+ if (!_bFromSM) {
+ _s.destroySound(_t.sID, true);
+ }
+ };
+ this.play = function(oOptions, _updatePlayState) {
+ var fN, allowMulti, a, onready;
+ _updatePlayState = _updatePlayState === undefined ? true : _updatePlayState;
+ if (!oOptions) {
+ oOptions = {};
+ }
+ _t._iO = _mixin(oOptions, _t._iO);
+ _t._iO = _mixin(_t._iO, _t.options);
+ _t._iO.url = _parseURL(_t._iO.url);
+ _t.instanceOptions = _t._iO;
+ if (_t._iO.serverURL && !_t.connected) {
+ if (!_t.getAutoPlay()) {
+ _t.setAutoPlay(true);
+ }
+ return _t;
+ }
+ if (_html5OK(_t._iO)) {
+ _t._setup_html5(_t._iO);
+ _start_html5_timer();
+ }
+ if (_t.playState === 1 && !_t.paused) {
+ allowMulti = _t._iO.multiShot;
+ if (!allowMulti) {
+ return _t;
+ } else {
+ }
+ }
+ if (!_t.loaded) {
+ if (_t.readyState === 0) {
+ if (!_t.isHTML5) {
+ _t._iO.autoPlay = true;
+ }
+ _t.load(_t._iO);
+ } else if (_t.readyState === 2) {
+ return _t;
+ } else {
+ }
+ } else {
+ }
+ if (!_t.isHTML5 && _fV === 9 && _t.position > 0 && _t.position === _t.duration) {
+ oOptions.position = 0;
+ }
+ if (_t.paused && _t.position && _t.position > 0) {
+ _t.resume();
+ } else {
+ _t._iO = _mixin(oOptions, _t._iO);
+ if (_t._iO.from !== null && _t._iO.to !== null && _t.instanceCount === 0 && _t.playState === 0 && !_t._iO.serverURL) {
+ onready = function() {
+ _t._iO = _mixin(oOptions, _t._iO);
+ _t.play(_t._iO);
+ };
+ if (_t.isHTML5 && !_t._html5_canplay) {
+ _t.load({
+ _oncanplay: onready
+ });
+ return false;
+ } else if (!_t.isHTML5 && !_t.loaded && (!_t.readyState || _t.readyState !== 2)) {
+ _t.load({
+ onload: onready
+ });
+ return false;
+ }
+ _t._iO = _applyFromTo();
+ }
+ if (!_t.instanceCount || _t._iO.multiShotEvents || (!_t.isHTML5 && _fV > 8 && !_t.getAutoPlay())) {
+ _t.instanceCount++;
+ }
+ if (_t.playState === 0 && _t._iO.onposition) {
+ _attachOnPosition(_t);
+ }
+ _t.playState = 1;
+ _t.paused = false;
+ _t.position = (typeof _t._iO.position !== 'undefined' && !isNaN(_t._iO.position) ? _t._iO.position : 0);
+ if (!_t.isHTML5) {
+ _t._iO = _policyFix(_loopFix(_t._iO));
+ }
+ if (_t._iO.onplay && _updatePlayState) {
+ _t._iO.onplay.apply(_t);
+ _onplay_called = true;
+ }
+ _t.setVolume(_t._iO.volume, true);
+ _t.setPan(_t._iO.pan, true);
+ if (!_t.isHTML5) {
+ _flash._start(_t.sID, _t._iO.loops || 1, (_fV === 9?_t._iO.position:_t._iO.position / 1000));
+ } else {
+ _start_html5_timer();
+ a = _t._setup_html5();
+ _t.setPosition(_t._iO.position);
+ a.play();
+ }
+ }
+ return _t;
+ };
+ this.start = this.play;
+ this.stop = function(bAll) {
+ var _iO = _t._iO, _oP;
+ if (_t.playState === 1) {
+ _t._onbufferchange(0);
+ _t._resetOnPosition(0);
+ _t.paused = false;
+ if (!_t.isHTML5) {
+ _t.playState = 0;
+ }
+ _detachOnPosition();
+ if (_iO.to) {
+ _t.clearOnPosition(_iO.to);
+ }
+ if (!_t.isHTML5) {
+ _flash._stop(_t.sID, bAll);
+ if (_iO.serverURL) {
+ _t.unload();
+ }
+ } else {
+ if (_t._a) {
+ _oP = _t.position;
+ _t.setPosition(0);
+ _t.position = _oP;
+ _t._a.pause();
+ _t.playState = 0;
+ _t._onTimer();
+ _stop_html5_timer();
+ }
+ }
+ _t.instanceCount = 0;
+ _t._iO = {};
+ if (_iO.onstop) {
+ _iO.onstop.apply(_t);
+ }
+ }
+ return _t;
+ };
+ this.setAutoPlay = function(autoPlay) {
+ _t._iO.autoPlay = autoPlay;
+ if (!_t.isHTML5) {
+ _flash._setAutoPlay(_t.sID, autoPlay);
+ if (autoPlay) {
+ if (!_t.instanceCount && _t.readyState === 1) {
+ _t.instanceCount++;
+ }
+ }
+ }
+ };
+ this.getAutoPlay = function() {
+ return _t._iO.autoPlay;
+ };
+ this.setPosition = function(nMsecOffset) {
+ if (nMsecOffset === undefined) {
+ nMsecOffset = 0;
+ }
+ var original_pos,
+ position, position1K,
+ offset = (_t.isHTML5 ? Math.max(nMsecOffset,0) : Math.min(_t.duration || _t._iO.duration, Math.max(nMsecOffset, 0)));
+ original_pos = _t.position;
+ _t.position = offset;
+ position1K = _t.position/1000;
+ _t._resetOnPosition(_t.position);
+ _t._iO.position = offset;
+ if (!_t.isHTML5) {
+ position = (_fV === 9 ? _t.position : position1K);
+ if (_t.readyState && _t.readyState !== 2) {
+ _flash._setPosition(_t.sID, position, (_t.paused || !_t.playState));
+ }
+ } else if (_t._a) {
+ if (_t._html5_canplay) {
+ if (_t._a.currentTime !== position1K) {
+ try {
+ _t._a.currentTime = position1K;
+ if (_t.playState === 0 || _t.paused) {
+ _t._a.pause();
+ }
+ } catch(e) {
+ }
+ }
+ } else {
+ }
+ }
+ if (_t.isHTML5) {
+ if (_t.paused) {
+ _t._onTimer(true);
+ }
+ }
+ return _t;
+ };
+ this.pause = function(_bCallFlash) {
+ if (_t.paused || (_t.playState === 0 && _t.readyState !== 1)) {
+ return _t;
+ }
+ _t.paused = true;
+ if (!_t.isHTML5) {
+ if (_bCallFlash || _bCallFlash === undefined) {
+ _flash._pause(_t.sID);
+ }
+ } else {
+ _t._setup_html5().pause();
+ _stop_html5_timer();
+ }
+ if (_t._iO.onpause) {
+ _t._iO.onpause.apply(_t);
+ }
+ return _t;
+ };
+ this.resume = function() {
+ var _iO = _t._iO;
+ if (!_t.paused) {
+ return _t;
+ }
+ _t.paused = false;
+ _t.playState = 1;
+ if (!_t.isHTML5) {
+ if (_iO.isMovieStar && !_iO.serverURL) {
+ _t.setPosition(_t.position);
+ }
+ _flash._pause(_t.sID);
+ } else {
+ _t._setup_html5().play();
+ _start_html5_timer();
+ }
+ if (_onplay_called && _iO.onplay) {
+ _iO.onplay.apply(_t);
+ _onplay_called = true;
+ } else if (_iO.onresume) {
+ _iO.onresume.apply(_t);
+ }
+ return _t;
+ };
+ this.togglePause = function() {
+ if (_t.playState === 0) {
+ _t.play({
+ position: (_fV === 9 && !_t.isHTML5 ? _t.position : _t.position / 1000)
+ });
+ return _t;
+ }
+ if (_t.paused) {
+ _t.resume();
+ } else {
+ _t.pause();
+ }
+ return _t;
+ };
+ this.setPan = function(nPan, bInstanceOnly) {
+ if (typeof nPan === 'undefined') {
+ nPan = 0;
+ }
+ if (typeof bInstanceOnly === 'undefined') {
+ bInstanceOnly = false;
+ }
+ if (!_t.isHTML5) {
+ _flash._setPan(_t.sID, nPan);
+ }
+ _t._iO.pan = nPan;
+ if (!bInstanceOnly) {
+ _t.pan = nPan;
+ _t.options.pan = nPan;
+ }
+ return _t;
+ };
+ this.setVolume = function(nVol, _bInstanceOnly) {
+ if (typeof nVol === 'undefined') {
+ nVol = 100;
+ }
+ if (typeof _bInstanceOnly === 'undefined') {
+ _bInstanceOnly = false;
+ }
+ if (!_t.isHTML5) {
+ _flash._setVolume(_t.sID, (_s.muted && !_t.muted) || _t.muted?0:nVol);
+ } else if (_t._a) {
+ _t._a.volume = Math.max(0, Math.min(1, nVol/100));
+ }
+ _t._iO.volume = nVol;
+ if (!_bInstanceOnly) {
+ _t.volume = nVol;
+ _t.options.volume = nVol;
+ }
+ return _t;
+ };
+ this.mute = function() {
+ _t.muted = true;
+ if (!_t.isHTML5) {
+ _flash._setVolume(_t.sID, 0);
+ } else if (_t._a) {
+ _t._a.muted = true;
+ }
+ return _t;
+ };
+ this.unmute = function() {
+ _t.muted = false;
+ var hasIO = typeof _t._iO.volume !== 'undefined';
+ if (!_t.isHTML5) {
+ _flash._setVolume(_t.sID, hasIO?_t._iO.volume:_t.options.volume);
+ } else if (_t._a) {
+ _t._a.muted = false;
+ }
+ return _t;
+ };
+ this.toggleMute = function() {
+ return (_t.muted?_t.unmute():_t.mute());
+ };
+ this.onPosition = function(nPosition, oMethod, oScope) {
+ _onPositionItems.push({
+ position: nPosition,
+ method: oMethod,
+ scope: (typeof oScope !== 'undefined' ? oScope : _t),
+ fired: false
+ });
+ return _t;
+ };
+ this.onposition = this.onPosition;
+ this.clearOnPosition = function(nPosition, oMethod) {
+ var i;
+ nPosition = parseInt(nPosition, 10);
+ if (isNaN(nPosition)) {
+ return false;
+ }
+ for (i=0; i < _onPositionItems.length; i++) {
+ if (nPosition === _onPositionItems[i].position) {
+ if (!oMethod || (oMethod === _onPositionItems[i].method)) {
+ if (_onPositionItems[i].fired) {
+ _onPositionFired--;
+ }
+ _onPositionItems.splice(i, 1);
+ }
+ }
+ }
+ };
+ this._processOnPosition = function() {
+ var i, item, j = _onPositionItems.length;
+ if (!j || !_t.playState || _onPositionFired >= j) {
+ return false;
+ }
+ for (i=j; i--;) {
+ item = _onPositionItems[i];
+ if (!item.fired && _t.position >= item.position) {
+ item.fired = true;
+ _onPositionFired++;
+ item.method.apply(item.scope, [item.position]);
+ }
+ }
+ return true;
+ };
+ this._resetOnPosition = function(nPosition) {
+ var i, item, j = _onPositionItems.length;
+ if (!j) {
+ return false;
+ }
+ for (i=j; i--;) {
+ item = _onPositionItems[i];
+ if (item.fired && nPosition <= item.position) {
+ item.fired = false;
+ _onPositionFired--;
+ }
+ }
+ return true;
+ };
+ _applyFromTo = function() {
+ var _iO = _t._iO,
+ f = _iO.from,
+ t = _iO.to,
+ start, end;
+ end = function() {
+ _t.clearOnPosition(t, end);
+ _t.stop();
+ };
+ start = function() {
+ if (t !== null && !isNaN(t)) {
+ _t.onPosition(t, end);
+ }
+ };
+ if (f !== null && !isNaN(f)) {
+ _iO.position = f;
+ _iO.multiShot = false;
+ start();
+ }
+ return _iO;
+ };
+ _attachOnPosition = function() {
+ var op = _t._iO.onposition;
+ if (op) {
+ var item;
+ for (item in op) {
+ if (op.hasOwnProperty(item)) {
+ _t.onPosition(parseInt(item, 10), op[item]);
+ }
+ }
+ }
+ };
+ _detachOnPosition = function() {
+ var op = _t._iO.onposition;
+ if (op) {
+ var item;
+ for (item in op) {
+ if (op.hasOwnProperty(item)) {
+ _t.clearOnPosition(parseInt(item, 10));
+ }
+ }
+ }
+ };
+ _start_html5_timer = function() {
+ if (_t.isHTML5) {
+ _startTimer(_t);
+ }
+ };
+ _stop_html5_timer = function() {
+ if (_t.isHTML5) {
+ _stopTimer(_t);
+ }
+ };
+ _resetProperties = function() {
+ _onPositionItems = [];
+ _onPositionFired = 0;
+ _onplay_called = false;
+ _t._hasTimer = null;
+ _t._a = null;
+ _t._html5_canplay = false;
+ _t.bytesLoaded = null;
+ _t.bytesTotal = null;
+ _t.duration = (_t._iO && _t._iO.duration ? _t._iO.duration : null);
+ _t.durationEstimate = null;
+ _t.eqData = [];
+ _t.eqData.left = [];
+ _t.eqData.right = [];
+ _t.failures = 0;
+ _t.isBuffering = false;
+ _t.instanceOptions = {};
+ _t.instanceCount = 0;
+ _t.loaded = false;
+ _t.metadata = {};
+ _t.readyState = 0;
+ _t.muted = false;
+ _t.paused = false;
+ _t.peakData = {
+ left: 0,
+ right: 0
+ };
+ _t.waveformData = {
+ left: [],
+ right: []
+ };
+ _t.playState = 0;
+ _t.position = null;
+ };
+ _resetProperties();
+ this._onTimer = function(bForce) {
+ var duration, isNew = false, time, x = {};
+ if (_t._hasTimer || bForce) {
+ if (_t._a && (bForce || ((_t.playState > 0 || _t.readyState === 1) && !_t.paused))) {
+ duration = _t._get_html5_duration();
+ if (duration !== _lastHTML5State.duration) {
+ _lastHTML5State.duration = duration;
+ _t.duration = duration;
+ isNew = true;
+ }
+ _t.durationEstimate = _t.duration;
+ time = (_t._a.currentTime * 1000 || 0);
+ if (time !== _lastHTML5State.time) {
+ _lastHTML5State.time = time;
+ isNew = true;
+ }
+ if (isNew || bForce) {
+ _t._whileplaying(time,x,x,x,x);
+ }
+ return isNew;
+ } else {
+ return false;
+ }
+ }
+ };
+ this._get_html5_duration = function() {
+ var _iO = _t._iO,
+ d = (_t._a ? _t._a.duration*1000 : (_iO ? _iO.duration : undefined)),
+ result = (d && !isNaN(d) && d !== Infinity ? d : (_iO ? _iO.duration : null));
+ return result;
+ };
+ this._setup_html5 = function(oOptions) {
+ var _iO = _mixin(_t._iO, oOptions), d = decodeURI,
+ _a = _useGlobalHTML5Audio ? _s._global_a : _t._a,
+ _dURL = d(_iO.url),
+ _oldIO = (_a && _a._t ? _a._t.instanceOptions : null);
+ if (_a) {
+ if (_a._t) {
+ if (!_useGlobalHTML5Audio && _dURL === d(_lastURL)) {
+ return _a;
+ } else if (_useGlobalHTML5Audio && _oldIO.url === _iO.url && (!_lastURL || (_lastURL === _oldIO.url))) {
+ return _a;
+ }
+ }
+ if (_useGlobalHTML5Audio && _a._t && _a._t.playState && _iO.url !== _oldIO.url) {
+ _a._t.stop();
+ }
+ _resetProperties();
+ _a.src = _iO.url;
+ _t.url = _iO.url;
+ _lastURL = _iO.url;
+ _a._called_load = false;
+ } else {
+ _a = new Audio(_iO.url);
+ _a._called_load = false;
+ if (_is_android) {
+ _a._called_load = true;
+ }
+ if (_useGlobalHTML5Audio) {
+ _s._global_a = _a;
+ }
+ }
+ _t.isHTML5 = true;
+ _t._a = _a;
+ _a._t = _t;
+ _add_html5_events();
+ _a.loop = (_iO.loops>1?'loop':'');
+ if (_iO.autoLoad || _iO.autoPlay) {
+ _t.load();
+ } else {
+ _a.autobuffer = false;
+ _a.preload = 'none';
+ }
+ _a.loop = (_iO.loops > 1 ? 'loop' : '');
+ return _a;
+ };
+ _add_html5_events = function() {
+ if (_t._a._added_events) {
+ return false;
+ }
+ var f;
+ function add(oEvt, oFn, bCapture) {
+ return _t._a ? _t._a.addEventListener(oEvt, oFn, bCapture||false) : null;
+ }
+ _t._a._added_events = true;
+ for (f in _html5_events) {
+ if (_html5_events.hasOwnProperty(f)) {
+ add(f, _html5_events[f]);
+ }
+ }
+ return true;
+ };
+ _remove_html5_events = function() {
+ var f;
+ function remove(oEvt, oFn, bCapture) {
+ return (_t._a ? _t._a.removeEventListener(oEvt, oFn, bCapture||false) : null);
+ }
+ _t._a._added_events = false;
+ for (f in _html5_events) {
+ if (_html5_events.hasOwnProperty(f)) {
+ remove(f, _html5_events[f]);
+ }
+ }
+ };
+ this._onload = function(nSuccess) {
+ var fN, loadOK = !!(nSuccess);
+ _t.loaded = loadOK;
+ _t.readyState = loadOK?3:2;
+ _t._onbufferchange(0);
+ if (_t._iO.onload) {
+ _t._iO.onload.apply(_t, [loadOK]);
+ }
+ return true;
+ };
+ this._onbufferchange = function(nIsBuffering) {
+ if (_t.playState === 0) {
+ return false;
+ }
+ if ((nIsBuffering && _t.isBuffering) || (!nIsBuffering && !_t.isBuffering)) {
+ return false;
+ }
+ _t.isBuffering = (nIsBuffering === 1);
+ if (_t._iO.onbufferchange) {
+ _t._iO.onbufferchange.apply(_t);
+ }
+ return true;
+ };
+ this._onsuspend = function() {
+ if (_t._iO.onsuspend) {
+ _t._iO.onsuspend.apply(_t);
+ }
+ return true;
+ };
+ this._onfailure = function(msg, level, code) {
+ _t.failures++;
+ if (_t._iO.onfailure && _t.failures === 1) {
+ _t._iO.onfailure(_t, msg, level, code);
+ } else {
+ }
+ };
+ this._onfinish = function() {
+ var _io_onfinish = _t._iO.onfinish;
+ _t._onbufferchange(0);
+ _t._resetOnPosition(0);
+ if (_t.instanceCount) {
+ _t.instanceCount--;
+ if (!_t.instanceCount) {
+ _detachOnPosition();
+ _t.playState = 0;
+ _t.paused = false;
+ _t.instanceCount = 0;
+ _t.instanceOptions = {};
+ _t._iO = {};
+ _stop_html5_timer();
+ }
+ if (!_t.instanceCount || _t._iO.multiShotEvents) {
+ if (_io_onfinish) {
+ _io_onfinish.apply(_t);
+ }
+ }
+ }
+ };
+ this._whileloading = function(nBytesLoaded, nBytesTotal, nDuration, nBufferLength) {
+ var _iO = _t._iO;
+ _t.bytesLoaded = nBytesLoaded;
+ _t.bytesTotal = nBytesTotal;
+ _t.duration = Math.floor(nDuration);
+ _t.bufferLength = nBufferLength;
+ if (!_iO.isMovieStar) {
+ if (_iO.duration) {
+ _t.durationEstimate = (_t.duration > _iO.duration) ? _t.duration : _iO.duration;
+ } else {
+ _t.durationEstimate = parseInt((_t.bytesTotal / _t.bytesLoaded) * _t.duration, 10);
+ }
+ if (_t.durationEstimate === undefined) {
+ _t.durationEstimate = _t.duration;
+ }
+ if (_t.readyState !== 3 && _iO.whileloading) {
+ _iO.whileloading.apply(_t);
+ }
+ } else {
+ _t.durationEstimate = _t.duration;
+ if (_t.readyState !== 3 && _iO.whileloading) {
+ _iO.whileloading.apply(_t);
+ }
+ }
+ };
+ this._whileplaying = function(nPosition, oPeakData, oWaveformDataLeft, oWaveformDataRight, oEQData) {
+ var _iO = _t._iO;
+ if (isNaN(nPosition) || nPosition === null) {
+ return false;
+ }
+ _t.position = nPosition;
+ _t._processOnPosition();
+ if (!_t.isHTML5 && _fV > 8) {
+ if (_iO.usePeakData && typeof oPeakData !== 'undefined' && oPeakData) {
+ _t.peakData = {
+ left: oPeakData.leftPeak,
+ right: oPeakData.rightPeak
+ };
+ }
+ if (_iO.useWaveformData && typeof oWaveformDataLeft !== 'undefined' && oWaveformDataLeft) {
+ _t.waveformData = {
+ left: oWaveformDataLeft.split(','),
+ right: oWaveformDataRight.split(',')
+ };
+ }
+ if (_iO.useEQData) {
+ if (typeof oEQData !== 'undefined' && oEQData && oEQData.leftEQ) {
+ var eqLeft = oEQData.leftEQ.split(',');
+ _t.eqData = eqLeft;
+ _t.eqData.left = eqLeft;
+ if (typeof oEQData.rightEQ !== 'undefined' && oEQData.rightEQ) {
+ _t.eqData.right = oEQData.rightEQ.split(',');
+ }
+ }
+ }
+ }
+ if (_t.playState === 1) {
+ if (!_t.isHTML5 && _fV === 8 && !_t.position && _t.isBuffering) {
+ _t._onbufferchange(0);
+ }
+ if (_iO.whileplaying) {
+ _iO.whileplaying.apply(_t);
+ }
+ }
+ return true;
+ };
+ this._onmetadata = function(oMDProps, oMDData) {
+ var oData = {}, i, j;
+ for (i = 0, j = oMDProps.length; i < j; i++) {
+ oData[oMDProps[i]] = oMDData[i];
+ }
+ _t.metadata = oData;
+ if (_t._iO.onmetadata) {
+ _t._iO.onmetadata.apply(_t);
+ }
+ };
+ this._onid3 = function(oID3Props, oID3Data) {
+ var oData = [], i, j;
+ for (i = 0, j = oID3Props.length; i < j; i++) {
+ oData[oID3Props[i]] = oID3Data[i];
+ }
+ _t.id3 = _mixin(_t.id3, oData);
+ if (_t._iO.onid3) {
+ _t._iO.onid3.apply(_t);
+ }
+ };
+ this._onconnect = function(bSuccess) {
+ bSuccess = (bSuccess === 1);
+ _t.connected = bSuccess;
+ if (bSuccess) {
+ _t.failures = 0;
+ if (_idCheck(_t.sID)) {
+ if (_t.getAutoPlay()) {
+ _t.play(undefined, _t.getAutoPlay());
+ } else if (_t._iO.autoLoad) {
+ _t.load();
+ }
+ }
+ if (_t._iO.onconnect) {
+ _t._iO.onconnect.apply(_t, [bSuccess]);
+ }
+ }
+ };
+ this._ondataerror = function(sError) {
+ if (_t.playState > 0) {
+ if (_t._iO.ondataerror) {
+ _t._iO.ondataerror.apply(_t);
+ }
+ }
+ };
+ };
+ _getDocument = function() {
+ return (_doc.body || _doc._docElement || _doc.getElementsByTagName('div')[0]);
+ };
+ _id = function(sID) {
+ return _doc.getElementById(sID);
+ };
+ _mixin = function(oMain, oAdd) {
+ var o1 = {}, i, o2, o;
+ for (i in oMain) {
+ if (oMain.hasOwnProperty(i)) {
+ o1[i] = oMain[i];
+ }
+ }
+ o2 = (typeof oAdd === 'undefined'?_s.defaultOptions:oAdd);
+ for (o in o2) {
+ if (o2.hasOwnProperty(o) && typeof o1[o] === 'undefined') {
+ o1[o] = o2[o];
+ }
+ }
+ return o1;
+ };
+ _event = (function() {
+ var old = (_win.attachEvent),
+ evt = {
+ add: (old?'attachEvent':'addEventListener'),
+ remove: (old?'detachEvent':'removeEventListener')
+ };
+ function getArgs(oArgs) {
+ var args = _slice.call(oArgs), len = args.length;
+ if (old) {
+ args[1] = 'on' + args[1];
+ if (len > 3) {
+ args.pop();
+ }
+ } else if (len === 3) {
+ args.push(false);
+ }
+ return args;
+ }
+ function apply(args, sType) {
+ var element = args.shift(),
+ method = [evt[sType]];
+ if (old) {
+ element[method](args[0], args[1]);
+ } else {
+ element[method].apply(element, args);
+ }
+ }
+ function add() {
+ apply(getArgs(arguments), 'add');
+ }
+ function remove() {
+ apply(getArgs(arguments), 'remove');
+ }
+ return {
+ 'add': add,
+ 'remove': remove
+ };
+ }());
+ function _html5_event(oFn) {
+ return function(e) {
+ var t = this._t;
+ if (!t || !t._a) {
+ return null;
+ } else {
+ return oFn.call(this, e);
+ }
+ };
+ }
+ _html5_events = {
+ abort: _html5_event(function(e) {
+ }),
+ canplay: _html5_event(function(e) {
+ var t = this._t;
+ if (t._html5_canplay) {
+ return true;
+ }
+ t._html5_canplay = true;
+ t._onbufferchange(0);
+ var position1K = (!isNaN(t.position)?t.position/1000:null);
+ if (t.position && this.currentTime !== position1K) {
+ try {
+ this.currentTime = position1K;
+ } catch(ee) {
+ }
+ }
+ if (t._iO._oncanplay) {
+ t._iO._oncanplay();
+ }
+ }),
+ load: _html5_event(function(e) {
+ var t = this._t;
+ if (!t.loaded) {
+ t._onbufferchange(0);
+ t._whileloading(t.bytesTotal, t.bytesTotal, t._get_html5_duration());
+ t._onload(true);
+ }
+ }),
+ emptied: _html5_event(function(e) {
+ }),
+ ended: _html5_event(function(e) {
+ var t = this._t;
+ t._onfinish();
+ }),
+ error: _html5_event(function(e) {
+ this._t._onload(false);
+ }),
+ loadeddata: _html5_event(function(e) {
+ var t = this._t,
+ bytesTotal = t.bytesTotal || 1;
+ if (!t._loaded && !_isSafari) {
+ t.duration = t._get_html5_duration();
+ t._whileloading(bytesTotal, bytesTotal, t._get_html5_duration());
+ t._onload(true);
+ }
+ }),
+ loadedmetadata: _html5_event(function(e) {
+ }),
+ loadstart: _html5_event(function(e) {
+ this._t._onbufferchange(1);
+ }),
+ play: _html5_event(function(e) {
+ this._t._onbufferchange(0);
+ }),
+ playing: _html5_event(function(e) {
+ this._t._onbufferchange(0);
+ }),
+ progress: _html5_event(function(e) {
+ var t = this._t;
+ if (t.loaded) {
+ return false;
+ }
+ var i, j, str, buffered = 0,
+ isProgress = (e.type === 'progress'),
+ ranges = e.target.buffered,
+ loaded = (e.loaded||0),
+ total = (e.total||1);
+ if (ranges && ranges.length) {
+ for (i=ranges.length; i--;) {
+ buffered = (ranges.end(i) - ranges.start(i));
+ }
+ loaded = buffered/e.target.duration;
+ }
+ if (!isNaN(loaded)) {
+ t._onbufferchange(0);
+ t._whileloading(loaded, total, t._get_html5_duration());
+ if (loaded && total && loaded === total) {
+ _html5_events.load.call(this, e);
+ }
+ }
+ }),
+ ratechange: _html5_event(function(e) {
+ }),
+ suspend: _html5_event(function(e) {
+ var t = this._t;
+ _html5_events.progress.call(this, e);
+ t._onsuspend();
+ }),
+ stalled: _html5_event(function(e) {
+ }),
+ timeupdate: _html5_event(function(e) {
+ this._t._onTimer();
+ }),
+ waiting: _html5_event(function(e) {
+ var t = this._t;
+ t._onbufferchange(1);
+ })
+ };
+ _html5OK = function(iO) {
+ return (!iO.serverURL && (iO.type?_html5CanPlay({type:iO.type}):_html5CanPlay({url:iO.url})||_s.html5Only));
+ };
+ _html5Unload = function(oAudio) {
+ if (oAudio) {
+ oAudio.src = (_is_firefox ? '' : _emptyURL);
+ }
+ };
+ _html5CanPlay = function(o) {
+ if (!_s.useHTML5Audio || !_s.hasHTML5) {
+ return false;
+ }
+ var url = (o.url || null),
+ mime = (o.type || null),
+ aF = _s.audioFormats,
+ result,
+ offset,
+ fileExt,
+ item;
+ function preferFlashCheck(kind) {
+ return (_s.preferFlash && _hasFlash && !_s.ignoreFlash && (typeof _s.flash[kind] !== 'undefined' && _s.flash[kind]));
+ }
+ if (mime && _s.html5[mime] !== 'undefined') {
+ return (_s.html5[mime] && !preferFlashCheck(mime));
+ }
+ if (!_html5Ext) {
+ _html5Ext = [];
+ for (item in aF) {
+ if (aF.hasOwnProperty(item)) {
+ _html5Ext.push(item);
+ if (aF[item].related) {
+ _html5Ext = _html5Ext.concat(aF[item].related);
+ }
+ }
+ }
+ _html5Ext = new RegExp('\\.('+_html5Ext.join('|')+')(\\?.*)?$','i');
+ }
+ fileExt = (url ? url.toLowerCase().match(_html5Ext) : null);
+ if (!fileExt || !fileExt.length) {
+ if (!mime) {
+ return false;
+ } else {
+ offset = mime.indexOf(';');
+ fileExt = (offset !== -1?mime.substr(0,offset):mime).substr(6);
+ }
+ } else {
+ fileExt = fileExt[1];
+ }
+ if (fileExt && typeof _s.html5[fileExt] !== 'undefined') {
+ return (_s.html5[fileExt] && !preferFlashCheck(fileExt));
+ } else {
+ mime = 'audio/'+fileExt;
+ result = _s.html5.canPlayType({type:mime});
+ _s.html5[fileExt] = result;
+ return (result && _s.html5[mime] && !preferFlashCheck(mime));
+ }
+ };
+ _testHTML5 = function() {
+ if (!_s.useHTML5Audio || typeof Audio === 'undefined') {
+ return false;
+ }
+ var a = (typeof Audio !== 'undefined' ? (_isOpera ? new Audio(null) : new Audio()) : null),
+ item, support = {}, aF, i;
+ function _cp(m) {
+ var canPlay, i, j, isOK = false;
+ if (!a || typeof a.canPlayType !== 'function') {
+ return false;
+ }
+ if (m instanceof Array) {
+ for (i=0, j=m.length; i<j && !isOK; i++) {
+ if (_s.html5[m[i]] || a.canPlayType(m[i]).match(_s.html5Test)) {
+ isOK = true;
+ _s.html5[m[i]] = true;
+ _s.flash[m[i]] = !!(_s.preferFlash && _hasFlash && m[i].match(_flashMIME));
+ }
+ }
+ return isOK;
+ } else {
+ canPlay = (a && typeof a.canPlayType === 'function' ? a.canPlayType(m) : false);
+ return !!(canPlay && (canPlay.match(_s.html5Test)));
+ }
+ }
+ aF = _s.audioFormats;
+ for (item in aF) {
+ if (aF.hasOwnProperty(item)) {
+ support[item] = _cp(aF[item].type);
+ support['audio/'+item] = support[item];
+ if (_s.preferFlash && !_s.ignoreFlash && item.match(_flashMIME)) {
+ _s.flash[item] = true;
+ } else {
+ _s.flash[item] = false;
+ }
+ if (aF[item] && aF[item].related) {
+ for (i=aF[item].related.length; i--;) {
+ support['audio/'+aF[item].related[i]] = support[item];
+ _s.html5[aF[item].related[i]] = support[item];
+ _s.flash[aF[item].related[i]] = support[item];
+ }
+ }
+ }
+ }
+ support.canPlayType = (a?_cp:null);
+ _s.html5 = _mixin(_s.html5, support);
+ return true;
+ };
+ _strings = {
+ };
+ _str = function() {
+ };
+ _loopFix = function(sOpt) {
+ if (_fV === 8 && sOpt.loops > 1 && sOpt.stream) {
+ sOpt.stream = false;
+ }
+ return sOpt;
+ };
+ _policyFix = function(sOpt, sPre) {
+ if (sOpt && !sOpt.usePolicyFile && (sOpt.onid3 || sOpt.usePeakData || sOpt.useWaveformData || sOpt.useEQData)) {
+ sOpt.usePolicyFile = true;
+ }
+ return sOpt;
+ };
+ _complain = function(sMsg) {
+ };
+ _doNothing = function() {
+ return false;
+ };
+ _disableObject = function(o) {
+ var oProp;
+ for (oProp in o) {
+ if (o.hasOwnProperty(oProp) && typeof o[oProp] === 'function') {
+ o[oProp] = _doNothing;
+ }
+ }
+ oProp = null;
+ };
+ _failSafely = function(bNoDisable) {
+ if (typeof bNoDisable === 'undefined') {
+ bNoDisable = false;
+ }
+ if (_disabled || bNoDisable) {
+ _s.disable(bNoDisable);
+ }
+ };
+ _normalizeMovieURL = function(smURL) {
+ var urlParams = null, url;
+ if (smURL) {
+ if (smURL.match(/\.swf(\?.*)?$/i)) {
+ urlParams = smURL.substr(smURL.toLowerCase().lastIndexOf('.swf?') + 4);
+ if (urlParams) {
+ return smURL;
+ }
+ } else if (smURL.lastIndexOf('/') !== smURL.length - 1) {
+ smURL += '/';
+ }
+ }
+ url = (smURL && smURL.lastIndexOf('/') !== - 1 ? smURL.substr(0, smURL.lastIndexOf('/') + 1) : './') + _s.movieURL;
+ if (_s.noSWFCache) {
+ url += ('?ts=' + new Date().getTime());
+ }
+ return url;
+ };
+ _setVersionInfo = function() {
+ _fV = parseInt(_s.flashVersion, 10);
+ if (_fV !== 8 && _fV !== 9) {
+ _s.flashVersion = _fV = _defaultFlashVersion;
+ }
+ var isDebug = (_s.debugMode || _s.debugFlash?'_debug.swf':'.swf');
+ if (_s.useHTML5Audio && !_s.html5Only && _s.audioFormats.mp4.required && _fV < 9) {
+ _s.flashVersion = _fV = 9;
+ }
+ _s.version = _s.versionNumber + (_s.html5Only?' (HTML5-only mode)':(_fV === 9?' (AS3/Flash 9)':' (AS2/Flash 8)'));
+ if (_fV > 8) {
+ _s.defaultOptions = _mixin(_s.defaultOptions, _s.flash9Options);
+ _s.features.buffering = true;
+ _s.defaultOptions = _mixin(_s.defaultOptions, _s.movieStarOptions);
+ _s.filePatterns.flash9 = new RegExp('\\.(mp3|' + _netStreamTypes.join('|') + ')(\\?.*)?$', 'i');
+ _s.features.movieStar = true;
+ } else {
+ _s.features.movieStar = false;
+ }
+ _s.filePattern = _s.filePatterns[(_fV !== 8?'flash9':'flash8')];
+ _s.movieURL = (_fV === 8?'soundmanager2.swf':'soundmanager2_flash9.swf').replace('.swf', isDebug);
+ _s.features.peakData = _s.features.waveformData = _s.features.eqData = (_fV > 8);
+ };
+ _setPolling = function(bPolling, bHighPerformance) {
+ if (!_flash) {
+ return false;
+ }
+ _flash._setPolling(bPolling, bHighPerformance);
+ };
+ _initDebug = function() {
+ if (_s.debugURLParam.test(_wl)) {
+ _s.debugMode = true;
+ }
+ };
+ _idCheck = this.getSoundById;
+ _getSWFCSS = function() {
+ var css = [];
+ if (_s.debugMode) {
+ css.push(_swfCSS.sm2Debug);
+ }
+ if (_s.debugFlash) {
+ css.push(_swfCSS.flashDebug);
+ }
+ if (_s.useHighPerformance) {
+ css.push(_swfCSS.highPerf);
+ }
+ return css.join(' ');
+ };
+ _flashBlockHandler = function() {
+ var name = _str('fbHandler'),
+ p = _s.getMoviePercent(),
+ css = _swfCSS,
+ error = {type:'FLASHBLOCK'};
+ if (_s.html5Only) {
+ return false;
+ }
+ if (!_s.ok()) {
+ if (_needsFlash) {
+ _s.oMC.className = _getSWFCSS() + ' ' + css.swfDefault + ' ' + (p === null?css.swfTimedout:css.swfError);
+ }
+ _s.didFlashBlock = true;
+ _processOnEvents({type:'ontimeout', ignoreInit:true, error:error});
+ _catchError(error);
+ } else {
+ if (_s.oMC) {
+ _s.oMC.className = [_getSWFCSS(), css.swfDefault, css.swfLoaded + (_s.didFlashBlock?' '+css.swfUnblocked:'')].join(' ');
+ }
+ }
+ };
+ _addOnEvent = function(sType, oMethod, oScope) {
+ if (typeof _on_queue[sType] === 'undefined') {
+ _on_queue[sType] = [];
+ }
+ _on_queue[sType].push({
+ 'method': oMethod,
+ 'scope': (oScope || null),
+ 'fired': false
+ });
+ };
+ _processOnEvents = function(oOptions) {
+ if (!oOptions) {
+ oOptions = {
+ type: 'onready'
+ };
+ }
+ if (!_didInit && oOptions && !oOptions.ignoreInit) {
+ return false;
+ }
+ if (oOptions.type === 'ontimeout' && _s.ok()) {
+ return false;
+ }
+ var status = {
+ success: (oOptions && oOptions.ignoreInit?_s.ok():!_disabled)
+ },
+ srcQueue = (oOptions && oOptions.type?_on_queue[oOptions.type]||[]:[]),
+ queue = [], i, j,
+ args = [status],
+ canRetry = (_needsFlash && _s.useFlashBlock && !_s.ok());
+ if (oOptions.error) {
+ args[0].error = oOptions.error;
+ }
+ for (i = 0, j = srcQueue.length; i < j; i++) {
+ if (srcQueue[i].fired !== true) {
+ queue.push(srcQueue[i]);
+ }
+ }
+ if (queue.length) {
+ for (i = 0, j = queue.length; i < j; i++) {
+ if (queue[i].scope) {
+ queue[i].method.apply(queue[i].scope, args);
+ } else {
+ queue[i].method.apply(this, args);
+ }
+ if (!canRetry) {
+ queue[i].fired = true;
+ }
+ }
+ }
+ return true;
+ };
+ _initUserOnload = function() {
+ _win.setTimeout(function() {
+ if (_s.useFlashBlock) {
+ _flashBlockHandler();
+ }
+ _processOnEvents();
+ if (_s.onload instanceof Function) {
+ _s.onload.apply(_win);
+ }
+ if (_s.waitForWindowLoad) {
+ _event.add(_win, 'load', _initUserOnload);
+ }
+ },1);
+ };
+ _detectFlash = function() {
+ if (_hasFlash !== undefined) {
+ return _hasFlash;
+ }
+ var hasPlugin = false, n = navigator, nP = n.plugins, obj, type, types, AX = _win.ActiveXObject;
+ if (nP && nP.length) {
+ type = 'application/x-shockwave-flash';
+ types = n.mimeTypes;
+ if (types && types[type] && types[type].enabledPlugin && types[type].enabledPlugin.description) {
+ hasPlugin = true;
+ }
+ } else if (typeof AX !== 'undefined') {
+ try {
+ obj = new AX('ShockwaveFlash.ShockwaveFlash');
+ } catch(e) {
+ }
+ hasPlugin = (!!obj);
+ }
+ _hasFlash = hasPlugin;
+ return hasPlugin;
+ };
+ _featureCheck = function() {
+ var needsFlash, item,
+ isSpecial = (_is_iDevice && !!(_ua.match(/os (1|2|3_0|3_1)/i)));
+ if (isSpecial) {
+ _s.hasHTML5 = false;
+ _s.html5Only = true;
+ if (_s.oMC) {
+ _s.oMC.style.display = 'none';
+ }
+ return false;
+ }
+ if (_s.useHTML5Audio) {
+ if (!_s.html5 || !_s.html5.canPlayType) {
+ _s.hasHTML5 = false;
+ return true;
+ } else {
+ _s.hasHTML5 = true;
+ }
+ if (_isBadSafari) {
+ if (_detectFlash()) {
+ return true;
+ }
+ }
+ } else {
+ return true;
+ }
+ for (item in _s.audioFormats) {
+ if (_s.audioFormats.hasOwnProperty(item)) {
+ if ((_s.audioFormats[item].required && !_s.html5.canPlayType(_s.audioFormats[item].type)) || _s.flash[item] || _s.flash[_s.audioFormats[item].type]) {
+ needsFlash = true;
+ }
+ }
+ }
+ if (_s.ignoreFlash) {
+ needsFlash = false;
+ }
+ _s.html5Only = (_s.hasHTML5 && _s.useHTML5Audio && !needsFlash);
+ return (!_s.html5Only);
+ };
+ _parseURL = function(url) {
+ var i, j, result = 0;
+ if (url instanceof Array) {
+ for (i=0, j=url.length; i<j; i++) {
+ if (url[i] instanceof Object) {
+ if (_s.canPlayMIME(url[i].type)) {
+ result = i;
+ break;
+ }
+ } else if (_s.canPlayURL(url[i])) {
+ result = i;
+ break;
+ }
+ }
+ if (url[result].url) {
+ url[result] = url[result].url;
+ }
+ return url[result];
+ } else {
+ return url;
+ }
+ };
+ _startTimer = function(oSound) {
+ if (!oSound._hasTimer) {
+ oSound._hasTimer = true;
+ if (!_likesHTML5 && _s.html5PollingInterval) {
+ if (_h5IntervalTimer === null && _h5TimerCount === 0) {
+ _h5IntervalTimer = window.setInterval(_timerExecute, _s.html5PollingInterval);
+ }
+ _h5TimerCount++;
+ }
+ }
+ };
+ _stopTimer = function(oSound) {
+ if (oSound._hasTimer) {
+ oSound._hasTimer = false;
+ if (!_likesHTML5 && _s.html5PollingInterval) {
+ _h5TimerCount--;
+ }
+ }
+ };
+ _timerExecute = function() {
+ var i, j;
+ if (_h5IntervalTimer !== null && !_h5TimerCount) {
+ window.clearInterval(_h5IntervalTimer);
+ _h5IntervalTimer = null;
+ return false;
+ }
+ for (i = _s.soundIDs.length; i--;) {
+ if (_s.sounds[_s.soundIDs[i]].isHTML5 && _s.sounds[_s.soundIDs[i]]._hasTimer) {
+ _s.sounds[_s.soundIDs[i]]._onTimer();
+ }
+ }
+ };
+ _catchError = function(options) {
+ options = (typeof options !== 'undefined' ? options : {});
+ if (_s.onerror instanceof Function) {
+ _s.onerror.apply(_win, [{type:(typeof options.type !== 'undefined' ? options.type : null)}]);
+ }
+ if (typeof options.fatal !== 'undefined' && options.fatal) {
+ _s.disable();
+ }
+ };
+ _badSafariFix = function() {
+ if (!_isBadSafari || !_detectFlash()) {
+ return false;
+ }
+ var aF = _s.audioFormats, i, item;
+ for (item in aF) {
+ if (aF.hasOwnProperty(item)) {
+ if (item === 'mp3' || item === 'mp4') {
+ _s.html5[item] = false;
+ if (aF[item] && aF[item].related) {
+ for (i = aF[item].related.length; i--;) {
+ _s.html5[aF[item].related[i]] = false;
+ }
+ }
+ }
+ }
+ }
+ };
+ this._setSandboxType = function(sandboxType) {
+ };
+ this._externalInterfaceOK = function(flashDate, swfVersion) {
+ if (_s.swfLoaded) {
+ return false;
+ }
+ var e, eiTime = new Date().getTime();
+ _s.swfLoaded = true;
+ _tryInitOnFocus = false;
+ if (_isBadSafari) {
+ _badSafariFix();
+ }
+ if (_isIE) {
+ setTimeout(_init, 100);
+ } else {
+ _init();
+ }
+ };
+ _createMovie = function(smID, smURL) {
+ if (_didAppend && _appendSuccess) {
+ return false;
+ }
+ function _initMsg() {
+ }
+ if (_s.html5Only) {
+ _setVersionInfo();
+ _initMsg();
+ _s.oMC = _id(_s.movieID);
+ _init();
+ _didAppend = true;
+ _appendSuccess = true;
+ return false;
+ }
+ var remoteURL = (smURL || _s.url),
+ localURL = (_s.altURL || remoteURL),
+ swfTitle = 'JS/Flash audio component (SoundManager 2)',
+ oEmbed, oMovie, oTarget = _getDocument(), tmp, movieHTML, oEl, extraClass = _getSWFCSS(),
+ s, x, sClass, side = 'auto', isRTL = null,
+ html = _doc.getElementsByTagName('html')[0];
+ isRTL = (html && html.dir && html.dir.match(/rtl/i));
+ smID = (typeof smID === 'undefined'?_s.id:smID);
+ function param(name, value) {
+ return '<param name="'+name+'" value="'+value+'" />';
+ }
+ _setVersionInfo();
+ _s.url = _normalizeMovieURL(_overHTTP?remoteURL:localURL);
+ smURL = _s.url;
+ _s.wmode = (!_s.wmode && _s.useHighPerformance ? 'transparent' : _s.wmode);
+ if (_s.wmode !== null && (_ua.match(/msie 8/i) || (!_isIE && !_s.useHighPerformance)) && navigator.platform.match(/win32|win64/i)) {
+ _s.wmode = null;
+ }
+ oEmbed = {
+ 'name': smID,
+ 'id': smID,
+ 'src': smURL,
+ 'width': side,
+ 'height': side,
+ 'quality': 'high',
+ 'allowScriptAccess': _s.allowScriptAccess,
+ 'bgcolor': _s.bgColor,
+ 'pluginspage': _http+'www.macromedia.com/go/getflashplayer',
+ 'title': swfTitle,
+ 'type': 'application/x-shockwave-flash',
+ 'wmode': _s.wmode,
+ 'hasPriority': 'true'
+ };
+ if (_s.debugFlash) {
+ oEmbed.FlashVars = 'debug=1';
+ }
+ if (!_s.wmode) {
+ delete oEmbed.wmode;
+ }
+ if (_isIE) {
+ oMovie = _doc.createElement('div');
+ movieHTML = [
+ '<object id="' + smID + '" data="' + smURL + '" type="' + oEmbed.type + '" title="' + oEmbed.title +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="' + _http+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="' + oEmbed.width + '" height="' + oEmbed.height + '">',
+ param('movie', smURL),
+ param('AllowScriptAccess', _s.allowScriptAccess),
+ param('quality', oEmbed.quality),
+ (_s.wmode? param('wmode', _s.wmode): ''),
+ param('bgcolor', _s.bgColor),
+ param('hasPriority', 'true'),
+ (_s.debugFlash ? param('FlashVars', oEmbed.FlashVars) : ''),
+ '</object>'
+ ].join('');
+ } else {
+ oMovie = _doc.createElement('embed');
+ for (tmp in oEmbed) {
+ if (oEmbed.hasOwnProperty(tmp)) {
+ oMovie.setAttribute(tmp, oEmbed[tmp]);
+ }
+ }
+ }
+ _initDebug();
+ extraClass = _getSWFCSS();
+ oTarget = _getDocument();
+ if (oTarget) {
+ _s.oMC = (_id(_s.movieID) || _doc.createElement('div'));
+ if (!_s.oMC.id) {
+ _s.oMC.id = _s.movieID;
+ _s.oMC.className = _swfCSS.swfDefault + ' ' + extraClass;
+ s = null;
+ oEl = null;
+ if (!_s.useFlashBlock) {
+ if (_s.useHighPerformance) {
+ s = {
+ 'position': 'fixed',
+ 'width': '8px',
+ 'height': '8px',
+ 'bottom': '0px',
+ 'left': '0px',
+ 'overflow': 'hidden'
+ };
+ } else {
+ s = {
+ 'position': 'absolute',
+ 'width': '6px',
+ 'height': '6px',
+ 'top': '-9999px',
+ 'left': '-9999px'
+ };
+ if (isRTL) {
+ s.left = Math.abs(parseInt(s.left,10))+'px';
+ }
+ }
+ }
+ if (_isWebkit) {
+ _s.oMC.style.zIndex = 10000;
+ }
+ if (!_s.debugFlash) {
+ for (x in s) {
+ if (s.hasOwnProperty(x)) {
+ _s.oMC.style[x] = s[x];
+ }
+ }
+ }
+ try {
+ if (!_isIE) {
+ _s.oMC.appendChild(oMovie);
+ }
+ oTarget.appendChild(_s.oMC);
+ if (_isIE) {
+ oEl = _s.oMC.appendChild(_doc.createElement('div'));
+ oEl.className = _swfCSS.swfBox;
+ oEl.innerHTML = movieHTML;
+ }
+ _appendSuccess = true;
+ } catch(e) {
+ throw new Error(_str('domError')+' \n'+e.toString());
+ }
+ } else {
+ sClass = _s.oMC.className;
+ _s.oMC.className = (sClass?sClass+' ':_swfCSS.swfDefault) + (extraClass?' '+extraClass:'');
+ _s.oMC.appendChild(oMovie);
+ if (_isIE) {
+ oEl = _s.oMC.appendChild(_doc.createElement('div'));
+ oEl.className = _swfCSS.swfBox;
+ oEl.innerHTML = movieHTML;
+ }
+ _appendSuccess = true;
+ }
+ }
+ _didAppend = true;
+ _initMsg();
+ return true;
+ };
+ _initMovie = function() {
+ if (_s.html5Only) {
+ _createMovie();
+ return false;
+ }
+ if (_flash) {
+ return false;
+ }
+ _flash = _s.getMovie(_s.id);
+ if (!_flash) {
+ if (!_oRemoved) {
+ _createMovie(_s.id, _s.url);
+ } else {
+ if (!_isIE) {
+ _s.oMC.appendChild(_oRemoved);
+ } else {
+ _s.oMC.innerHTML = _oRemovedHTML;
+ }
+ _oRemoved = null;
+ _didAppend = true;
+ }
+ _flash = _s.getMovie(_s.id);
+ }
+ if (_s.oninitmovie instanceof Function) {
+ setTimeout(_s.oninitmovie, 1);
+ }
+ return true;
+ };
+ _delayWaitForEI = function() {
+ setTimeout(_waitForEI, 1000);
+ };
+ _waitForEI = function() {
+ if (_waitingForEI) {
+ return false;
+ }
+ _waitingForEI = true;
+ _event.remove(_win, 'load', _delayWaitForEI);
+ if (_tryInitOnFocus && !_isFocused) {
+ return false;
+ }
+ var p;
+ if (!_didInit) {
+ p = _s.getMoviePercent();
+ }
+ setTimeout(function() {
+ p = _s.getMoviePercent();
+ if (!_didInit && _okToDisable) {
+ if (p === null) {
+ if (_s.useFlashBlock || _s.flashLoadTimeout === 0) {
+ if (_s.useFlashBlock) {
+ _flashBlockHandler();
+ }
+ } else {
+ _failSafely(true);
+ }
+ } else {
+ if (_s.flashLoadTimeout === 0) {
+ } else {
+ _failSafely(true);
+ }
+ }
+ }
+ }, _s.flashLoadTimeout);
+ };
+ _handleFocus = function() {
+ function cleanup() {
+ _event.remove(_win, 'focus', _handleFocus);
+ _event.remove(_win, 'load', _handleFocus);
+ }
+ if (_isFocused || !_tryInitOnFocus) {
+ cleanup();
+ return true;
+ }
+ _okToDisable = true;
+ _isFocused = true;
+ if (_isSafari && _tryInitOnFocus) {
+ _event.remove(_win, 'mousemove', _handleFocus);
+ }
+ _waitingForEI = false;
+ cleanup();
+ return true;
+ };
+ _showSupport = function() {
+ var item, tests = [];
+ if (_s.useHTML5Audio && _s.hasHTML5) {
+ for (item in _s.audioFormats) {
+ if (_s.audioFormats.hasOwnProperty(item)) {
+ tests.push(item + ': ' + _s.html5[item] + (!_s.html5[item] && _hasFlash && _s.flash[item] ? ' (using flash)' : (_s.preferFlash && _s.flash[item] && _hasFlash ? ' (preferring flash)': (!_s.html5[item] ? ' (' + (_s.audioFormats[item].required ? 'required, ':'') + 'and no flash support)' : ''))));
+ }
+ }
+ }
+ };
+ _initComplete = function(bNoDisable) {
+ if (_didInit) {
+ return false;
+ }
+ if (_s.html5Only) {
+ _didInit = true;
+ _initUserOnload();
+ return true;
+ }
+ var wasTimeout = (_s.useFlashBlock && _s.flashLoadTimeout && !_s.getMoviePercent()),
+ error;
+ if (!wasTimeout) {
+ _didInit = true;
+ if (_disabled) {
+ error = {type: (!_hasFlash && _needsFlash ? 'NO_FLASH' : 'INIT_TIMEOUT')};
+ }
+ }
+ if (_disabled || bNoDisable) {
+ if (_s.useFlashBlock && _s.oMC) {
+ _s.oMC.className = _getSWFCSS() + ' ' + (_s.getMoviePercent() === null?_swfCSS.swfTimedout:_swfCSS.swfError);
+ }
+ _processOnEvents({type:'ontimeout', error:error});
+ _catchError(error);
+ return false;
+ } else {
+ }
+ if (_s.waitForWindowLoad && !_windowLoaded) {
+ _event.add(_win, 'load', _initUserOnload);
+ return false;
+ } else {
+ _initUserOnload();
+ }
+ return true;
+ };
+ _init = function() {
+ if (_didInit) {
+ return false;
+ }
+ function _cleanup() {
+ _event.remove(_win, 'load', _s.beginDelayedInit);
+ }
+ if (_s.html5Only) {
+ if (!_didInit) {
+ _cleanup();
+ _s.enabled = true;
+ _initComplete();
+ }
+ return true;
+ }
+ _initMovie();
+ try {
+ _flash._externalInterfaceTest(false);
+ _setPolling(true, (_s.flashPollingInterval || (_s.useHighPerformance ? 10 : 50)));
+ if (!_s.debugMode) {
+ _flash._disableDebug();
+ }
+ _s.enabled = true;
+ if (!_s.html5Only) {
+ _event.add(_win, 'unload', _doNothing);
+ }
+ } catch(e) {
+ _catchError({type:'JS_TO_FLASH_EXCEPTION', fatal:true});
+ _failSafely(true);
+ _initComplete();
+ return false;
+ }
+ _initComplete();
+ _cleanup();
+ return true;
+ };
+ _domContentLoaded = function() {
+ if (_didDCLoaded) {
+ return false;
+ }
+ _didDCLoaded = true;
+ _initDebug();
+ if (!_hasFlash && _s.hasHTML5) {
+ _s.useHTML5Audio = true;
+ _s.preferFlash = false;
+ }
+ _testHTML5();
+ _s.html5.usingFlash = _featureCheck();
+ _needsFlash = _s.html5.usingFlash;
+ _showSupport();
+ if (!_hasFlash && _needsFlash) {
+ _s.flashLoadTimeout = 1;
+ }
+ if (_doc.removeEventListener) {
+ _doc.removeEventListener('DOMContentLoaded', _domContentLoaded, false);
+ }
+ _initMovie();
+ return true;
+ };
+ _domContentLoadedIE = function() {
+ if (_doc.readyState === 'complete') {
+ _domContentLoaded();
+ _doc.detachEvent('onreadystatechange', _domContentLoadedIE);
+ }
+ return true;
+ };
+ _winOnLoad = function() {
+ _windowLoaded = true;
+ _event.remove(_win, 'load', _winOnLoad);
+ };
+ _detectFlash();
+ _event.add(_win, 'focus', _handleFocus);
+ _event.add(_win, 'load', _handleFocus);
+ _event.add(_win, 'load', _delayWaitForEI);
+ _event.add(_win, 'load', _winOnLoad);
+ if (_isSafari && _tryInitOnFocus) {
+ _event.add(_win, 'mousemove', _handleFocus);
+ }
+ if (_doc.addEventListener) {
+ _doc.addEventListener('DOMContentLoaded', _domContentLoaded, false);
+ } else if (_doc.attachEvent) {
+ _doc.attachEvent('onreadystatechange', _domContentLoadedIE);
+ } else {
+ _catchError({type:'NO_DOM2_EVENTS', fatal:true});
+ }
+ if (_doc.readyState === 'complete') {
+ setTimeout(_domContentLoaded,100);
+ }
+}
+// SM2_DEFER details: http://www.schillmania.com/projects/soundmanager2/doc/getstarted/#lazy-loading
+if (typeof SM2_DEFER === 'undefined' || !SM2_DEFER) {
+ soundManager = new SoundManager();
+}
+window.SoundManager = SoundManager;
+window.soundManager = soundManager;
+}(window)); \ No newline at end of file
diff --git a/Processing-js/libs/inc/SoundManager2/script/soundmanager2.js b/Processing-js/libs/inc/SoundManager2/script/soundmanager2.js
new file mode 100755
index 0000000..4b115c3
--- /dev/null
+++ b/Processing-js/libs/inc/SoundManager2/script/soundmanager2.js
@@ -0,0 +1,5019 @@
+/** @license
+ *
+ * SoundManager 2: JavaScript Sound for the Web
+ * ----------------------------------------------
+ * http://schillmania.com/projects/soundmanager2/
+ *
+ * Copyright (c) 2007, Scott Schiller. All rights reserved.
+ * Code provided under the BSD License:
+ * http://schillmania.com/projects/soundmanager2/license.txt
+ *
+ * V2.97a.20111220
+ */
+
+/*global window, SM2_DEFER, sm2Debugger, console, document, navigator, setTimeout, setInterval, clearInterval, Audio */
+/* jslint regexp: true, sloppy: true, white: true, nomen: true, plusplus: true */
+
+/**
+ * About this file
+ * ---------------
+ * This is the fully-commented source version of the SoundManager 2 API,
+ * recommended for use during development and testing.
+ *
+ * See soundmanager2-nodebug-jsmin.js for an optimized build (~10KB with gzip.)
+ * http://schillmania.com/projects/soundmanager2/doc/getstarted/#basic-inclusion
+ * Alternately, serve this file with gzip for 75% compression savings (~30KB over HTTP.)
+ *
+ * You may notice <d> and </d> comments in this source; these are delimiters for
+ * debug blocks which are removed in the -nodebug builds, further optimizing code size.
+ *
+ * Also, as you may note: Whoa, reliable cross-platform/device audio support is hard! ;)
+ */
+
+(function(window) {
+
+var soundManager = null;
+
+/**
+ * The SoundManager constructor.
+ *
+ * @constructor
+ * @param {string} smURL Optional: Path to SWF files
+ * @param {string} smID Optional: The ID to use for the SWF container element
+ * @this {SoundManager}
+ * @return {SoundManager} The new SoundManager instance
+ */
+
+function SoundManager(smURL, smID) {
+ // Top-level configuration options
+
+ this.flashVersion = 8; // flash build to use (8 or 9.) Some API features require 9.
+ this.debugMode = true; // enable debugging output (console.log() with HTML fallback)
+ this.debugFlash = false; // enable debugging output inside SWF, troubleshoot Flash/browser issues
+ this.useConsole = true; // use console.log() if available (otherwise, writes to #soundmanager-debug element)
+ this.consoleOnly = true; // if console is being used, do not create/write to #soundmanager-debug
+ this.waitForWindowLoad = false; // force SM2 to wait for window.onload() before trying to call soundManager.onload()
+ this.bgColor = '#ffffff'; // SWF background color. N/A when wmode = 'transparent'
+ this.useHighPerformance = false; // position:fixed flash movie can help increase js/flash speed, minimize lag
+ this.flashPollingInterval = null; // msec affecting whileplaying/loading callback frequency. If null, default of 50 msec is used.
+ this.html5PollingInterval = null; // msec affecting whileplaying() for HTML5 audio, excluding mobile devices. If null, native HTML5 update events are used.
+ this.flashLoadTimeout = 1000; // msec to wait for flash movie to load before failing (0 = infinity)
+ this.wmode = null; // flash rendering mode - null, 'transparent', or 'opaque' (last two allow z-index to work)
+ this.allowScriptAccess = 'always'; // for scripting the SWF (object/embed property), 'always' or 'sameDomain'
+ this.useFlashBlock = false; // *requires flashblock.css, see demos* - allow recovery from flash blockers. Wait indefinitely and apply timeout CSS to SWF, if applicable.
+ this.useHTML5Audio = true; // use HTML5 Audio() where API is supported (most Safari, Chrome versions), Firefox (no MP3/MP4.) Ideally, transparent vs. Flash API where possible.
+ this.html5Test = /^(probably|maybe)$/i; // HTML5 Audio() format support test. Use /^probably$/i; if you want to be more conservative.
+ this.preferFlash = true; // overrides useHTML5audio. if true and flash support present, will try to use flash for MP3/MP4 as needed since HTML5 audio support is still quirky in browsers.
+ this.noSWFCache = false; // if true, appends ?ts={date} to break aggressive SWF caching.
+
+ this.audioFormats = {
+
+ /**
+ * determines HTML5 support + flash requirements.
+ * if no support (via flash and/or HTML5) for a "required" format, SM2 will fail to start.
+ * flash fallback is used for MP3 or MP4 if HTML5 can't play it (or if preferFlash = true)
+ * multiple MIME types may be tested while trying to get a positive canPlayType() response.
+ */
+
+ 'mp3': {
+ 'type': ['audio/mpeg; codecs="mp3"', 'audio/mpeg', 'audio/mp3', 'audio/MPA', 'audio/mpa-robust'],
+ 'required': true
+ },
+
+ 'mp4': {
+ 'related': ['aac','m4a'], // additional formats under the MP4 container
+ 'type': ['audio/mp4; codecs="mp4a.40.2"', 'audio/aac', 'audio/x-m4a', 'audio/MP4A-LATM', 'audio/mpeg4-generic'],
+ 'required': false
+ },
+
+ 'ogg': {
+ 'type': ['audio/ogg; codecs=vorbis'],
+ 'required': false
+ },
+
+ 'wav': {
+ 'type': ['audio/wav; codecs="1"', 'audio/wav', 'audio/wave', 'audio/x-wav'],
+ 'required': false
+ }
+
+ };
+
+ this.defaultOptions = {
+
+ /**
+ * the default configuration for sound objects made with createSound() and related methods
+ * eg., volume, auto-load behaviour and so forth
+ */
+
+ 'autoLoad': false, // enable automatic loading (otherwise .load() will be called on demand with .play(), the latter being nicer on bandwidth - if you want to .load yourself, you also can)
+ 'autoPlay': false, // enable playing of file as soon as possible (much faster if "stream" is true)
+ 'from': null, // position to start playback within a sound (msec), default = beginning
+ 'loops': 1, // how many times to repeat the sound (position will wrap around to 0, setPosition() will break out of loop when >0)
+ 'onid3': null, // callback function for "ID3 data is added/available"
+ 'onload': null, // callback function for "load finished"
+ 'whileloading': null, // callback function for "download progress update" (X of Y bytes received)
+ 'onplay': null, // callback for "play" start
+ 'onpause': null, // callback for "pause"
+ 'onresume': null, // callback for "resume" (pause toggle)
+ 'whileplaying': null, // callback during play (position update)
+ 'onposition': null, // object containing times and function callbacks for positions of interest
+ 'onstop': null, // callback for "user stop"
+ 'onfailure': null, // callback function for when playing fails
+ 'onfinish': null, // callback function for "sound finished playing"
+ 'multiShot': true, // let sounds "restart" or layer on top of each other when played multiple times, rather than one-shot/one at a time
+ 'multiShotEvents': false, // fire multiple sound events (currently onfinish() only) when multiShot is enabled
+ 'position': null, // offset (milliseconds) to seek to within loaded sound data.
+ 'pan': 0, // "pan" settings, left-to-right, -100 to 100
+ 'stream': true, // allows playing before entire file has loaded (recommended)
+ 'to': null, // position to end playback within a sound (msec), default = end
+ 'type': null, // MIME-like hint for file pattern / canPlay() tests, eg. audio/mp3
+ 'usePolicyFile': false, // enable crossdomain.xml request for audio on remote domains (for ID3/waveform access)
+ 'volume': 100 // self-explanatory. 0-100, the latter being the max.
+
+ };
+
+ this.flash9Options = {
+
+ /**
+ * flash 9-only options,
+ * merged into defaultOptions if flash 9 is being used
+ */
+
+ 'isMovieStar': null, // "MovieStar" MPEG4 audio mode. Null (default) = auto detect MP4, AAC etc. based on URL. true = force on, ignore URL
+ 'usePeakData': false, // enable left/right channel peak (level) data
+ 'useWaveformData': false, // enable sound spectrum (raw waveform data) - NOTE: May increase CPU load.
+ 'useEQData': false, // enable sound EQ (frequency spectrum data) - NOTE: May increase CPU load.
+ 'onbufferchange': null, // callback for "isBuffering" property change
+ 'ondataerror': null // callback for waveform/eq data access error (flash playing audio in other tabs/domains)
+
+ };
+
+ this.movieStarOptions = {
+
+ /**
+ * flash 9.0r115+ MPEG4 audio options,
+ * merged into defaultOptions if flash 9+movieStar mode is enabled
+ */
+
+ 'bufferTime': 3, // seconds of data to buffer before playback begins (null = flash default of 0.1 seconds - if AAC playback is gappy, try increasing.)
+ 'serverURL': null, // rtmp: FMS or FMIS server to connect to, required when requesting media via RTMP or one of its variants
+ 'onconnect': null, // rtmp: callback for connection to flash media server
+ 'duration': null // rtmp: song duration (msec)
+
+ };
+
+ // HTML attributes (id + class names) for the SWF container
+
+ this.movieID = 'sm2-container';
+ this.id = (smID || 'sm2movie');
+
+ this.debugID = 'soundmanager-debug';
+ this.debugURLParam = /([#?&])debug=1/i;
+
+ // dynamic attributes
+
+ this.versionNumber = 'V2.97a.20111220';
+ this.version = null;
+ this.movieURL = null;
+ this.url = (smURL || null);
+ this.altURL = null;
+ this.swfLoaded = false;
+ this.enabled = false;
+ this.oMC = null;
+ this.sounds = {};
+ this.soundIDs = [];
+ this.muted = false;
+ this.didFlashBlock = false;
+ this.filePattern = null;
+
+ this.filePatterns = {
+
+ 'flash8': /\.mp3(\?.*)?$/i,
+ 'flash9': /\.mp3(\?.*)?$/i
+
+ };
+
+ // support indicators, set at init
+
+ this.features = {
+
+ 'buffering': false,
+ 'peakData': false,
+ 'waveformData': false,
+ 'eqData': false,
+ 'movieStar': false
+
+ };
+
+ // flash sandbox info, used primarily in troubleshooting
+
+ this.sandbox = {
+
+ // <d>
+ 'type': null,
+ 'types': {
+ 'remote': 'remote (domain-based) rules',
+ 'localWithFile': 'local with file access (no internet access)',
+ 'localWithNetwork': 'local with network (internet access only, no local access)',
+ 'localTrusted': 'local, trusted (local+internet access)'
+ },
+ 'description': null,
+ 'noRemote': null,
+ 'noLocal': null
+ // </d>
+
+ };
+
+ /**
+ * basic HTML5 Audio() support test
+ * try...catch because of IE 9 "not implemented" nonsense
+ * https://github.com/Modernizr/Modernizr/issues/224
+ */
+
+ this.hasHTML5 = (function() {
+ try {
+ return (typeof Audio !== 'undefined' && typeof new Audio().canPlayType !== 'undefined');
+ } catch(e) {
+ return false;
+ }
+ }());
+
+ /**
+ * format support (html5/flash)
+ * stores canPlayType() results based on audioFormats.
+ * eg. { mp3: boolean, mp4: boolean }
+ * treat as read-only.
+ */
+
+ this.html5 = {
+ 'usingFlash': null // set if/when flash fallback is needed
+ };
+
+ this.flash = {}; // file type support hash
+
+ this.html5Only = false; // determined at init time
+ this.ignoreFlash = false; // used for special cases (eg. iPad/iPhone/palm OS?)
+
+ /**
+ * a few private internals (OK, a lot. :D)
+ */
+
+ var SMSound,
+ _s = this, _flash = null, _sm = 'soundManager', _smc = _sm+'::', _h5 = 'HTML5::', _id, _ua = navigator.userAgent, _win = window, _wl = _win.location.href.toString(), _doc = document, _doNothing, _init, _fV, _on_queue = [], _debugOpen = true, _debugTS, _didAppend = false, _appendSuccess = false, _didInit = false, _disabled = false, _windowLoaded = false, _wDS, _wdCount = 0, _initComplete, _mixin, _addOnEvent, _processOnEvents, _initUserOnload, _delayWaitForEI, _waitForEI, _setVersionInfo, _handleFocus, _strings, _initMovie, _domContentLoaded, _winOnLoad, _didDCLoaded, _getDocument, _createMovie, _catchError, _setPolling, _initDebug, _debugLevels = ['log', 'info', 'warn', 'error'], _defaultFlashVersion = 8, _disableObject, _failSafely, _normalizeMovieURL, _oRemoved = null, _oRemovedHTML = null, _str, _flashBlockHandler, _getSWFCSS, _swfCSS, _toggleDebug, _loopFix, _policyFix, _complain, _idCheck, _waitingForEI = false, _initPending = false, _smTimer, _onTimer, _startTimer, _stopTimer, _timerExecute, _h5TimerCount = 0, _h5IntervalTimer = null, _parseURL,
+ _needsFlash = null, _featureCheck, _html5OK, _html5CanPlay, _html5Ext, _html5Unload, _domContentLoadedIE, _testHTML5, _event, _slice = Array.prototype.slice, _useGlobalHTML5Audio = false, _hasFlash, _detectFlash, _badSafariFix, _html5_events, _showSupport,
+ _is_iDevice = _ua.match(/(ipad|iphone|ipod)/i), _is_firefox = _ua.match(/firefox/i), _is_android = _ua.match(/droid/i), _isIE = _ua.match(/msie/i), _isWebkit = _ua.match(/webkit/i), _isSafari = (_ua.match(/safari/i) && !_ua.match(/chrome/i)), _isOpera = (_ua.match(/opera/i)),
+ _likesHTML5 = (_ua.match(/(mobile|pre\/|xoom)/i) || _is_iDevice),
+ _isBadSafari = (!_wl.match(/usehtml5audio/i) && !_wl.match(/sm2\-ignorebadua/i) && _isSafari && !_ua.match(/silk/i) && _ua.match(/OS X 10_6_([3-7])/i)), // Safari 4 and 5 (excluding Kindle Fire, "Silk") occasionally fail to load/play HTML5 audio on Snow Leopard 10.6.3 through 10.6.7 due to bug(s) in QuickTime X and/or other underlying frameworks. :/ Confirmed bug. https://bugs.webkit.org/show_bug.cgi?id=32159
+ _hasConsole = (typeof console !== 'undefined' && typeof console.log !== 'undefined'), _isFocused = (typeof _doc.hasFocus !== 'undefined'?_doc.hasFocus():null), _tryInitOnFocus = (_isSafari && typeof _doc.hasFocus === 'undefined'), _okToDisable = !_tryInitOnFocus, _flashMIME = /(mp3|mp4|mpa)/i,
+ _emptyURL = 'about:blank', // safe URL to unload, or load nothing from (flash 8 + most HTML5 UAs)
+ _overHTTP = (_doc.location?_doc.location.protocol.match(/http/i):null),
+ _http = (!_overHTTP ? 'http:/'+'/' : ''),
+ // mp3, mp4, aac etc.
+ _netStreamMimeTypes = /^\s*audio\/(?:x-)?(?:mpeg4|aac|flv|mov|mp4||m4v|m4a|mp4v|3gp|3g2)\s*(?:$|;)/i,
+ // Flash v9.0r115+ "moviestar" formats
+ _netStreamTypes = ['mpeg4', 'aac', 'flv', 'mov', 'mp4', 'm4v', 'f4v', 'm4a', 'mp4v', '3gp', '3g2'],
+ _netStreamPattern = new RegExp('\\.(' + _netStreamTypes.join('|') + ')(\\?.*)?$', 'i');
+
+ this.mimePattern = /^\s*audio\/(?:x-)?(?:mp(?:eg|3))\s*(?:$|;)/i; // default mp3 set
+
+ // use altURL if not "online"
+ this.useAltURL = !_overHTTP;
+ this._global_a = null;
+
+ _swfCSS = {
+
+ 'swfBox': 'sm2-object-box',
+ 'swfDefault': 'movieContainer',
+ 'swfError': 'swf_error', // SWF loaded, but SM2 couldn't start (other error)
+ 'swfTimedout': 'swf_timedout',
+ 'swfLoaded': 'swf_loaded',
+ 'swfUnblocked': 'swf_unblocked', // or loaded OK
+ 'sm2Debug': 'sm2_debug',
+ 'highPerf': 'high_performance',
+ 'flashDebug': 'flash_debug'
+
+ };
+
+ if (_likesHTML5) {
+
+ // prefer HTML5 for mobile + tablet-like devices, probably more reliable vs. flash at this point.
+ _s.useHTML5Audio = true;
+ _s.preferFlash = false;
+
+ if (_is_iDevice) {
+ // by default, use global feature. iOS onfinish() -> next may fail otherwise.
+ _s.ignoreFlash = true;
+ _useGlobalHTML5Audio = true;
+ }
+
+ }
+
+ /**
+ * Public SoundManager API
+ * -----------------------
+ */
+
+ this.ok = function() {
+
+ return (_needsFlash?(_didInit && !_disabled):(_s.useHTML5Audio && _s.hasHTML5));
+
+ };
+
+ this.supported = this.ok; // legacy
+
+ this.getMovie = function(smID) {
+
+ // safety net: some old browsers differ on SWF references, possibly related to ExternalInterface / flash version
+ return _id(smID) || _doc[smID] || _win[smID];
+
+ };
+
+ /**
+ * Creates a SMSound sound object instance.
+ *
+ * @param {object} oOptions Sound options (at minimum, id and url are required.)
+ * @return {object} SMSound The new SMSound object.
+ */
+
+ this.createSound = function(oOptions) {
+
+ var _cs, _cs_string,
+ thisOptions = null, oSound = null, _tO = null;
+
+ // <d>
+ _cs = _sm+'.createSound(): ';
+ _cs_string = _cs + _str(!_didInit?'notReady':'notOK');
+ // </d>
+
+ if (!_didInit || !_s.ok()) {
+ _complain(_cs_string);
+ return false;
+ }
+
+ if (arguments.length === 2) {
+ // function overloading in JS! :) ..assume simple createSound(id,url) use case
+ oOptions = {
+ 'id': arguments[0],
+ 'url': arguments[1]
+ };
+ }
+
+ // inherit from defaultOptions
+ thisOptions = _mixin(oOptions);
+
+ thisOptions.url = _parseURL(thisOptions.url);
+
+ // local shortcut
+ _tO = thisOptions;
+
+ // <d>
+ if (_tO.id.toString().charAt(0).match(/^[0-9]$/)) {
+ _s._wD(_cs + _str('badID', _tO.id), 2);
+ }
+
+ _s._wD(_cs + _tO.id + ' (' + _tO.url + ')', 1);
+ // </d>
+
+ if (_idCheck(_tO.id, true)) {
+ _s._wD(_cs + _tO.id + ' exists', 1);
+ return _s.sounds[_tO.id];
+ }
+
+ function make() {
+
+ thisOptions = _loopFix(thisOptions);
+ _s.sounds[_tO.id] = new SMSound(_tO);
+ _s.soundIDs.push(_tO.id);
+ return _s.sounds[_tO.id];
+
+ }
+
+ if (_html5OK(_tO)) {
+
+ oSound = make();
+ _s._wD('Loading sound '+_tO.id+' via HTML5');
+ oSound._setup_html5(_tO);
+
+ } else {
+
+ if (_fV > 8) {
+ if (_tO.isMovieStar === null) {
+ // attempt to detect MPEG-4 formats
+ _tO.isMovieStar = (_tO.serverURL || (_tO.type ? _tO.type.match(_netStreamMimeTypes) : false) || _tO.url.match(_netStreamPattern));
+ }
+ // <d>
+ if (_tO.isMovieStar) {
+ _s._wD(_cs + 'using MovieStar handling');
+ }
+ // </d>
+ if (_tO.isMovieStar) {
+ if (_tO.usePeakData) {
+ _wDS('noPeak');
+ _tO.usePeakData = false;
+ }
+ // <d>
+ if (_tO.loops > 1) {
+ _wDS('noNSLoop');
+ }
+ // </d>
+ }
+ }
+
+ _tO = _policyFix(_tO, _cs);
+ oSound = make();
+
+ if (_fV === 8) {
+ _flash._createSound(_tO.id, _tO.loops||1, _tO.usePolicyFile);
+ } else {
+ _flash._createSound(_tO.id, _tO.url, _tO.usePeakData, _tO.useWaveformData, _tO.useEQData, _tO.isMovieStar, (_tO.isMovieStar?_tO.bufferTime:false), _tO.loops||1, _tO.serverURL, _tO.duration||null, _tO.autoPlay, true, _tO.autoLoad, _tO.usePolicyFile);
+ if (!_tO.serverURL) {
+ // We are connected immediately
+ oSound.connected = true;
+ if (_tO.onconnect) {
+ _tO.onconnect.apply(oSound);
+ }
+ }
+ }
+
+ if (!_tO.serverURL && (_tO.autoLoad || _tO.autoPlay)) {
+ // call load for non-rtmp streams
+ oSound.load(_tO);
+ }
+
+ }
+
+ // rtmp will play in onconnect
+ if (!_tO.serverURL && _tO.autoPlay) {
+ oSound.play();
+ }
+
+ return oSound;
+
+ };
+
+ /**
+ * Destroys a SMSound sound object instance.
+ *
+ * @param {string} sID The ID of the sound to destroy
+ */
+
+ this.destroySound = function(sID, _bFromSound) {
+
+ // explicitly destroy a sound before normal page unload, etc.
+
+ if (!_idCheck(sID)) {
+ return false;
+ }
+
+ var oS = _s.sounds[sID], i;
+
+ // Disable all callbacks while the sound is being destroyed
+ oS._iO = {};
+
+ oS.stop();
+ oS.unload();
+
+ for (i = 0; i < _s.soundIDs.length; i++) {
+ if (_s.soundIDs[i] === sID) {
+ _s.soundIDs.splice(i, 1);
+ break;
+ }
+ }
+
+ if (!_bFromSound) {
+ // ignore if being called from SMSound instance
+ oS.destruct(true);
+ }
+
+ oS = null;
+ delete _s.sounds[sID];
+
+ return true;
+
+ };
+
+ /**
+ * Calls the load() method of a SMSound object by ID.
+ *
+ * @param {string} sID The ID of the sound
+ * @param {object} oOptions Optional: Sound options
+ */
+
+ this.load = function(sID, oOptions) {
+
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].load(oOptions);
+
+ };
+
+ /**
+ * Calls the unload() method of a SMSound object by ID.
+ *
+ * @param {string} sID The ID of the sound
+ */
+
+ this.unload = function(sID) {
+
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].unload();
+
+ };
+
+ /**
+ * Calls the onPosition() method of a SMSound object by ID.
+ *
+ * @param {string} sID The ID of the sound
+ * @param {number} nPosition The position to watch for
+ * @param {function} oMethod The relevant callback to fire
+ * @param {object} oScope Optional: The scope to apply the callback to
+ * @return {SMSound} The SMSound object
+ */
+
+ this.onPosition = function(sID, nPosition, oMethod, oScope) {
+
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].onposition(nPosition, oMethod, oScope);
+
+ };
+
+ // legacy/backwards-compability: lower-case method name
+ this.onposition = this.onPosition;
+
+ /**
+ * Calls the clearOnPosition() method of a SMSound object by ID.
+ *
+ * @param {string} sID The ID of the sound
+ * @param {number} nPosition The position to watch for
+ * @param {function} oMethod Optional: The relevant callback to fire
+ * @return {SMSound} The SMSound object
+ */
+
+ this.clearOnPosition = function(sID, nPosition, oMethod) {
+
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].clearOnPosition(nPosition, oMethod);
+
+ };
+
+ /**
+ * Calls the play() method of a SMSound object by ID.
+ *
+ * @param {string} sID The ID of the sound
+ * @param {object} oOptions Optional: Sound options
+ * @return {SMSound} The SMSound object
+ */
+
+ this.play = function(sID, oOptions) {
+
+ if (!_didInit || !_s.ok()) {
+ _complain(_sm+'.play(): ' + _str(!_didInit?'notReady':'notOK'));
+ return false;
+ }
+
+ if (!_idCheck(sID)) {
+ if (!(oOptions instanceof Object)) {
+ // overloading use case: play('mySound','/path/to/some.mp3');
+ oOptions = {
+ url: oOptions
+ };
+ }
+ if (oOptions && oOptions.url) {
+ // overloading use case, create+play: .play('someID',{url:'/path/to.mp3'});
+ _s._wD(_sm+'.play(): attempting to create "' + sID + '"', 1);
+ oOptions.id = sID;
+ return _s.createSound(oOptions).play();
+ } else {
+ return false;
+ }
+ }
+
+ return _s.sounds[sID].play(oOptions);
+
+ };
+
+ this.start = this.play; // just for convenience
+
+ /**
+ * Calls the setPosition() method of a SMSound object by ID.
+ *
+ * @param {string} sID The ID of the sound
+ * @param {number} nMsecOffset Position (milliseconds)
+ * @return {SMSound} The SMSound object
+ */
+
+ this.setPosition = function(sID, nMsecOffset) {
+
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].setPosition(nMsecOffset);
+
+ };
+
+ /**
+ * Calls the stop() method of a SMSound object by ID.
+ *
+ * @param {string} sID The ID of the sound
+ * @return {SMSound} The SMSound object
+ */
+
+ this.stop = function(sID) {
+
+ if (!_idCheck(sID)) {
+ return false;
+ }
+
+ _s._wD(_sm+'.stop(' + sID + ')', 1);
+ return _s.sounds[sID].stop();
+
+ };
+
+ /**
+ * Stops all currently-playing sounds.
+ */
+
+ this.stopAll = function() {
+
+ var oSound;
+ _s._wD(_sm+'.stopAll()', 1);
+
+ for (oSound in _s.sounds) {
+ if (_s.sounds.hasOwnProperty(oSound)) {
+ // apply only to sound objects
+ _s.sounds[oSound].stop();
+ }
+ }
+
+ };
+
+ /**
+ * Calls the pause() method of a SMSound object by ID.
+ *
+ * @param {string} sID The ID of the sound
+ * @return {SMSound} The SMSound object
+ */
+
+ this.pause = function(sID) {
+
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].pause();
+
+ };
+
+ /**
+ * Pauses all currently-playing sounds.
+ */
+
+ this.pauseAll = function() {
+
+ var i;
+ for (i = _s.soundIDs.length; i--;) {
+ _s.sounds[_s.soundIDs[i]].pause();
+ }
+
+ };
+
+ /**
+ * Calls the resume() method of a SMSound object by ID.
+ *
+ * @param {string} sID The ID of the sound
+ * @return {SMSound} The SMSound object
+ */
+
+ this.resume = function(sID) {
+
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].resume();
+
+ };
+
+ /**
+ * Resumes all currently-paused sounds.
+ */
+
+ this.resumeAll = function() {
+
+ var i;
+ for (i = _s.soundIDs.length; i--;) {
+ _s.sounds[_s.soundIDs[i]].resume();
+ }
+
+ };
+
+ /**
+ * Calls the togglePause() method of a SMSound object by ID.
+ *
+ * @param {string} sID The ID of the sound
+ * @return {SMSound} The SMSound object
+ */
+
+ this.togglePause = function(sID) {
+
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].togglePause();
+
+ };
+
+ /**
+ * Calls the setPan() method of a SMSound object by ID.
+ *
+ * @param {string} sID The ID of the sound
+ * @param {number} nPan The pan value (-100 to 100)
+ * @return {SMSound} The SMSound object
+ */
+
+ this.setPan = function(sID, nPan) {
+
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].setPan(nPan);
+
+ };
+
+ /**
+ * Calls the setVolume() method of a SMSound object by ID.
+ *
+ * @param {string} sID The ID of the sound
+ * @param {number} nVol The volume value (0 to 100)
+ * @return {SMSound} The SMSound object
+ */
+
+ this.setVolume = function(sID, nVol) {
+
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].setVolume(nVol);
+
+ };
+
+ /**
+ * Calls the mute() method of either a single SMSound object by ID, or all sound objects.
+ *
+ * @param {string} sID Optional: The ID of the sound (if omitted, all sounds will be used.)
+ */
+
+ this.mute = function(sID) {
+
+ var i = 0;
+
+ if (typeof sID !== 'string') {
+ sID = null;
+ }
+
+ if (!sID) {
+ _s._wD(_sm+'.mute(): Muting all sounds');
+ for (i = _s.soundIDs.length; i--;) {
+ _s.sounds[_s.soundIDs[i]].mute();
+ }
+ _s.muted = true;
+ } else {
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ _s._wD(_sm+'.mute(): Muting "' + sID + '"');
+ return _s.sounds[sID].mute();
+ }
+
+ return true;
+
+ };
+
+ /**
+ * Mutes all sounds.
+ */
+
+ this.muteAll = function() {
+
+ _s.mute();
+
+ };
+
+ /**
+ * Calls the unmute() method of either a single SMSound object by ID, or all sound objects.
+ *
+ * @param {string} sID Optional: The ID of the sound (if omitted, all sounds will be used.)
+ */
+
+ this.unmute = function(sID) {
+
+ var i;
+
+ if (typeof sID !== 'string') {
+ sID = null;
+ }
+
+ if (!sID) {
+
+ _s._wD(_sm+'.unmute(): Unmuting all sounds');
+ for (i = _s.soundIDs.length; i--;) {
+ _s.sounds[_s.soundIDs[i]].unmute();
+ }
+ _s.muted = false;
+
+ } else {
+
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ _s._wD(_sm+'.unmute(): Unmuting "' + sID + '"');
+ return _s.sounds[sID].unmute();
+
+ }
+
+ return true;
+
+ };
+
+ /**
+ * Unmutes all sounds.
+ */
+
+ this.unmuteAll = function() {
+
+ _s.unmute();
+
+ };
+
+ /**
+ * Calls the toggleMute() method of a SMSound object by ID.
+ *
+ * @param {string} sID The ID of the sound
+ * @return {SMSound} The SMSound object
+ */
+
+ this.toggleMute = function(sID) {
+
+ if (!_idCheck(sID)) {
+ return false;
+ }
+ return _s.sounds[sID].toggleMute();
+
+ };
+
+ /**
+ * Retrieves the memory used by the flash plugin.
+ *
+ * @return {number} The amount of memory in use
+ */
+
+ this.getMemoryUse = function() {
+
+ // flash-only
+ var ram = 0;
+
+ if (_flash && _fV !== 8) {
+ ram = parseInt(_flash._getMemoryUse(), 10);
+ }
+
+ return ram;
+
+ };
+
+ /**
+ * Undocumented: NOPs soundManager and all SMSound objects.
+ */
+
+ this.disable = function(bNoDisable) {
+
+ // destroy all functions
+ var i;
+
+ if (typeof bNoDisable === 'undefined') {
+ bNoDisable = false;
+ }
+
+ if (_disabled) {
+ return false;
+ }
+
+ _disabled = true;
+ _wDS('shutdown', 1);
+
+ for (i = _s.soundIDs.length; i--;) {
+ _disableObject(_s.sounds[_s.soundIDs[i]]);
+ }
+
+ // fire "complete", despite fail
+ _initComplete(bNoDisable);
+ _event.remove(_win, 'load', _initUserOnload);
+
+ return true;
+
+ };
+
+ /**
+ * Determines playability of a MIME type, eg. 'audio/mp3'.
+ */
+
+ this.canPlayMIME = function(sMIME) {
+
+ var result;
+
+ if (_s.hasHTML5) {
+ result = _html5CanPlay({type:sMIME});
+ }
+
+ if (!_needsFlash || result) {
+ // no flash, or OK
+ return result;
+ } else {
+ // if flash 9, test netStream (movieStar) types as well.
+ return (sMIME ? !!((_fV > 8 ? sMIME.match(_netStreamMimeTypes) : null) || sMIME.match(_s.mimePattern)) : null);
+ }
+
+ };
+
+ /**
+ * Determines playability of a URL based on audio support.
+ *
+ * @param {string} sURL The URL to test
+ * @return {boolean} URL playability
+ */
+
+ this.canPlayURL = function(sURL) {
+
+ var result;
+
+ if (_s.hasHTML5) {
+ result = _html5CanPlay({url: sURL});
+ }
+
+ if (!_needsFlash || result) {
+ // no flash, or OK
+ return result;
+ } else {
+ return (sURL ? !!(sURL.match(_s.filePattern)) : null);
+ }
+
+ };
+
+ /**
+ * Determines playability of an HTML DOM &lt;a&gt; object (or similar object literal) based on audio support.
+ *
+ * @param {object} oLink an HTML DOM &lt;a&gt; object or object literal including href and/or type attributes
+ * @return {boolean} URL playability
+ */
+
+ this.canPlayLink = function(oLink) {
+
+ if (typeof oLink.type !== 'undefined' && oLink.type) {
+ if (_s.canPlayMIME(oLink.type)) {
+ return true;
+ }
+ }
+
+ return _s.canPlayURL(oLink.href);
+
+ };
+
+ /**
+ * Retrieves a SMSound object by ID.
+ *
+ * @param {string} sID The ID of the sound
+ * @return {SMSound} The SMSound object
+ */
+
+ this.getSoundById = function(sID, _suppressDebug) {
+
+ if (!sID) {
+ throw new Error(_sm+'.getSoundById(): sID is null/undefined');
+ }
+
+ var result = _s.sounds[sID];
+
+ // <d>
+ if (!result && !_suppressDebug) {
+ _s._wD('"' + sID + '" is an invalid sound ID.', 2);
+ }
+ // </d>
+
+ return result;
+
+ };
+
+ /**
+ * Queues a callback for execution when SoundManager has successfully initialized.
+ *
+ * @param {function} oMethod The callback method to fire
+ * @param {object} oScope Optional: The scope to apply to the callback
+ */
+
+ this.onready = function(oMethod, oScope) {
+
+ var sType = 'onready';
+
+ if (oMethod && oMethod instanceof Function) {
+
+ // <d>
+ if (_didInit) {
+ _s._wD(_str('queue', sType));
+ }
+ // </d>
+
+ if (!oScope) {
+ oScope = _win;
+ }
+
+ _addOnEvent(sType, oMethod, oScope);
+ _processOnEvents();
+
+ return true;
+
+ } else {
+
+ throw _str('needFunction', sType);
+
+ }
+
+ };
+
+ /**
+ * Queues a callback for execution when SoundManager has failed to initialize.
+ *
+ * @param {function} oMethod The callback method to fire
+ * @param {object} oScope Optional: The scope to apply to the callback
+ */
+
+ this.ontimeout = function(oMethod, oScope) {
+
+ var sType = 'ontimeout';
+
+ if (oMethod && oMethod instanceof Function) {
+
+ // <d>
+ if (_didInit) {
+ _s._wD(_str('queue', sType));
+ }
+ // </d>
+
+ if (!oScope) {
+ oScope = _win;
+ }
+
+ _addOnEvent(sType, oMethod, oScope);
+ _processOnEvents({type:sType});
+
+ return true;
+
+ } else {
+
+ throw _str('needFunction', sType);
+
+ }
+
+ };
+
+ /**
+ * Writes console.log()-style debug output to a console or in-browser element.
+ * Applies when SoundManager.debugMode = true
+ *
+ * @param {string} sText The console message
+ * @param {string} sType Optional: Log type of 'info', 'warn' or 'error'
+ * @param {object} Optional: The scope to apply to the callback
+ */
+
+ this._writeDebug = function(sText, sType, _bTimestamp) {
+
+ // pseudo-private console.log()-style output
+ // <d>
+
+ var sDID = 'soundmanager-debug', o, oItem, sMethod;
+
+ if (!_s.debugMode) {
+ return false;
+ }
+
+ if (typeof _bTimestamp !== 'undefined' && _bTimestamp) {
+ sText = sText + ' | ' + new Date().getTime();
+ }
+
+ if (_hasConsole && _s.useConsole) {
+ sMethod = _debugLevels[sType];
+ if (typeof console[sMethod] !== 'undefined') {
+ console[sMethod](sText);
+ } else {
+ console.log(sText);
+ }
+ if (_s.consoleOnly) {
+ return true;
+ }
+ }
+
+ try {
+
+ o = _id(sDID);
+
+ if (!o) {
+ return false;
+ }
+
+ oItem = _doc.createElement('div');
+
+ if (++_wdCount % 2 === 0) {
+ oItem.className = 'sm2-alt';
+ }
+
+ if (typeof sType === 'undefined') {
+ sType = 0;
+ } else {
+ sType = parseInt(sType, 10);
+ }
+
+ oItem.appendChild(_doc.createTextNode(sText));
+
+ if (sType) {
+ if (sType >= 2) {
+ oItem.style.fontWeight = 'bold';
+ }
+ if (sType === 3) {
+ oItem.style.color = '#ff3333';
+ }
+ }
+
+ // top-to-bottom
+ // o.appendChild(oItem);
+
+ // bottom-to-top
+ o.insertBefore(oItem, o.firstChild);
+
+ } catch(e) {
+ // oh well
+ }
+
+ o = null;
+ // </d>
+
+ return true;
+
+ };
+
+ // alias
+ this._wD = this._writeDebug;
+
+ /**
+ * Provides debug / state information on all SMSound objects.
+ */
+
+ this._debug = function() {
+
+ // <d>
+ var i, j;
+ _wDS('currentObj', 1);
+
+ for (i = 0, j = _s.soundIDs.length; i < j; i++) {
+ _s.sounds[_s.soundIDs[i]]._debug();
+ }
+ // </d>
+
+ };
+
+ /**
+ * Restarts and re-initializes the SoundManager instance.
+ */
+
+ this.reboot = function() {
+
+ // attempt to reset and init SM2
+ _s._wD(_sm+'.reboot()');
+
+ // <d>
+ if (_s.soundIDs.length) {
+ _s._wD('Destroying ' + _s.soundIDs.length + ' SMSound objects...');
+ }
+ // </d>
+
+ var i, j;
+
+ for (i = _s.soundIDs.length; i--;) {
+ _s.sounds[_s.soundIDs[i]].destruct();
+ }
+
+ // trash ze flash
+
+ try {
+ if (_isIE) {
+ _oRemovedHTML = _flash.innerHTML;
+ }
+ _oRemoved = _flash.parentNode.removeChild(_flash);
+ _s._wD('Flash movie removed.');
+ } catch(e) {
+ // uh-oh.
+ _wDS('badRemove', 2);
+ }
+
+ // actually, force recreate of movie.
+ _oRemovedHTML = _oRemoved = _needsFlash = null;
+
+ _s.enabled = _didDCLoaded = _didInit = _waitingForEI = _initPending = _didAppend = _appendSuccess = _disabled = _s.swfLoaded = false;
+ _s.soundIDs = _s.sounds = [];
+ _flash = null;
+
+ for (i in _on_queue) {
+ if (_on_queue.hasOwnProperty(i)) {
+ for (j = _on_queue[i].length; j--;) {
+ _on_queue[i][j].fired = false;
+ }
+ }
+ }
+
+ _s._wD(_sm + ': Rebooting...');
+ _win.setTimeout(_s.beginDelayedInit, 20);
+
+ };
+
+ /**
+ * Undocumented: Determines the SM2 flash movie's load progress.
+ *
+ * @return {number or null} Percent loaded, or if invalid/unsupported, null.
+ */
+
+ this.getMoviePercent = function() {
+
+ return (_flash && typeof _flash.PercentLoaded !== 'undefined' ? _flash.PercentLoaded() : null);
+
+ };
+
+ /**
+ * Additional helper for manually invoking SM2's init process after DOM Ready / window.onload().
+ */
+
+ this.beginDelayedInit = function() {
+
+ _windowLoaded = true;
+ _domContentLoaded();
+
+ setTimeout(function() {
+
+ if (_initPending) {
+ return false;
+ }
+
+ _createMovie();
+ _initMovie();
+ _initPending = true;
+
+ return true;
+
+ }, 20);
+
+ _delayWaitForEI();
+
+ };
+
+ /**
+ * Destroys the SoundManager instance and all SMSound instances.
+ */
+
+ this.destruct = function() {
+
+ _s._wD(_sm+'.destruct()');
+ _s.disable(true);
+
+ };
+
+ /**
+ * SMSound() (sound object) constructor
+ * ------------------------------------
+ *
+ * @param {object} oOptions Sound options (id and url are required attributes)
+ * @return {SMSound} The new SMSound object
+ */
+
+ SMSound = function(oOptions) {
+
+ var _t = this, _resetProperties, _add_html5_events, _remove_html5_events, _stop_html5_timer, _start_html5_timer, _attachOnPosition, _onplay_called = false, _onPositionItems = [], _onPositionFired = 0, _detachOnPosition, _applyFromTo, _lastURL = null;
+
+ var _lastHTML5State = {
+ // tracks duration + position (time)
+ duration: null,
+ time: null
+ };
+
+ this.sID = oOptions.id;
+ this.url = oOptions.url;
+ this.options = _mixin(oOptions);
+
+ // per-play-instance-specific options
+ this.instanceOptions = this.options;
+
+ // short alias
+ this._iO = this.instanceOptions;
+
+ // assign property defaults
+ this.pan = this.options.pan;
+ this.volume = this.options.volume;
+ this.isHTML5 = false;
+ this._a = null;
+
+ /**
+ * SMSound() public methods
+ * ------------------------
+ */
+
+ this.id3 = {};
+
+ /**
+ * Writes SMSound object parameters to debug console
+ */
+
+ this._debug = function() {
+
+ // <d>
+ // pseudo-private console.log()-style output
+
+ if (_s.debugMode) {
+
+ var stuff = null, msg = [], sF, sfBracket, maxLength = 64;
+
+ for (stuff in _t.options) {
+ if (_t.options[stuff] !== null) {
+ if (_t.options[stuff] instanceof Function) {
+ // handle functions specially
+ sF = _t.options[stuff].toString();
+ // normalize spaces
+ sF = sF.replace(/\s\s+/g, ' ');
+ sfBracket = sF.indexOf('{');
+ msg.push(' ' + stuff + ': {' + sF.substr(sfBracket + 1, (Math.min(Math.max(sF.indexOf('\n') - 1, maxLength), maxLength))).replace(/\n/g, '') + '... }');
+ } else {
+ msg.push(' ' + stuff + ': ' + _t.options[stuff]);
+ }
+ }
+ }
+
+ _s._wD('SMSound() merged options: {\n' + msg.join(', \n') + '\n}');
+
+ }
+ // </d>
+
+ };
+
+ // <d>
+ this._debug();
+ // </d>
+
+ /**
+ * Begins loading a sound per its *url*.
+ *
+ * @param {object} oOptions Optional: Sound options
+ * @return {SMSound} The SMSound object
+ */
+
+ this.load = function(oOptions) {
+
+ var oS = null, _iO;
+
+ if (typeof oOptions !== 'undefined') {
+ _t._iO = _mixin(oOptions, _t.options);
+ _t.instanceOptions = _t._iO;
+ } else {
+ oOptions = _t.options;
+ _t._iO = oOptions;
+ _t.instanceOptions = _t._iO;
+ if (_lastURL && _lastURL !== _t.url) {
+ _wDS('manURL');
+ _t._iO.url = _t.url;
+ _t.url = null;
+ }
+ }
+
+ if (!_t._iO.url) {
+ _t._iO.url = _t.url;
+ }
+
+ _t._iO.url = _parseURL(_t._iO.url);
+
+ _s._wD('SMSound.load(): ' + _t._iO.url, 1);
+
+ if (_t._iO.url === _t.url && _t.readyState !== 0 && _t.readyState !== 2) {
+ _wDS('onURL', 1);
+ // if loaded and an onload() exists, fire immediately.
+ if (_t.readyState === 3 && _t._iO.onload) {
+ // assume success based on truthy duration.
+ _t._iO.onload.apply(_t, [(!!_t.duration)]);
+ }
+ return _t;
+ }
+
+ // local shortcut
+ _iO = _t._iO;
+
+ _lastURL = _t.url;
+ _t.loaded = false;
+ _t.readyState = 1;
+ _t.playState = 0;
+
+ // TODO: If switching from HTML5 -> flash (or vice versa), stop currently-playing audio.
+
+ if (_html5OK(_iO)) {
+
+ oS = _t._setup_html5(_iO);
+
+ if (!oS._called_load) {
+
+ _s._wD(_h5+'load: '+_t.sID);
+ _t._html5_canplay = false;
+
+ // given explicit load call, try to get whole file.
+ // early HTML5 implementation (non-standard)
+ _t._a.autobuffer = 'auto';
+ // standard
+ _t._a.preload = 'auto';
+
+ oS.load();
+ oS._called_load = true;
+
+ if (_iO.autoPlay) {
+ _t.play();
+ }
+
+ } else {
+ _s._wD(_h5+'ignoring request to load again: '+_t.sID);
+ }
+
+ } else {
+
+ try {
+ _t.isHTML5 = false;
+ _t._iO = _policyFix(_loopFix(_iO));
+ // re-assign local shortcut
+ _iO = _t._iO;
+ if (_fV === 8) {
+ _flash._load(_t.sID, _iO.url, _iO.stream, _iO.autoPlay, (_iO.whileloading?1:0), _iO.loops||1, _iO.usePolicyFile);
+ } else {
+ _flash._load(_t.sID, _iO.url, !!(_iO.stream), !!(_iO.autoPlay), _iO.loops||1, !!(_iO.autoLoad), _iO.usePolicyFile);
+ }
+ } catch(e) {
+ _wDS('smError', 2);
+ _debugTS('onload', false);
+ _catchError({type:'SMSOUND_LOAD_JS_EXCEPTION', fatal:true});
+
+ }
+
+ }
+
+ return _t;
+
+ };
+
+ /**
+ * Unloads a sound, canceling any open HTTP requests.
+ *
+ * @return {SMSound} The SMSound object
+ */
+
+ this.unload = function() {
+
+ // Flash 8/AS2 can't "close" a stream - fake it by loading an empty URL
+ // Flash 9/AS3: Close stream, preventing further load
+ // HTML5: Most UAs will use empty URL
+
+ if (_t.readyState !== 0) {
+
+ _s._wD('SMSound.unload(): "' + _t.sID + '"');
+
+ if (!_t.isHTML5) {
+ if (_fV === 8) {
+ _flash._unload(_t.sID, _emptyURL);
+ } else {
+ _flash._unload(_t.sID);
+ }
+ } else {
+ _stop_html5_timer();
+ if (_t._a) {
+ _t._a.pause();
+ _html5Unload(_t._a);
+ }
+ }
+
+ // reset load/status flags
+ _resetProperties();
+
+ }
+
+ return _t;
+
+ };
+
+ /**
+ * Unloads and destroys a sound.
+ */
+
+ this.destruct = function(_bFromSM) {
+
+ _s._wD('SMSound.destruct(): "' + _t.sID + '"');
+
+ if (!_t.isHTML5) {
+
+ // kill sound within Flash
+ // Disable the onfailure handler
+ _t._iO.onfailure = null;
+ _flash._destroySound(_t.sID);
+
+ } else {
+
+ _stop_html5_timer();
+
+ if (_t._a) {
+ _t._a.pause();
+ _html5Unload(_t._a);
+ if (!_useGlobalHTML5Audio) {
+ _remove_html5_events();
+ }
+ // break obvious circular reference
+ _t._a._t = null;
+ _t._a = null;
+ }
+
+ }
+
+ if (!_bFromSM) {
+ // ensure deletion from controller
+ _s.destroySound(_t.sID, true);
+
+ }
+
+ };
+
+ /**
+ * Begins playing a sound.
+ *
+ * @param {object} oOptions Optional: Sound options
+ * @return {SMSound} The SMSound object
+ */
+
+ this.play = function(oOptions, _updatePlayState) {
+
+ var fN, allowMulti, a, onready;
+
+ // <d>
+ fN = 'SMSound.play(): ';
+ // </d>
+
+ _updatePlayState = _updatePlayState === undefined ? true : _updatePlayState; // default to true
+
+ if (!oOptions) {
+ oOptions = {};
+ }
+
+ _t._iO = _mixin(oOptions, _t._iO);
+ _t._iO = _mixin(_t._iO, _t.options);
+ _t._iO.url = _parseURL(_t._iO.url);
+ _t.instanceOptions = _t._iO;
+
+ // RTMP-only
+ if (_t._iO.serverURL && !_t.connected) {
+ if (!_t.getAutoPlay()) {
+ _s._wD(fN+' Netstream not connected yet - setting autoPlay');
+ _t.setAutoPlay(true);
+ }
+ // play will be called in _onconnect()
+ return _t;
+ }
+
+ if (_html5OK(_t._iO)) {
+ _t._setup_html5(_t._iO);
+ _start_html5_timer();
+ }
+
+ if (_t.playState === 1 && !_t.paused) {
+ allowMulti = _t._iO.multiShot;
+ if (!allowMulti) {
+ _s._wD(fN + '"' + _t.sID + '" already playing (one-shot)', 1);
+ return _t;
+ } else {
+ _s._wD(fN + '"' + _t.sID + '" already playing (multi-shot)', 1);
+ }
+ }
+
+ if (!_t.loaded) {
+
+ if (_t.readyState === 0) {
+
+ _s._wD(fN + 'Attempting to load "' + _t.sID + '"', 1);
+
+ // try to get this sound playing ASAP
+ if (!_t.isHTML5) {
+ // assign directly because setAutoPlay() increments the instanceCount
+ _t._iO.autoPlay = true;
+ }
+
+ _t.load(_t._iO);
+
+ } else if (_t.readyState === 2) {
+
+ _s._wD(fN + 'Could not load "' + _t.sID + '" - exiting', 2);
+ return _t;
+
+ } else {
+
+ _s._wD(fN + '"' + _t.sID + '" is loading - attempting to play..', 1);
+
+ }
+
+ } else {
+
+ _s._wD(fN + '"' + _t.sID + '"');
+
+ }
+
+ if (!_t.isHTML5 && _fV === 9 && _t.position > 0 && _t.position === _t.duration) {
+ // flash 9 needs a position reset if play() is called while at the end of a sound.
+ _s._wD(fN + '"' + _t.sID + '": Sound at end, resetting to position:0');
+ oOptions.position = 0;
+ }
+
+ /**
+ * Streams will pause when their buffer is full if they are being loaded.
+ * In this case paused is true, but the song hasn't started playing yet.
+ * If we just call resume() the onplay() callback will never be called.
+ * So only call resume() if the position is > 0.
+ * Another reason is because options like volume won't have been applied yet.
+ */
+
+ if (_t.paused && _t.position && _t.position > 0) {
+
+ // https://gist.github.com/37b17df75cc4d7a90bf6
+ _s._wD(fN + '"' + _t.sID + '" is resuming from paused state',1);
+ _t.resume();
+
+ } else {
+
+ _t._iO = _mixin(oOptions, _t._iO);
+
+ // apply from/to parameters, if they exist (and not using RTMP)
+ if (_t._iO.from !== null && _t._iO.to !== null && _t.instanceCount === 0 && _t.playState === 0 && !_t._iO.serverURL) {
+
+ onready = function() {
+ // sound "canplay" or onload()
+ // re-apply from/to to instance options, and start playback
+ _t._iO = _mixin(oOptions, _t._iO);
+ _t.play(_t._iO);
+ };
+
+ // HTML5 needs to at least have "canplay" fired before seeking.
+ if (_t.isHTML5 && !_t._html5_canplay) {
+
+ // this hasn't been loaded yet. load it first, and then do this again.
+ _s._wD(fN+'Beginning load of "'+ _t.sID+'" for from/to case');
+
+ _t.load({
+ _oncanplay: onready
+ });
+
+ return false;
+
+ } else if (!_t.isHTML5 && !_t.loaded && (!_t.readyState || _t.readyState !== 2)) {
+
+ // to be safe, preload the whole thing in Flash.
+
+ _s._wD(fN+'Preloading "'+ _t.sID+'" for from/to case');
+
+ _t.load({
+ onload: onready
+ });
+
+ return false;
+
+ }
+
+ // otherwise, we're ready to go. re-apply local options, and continue
+
+ _t._iO = _applyFromTo();
+
+ }
+
+ _s._wD(fN+'"'+ _t.sID+'" is starting to play');
+
+ if (!_t.instanceCount || _t._iO.multiShotEvents || (!_t.isHTML5 && _fV > 8 && !_t.getAutoPlay())) {
+ _t.instanceCount++;
+ }
+
+ // if first play and onposition parameters exist, apply them now
+ if (_t.playState === 0 && _t._iO.onposition) {
+ _attachOnPosition(_t);
+ }
+
+ _t.playState = 1;
+ _t.paused = false;
+
+ _t.position = (typeof _t._iO.position !== 'undefined' && !isNaN(_t._iO.position) ? _t._iO.position : 0);
+
+ if (!_t.isHTML5) {
+ _t._iO = _policyFix(_loopFix(_t._iO));
+ }
+
+ if (_t._iO.onplay && _updatePlayState) {
+ _t._iO.onplay.apply(_t);
+ _onplay_called = true;
+ }
+
+ _t.setVolume(_t._iO.volume, true);
+ _t.setPan(_t._iO.pan, true);
+
+ if (!_t.isHTML5) {
+
+ _flash._start(_t.sID, _t._iO.loops || 1, (_fV === 9?_t._iO.position:_t._iO.position / 1000));
+
+ } else {
+
+ _start_html5_timer();
+ a = _t._setup_html5();
+ _t.setPosition(_t._iO.position);
+ a.play();
+
+ }
+
+ }
+
+ return _t;
+
+ };
+
+ // just for convenience
+ this.start = this.play;
+
+ /**
+ * Stops playing a sound (and optionally, all sounds)
+ *
+ * @param {boolean} bAll Optional: Whether to stop all sounds
+ * @return {SMSound} The SMSound object
+ */
+
+ this.stop = function(bAll) {
+
+ var _iO = _t._iO, _oP;
+
+ if (_t.playState === 1) {
+
+ _t._onbufferchange(0);
+ _t._resetOnPosition(0);
+ _t.paused = false;
+
+ if (!_t.isHTML5) {
+ _t.playState = 0;
+ }
+
+ // remove onPosition listeners, if any
+ _detachOnPosition();
+
+ // and "to" position, if set
+ if (_iO.to) {
+ _t.clearOnPosition(_iO.to);
+ }
+
+ if (!_t.isHTML5) {
+
+ _flash._stop(_t.sID, bAll);
+
+ // hack for netStream: just unload
+ if (_iO.serverURL) {
+ _t.unload();
+ }
+
+ } else {
+
+ if (_t._a) {
+
+ _oP = _t.position;
+
+ // act like Flash, though
+ _t.setPosition(0);
+
+ // hack: reflect old position for onstop() (also like Flash)
+ _t.position = _oP;
+
+ // html5 has no stop()
+ // NOTE: pausing means iOS requires interaction to resume.
+ _t._a.pause();
+
+ _t.playState = 0;
+
+ // and update UI
+ _t._onTimer();
+
+ _stop_html5_timer();
+
+ }
+
+ }
+
+ _t.instanceCount = 0;
+ _t._iO = {};
+
+ if (_iO.onstop) {
+ _iO.onstop.apply(_t);
+ }
+
+ }
+
+ return _t;
+
+ };
+
+ /**
+ * Undocumented/internal: Sets autoPlay for RTMP.
+ *
+ * @param {boolean} autoPlay state
+ */
+
+ this.setAutoPlay = function(autoPlay) {
+
+ _s._wD('sound '+_t.sID+' turned autoplay ' + (autoPlay ? 'on' : 'off'));
+ _t._iO.autoPlay = autoPlay;
+
+ if (!_t.isHTML5) {
+ _flash._setAutoPlay(_t.sID, autoPlay);
+ if (autoPlay) {
+ // only increment the instanceCount if the sound isn't loaded (TODO: verify RTMP)
+ if (!_t.instanceCount && _t.readyState === 1) {
+ _t.instanceCount++;
+ _s._wD('sound '+_t.sID+' incremented instance count to '+_t.instanceCount);
+ }
+ }
+ }
+
+ };
+
+ /**
+ * Undocumented/internal: Returns the autoPlay boolean.
+ *
+ * @return {boolean} The current autoPlay value
+ */
+
+ this.getAutoPlay = function() {
+
+ return _t._iO.autoPlay;
+
+ };
+
+ /**
+ * Sets the position of a sound.
+ *
+ * @param {number} nMsecOffset Position (milliseconds)
+ * @return {SMSound} The SMSound object
+ */
+
+ this.setPosition = function(nMsecOffset) {
+
+ if (nMsecOffset === undefined) {
+ nMsecOffset = 0;
+ }
+
+ var original_pos,
+ position, position1K,
+ // Use the duration from the instance options, if we don't have a track duration yet.
+ // position >= 0 and <= current available (loaded) duration
+ offset = (_t.isHTML5 ? Math.max(nMsecOffset,0) : Math.min(_t.duration || _t._iO.duration, Math.max(nMsecOffset, 0)));
+
+ original_pos = _t.position;
+ _t.position = offset;
+ position1K = _t.position/1000;
+ _t._resetOnPosition(_t.position);
+ _t._iO.position = offset;
+
+ if (!_t.isHTML5) {
+
+ position = (_fV === 9 ? _t.position : position1K);
+ if (_t.readyState && _t.readyState !== 2) {
+ // if paused or not playing, will not resume (by playing)
+ _flash._setPosition(_t.sID, position, (_t.paused || !_t.playState));
+ }
+
+ } else if (_t._a) {
+
+ // Set the position in the canplay handler if the sound is not ready yet
+ if (_t._html5_canplay) {
+ if (_t._a.currentTime !== position1K) {
+ /**
+ * DOM/JS errors/exceptions to watch out for:
+ * if seek is beyond (loaded?) position, "DOM exception 11"
+ * "INDEX_SIZE_ERR": DOM exception 1
+ */
+ _s._wD('setPosition('+position1K+'): setting position');
+ try {
+ _t._a.currentTime = position1K;
+ if (_t.playState === 0 || _t.paused) {
+ // allow seek without auto-play/resume
+ _t._a.pause();
+ }
+ } catch(e) {
+ _s._wD('setPosition('+position1K+'): setting position failed: '+e.message, 2);
+ }
+ }
+ } else {
+ _s._wD('setPosition('+position1K+'): delaying, sound not ready');
+ }
+
+ }
+
+ if (_t.isHTML5) {
+ if (_t.paused) {
+ // if paused, refresh UI right away
+ // force update
+ _t._onTimer(true);
+ }
+ }
+
+ return _t;
+
+ };
+
+ /**
+ * Pauses sound playback.
+ *
+ * @return {SMSound} The SMSound object
+ */
+
+ this.pause = function(_bCallFlash) {
+
+ if (_t.paused || (_t.playState === 0 && _t.readyState !== 1)) {
+ return _t;
+ }
+
+ _s._wD('SMSound.pause()');
+ _t.paused = true;
+
+ if (!_t.isHTML5) {
+ if (_bCallFlash || _bCallFlash === undefined) {
+ _flash._pause(_t.sID);
+ }
+ } else {
+ _t._setup_html5().pause();
+ _stop_html5_timer();
+ }
+
+ if (_t._iO.onpause) {
+ _t._iO.onpause.apply(_t);
+ }
+
+ return _t;
+
+ };
+
+ /**
+ * Resumes sound playback.
+ *
+ * @return {SMSound} The SMSound object
+ */
+
+ /**
+ * When auto-loaded streams pause on buffer full they have a playState of 0.
+ * We need to make sure that the playState is set to 1 when these streams "resume".
+ * When a paused stream is resumed, we need to trigger the onplay() callback if it
+ * hasn't been called already. In this case since the sound is being played for the
+ * first time, I think it's more appropriate to call onplay() rather than onresume().
+ */
+
+ this.resume = function() {
+
+ var _iO = _t._iO;
+
+ if (!_t.paused) {
+ return _t;
+ }
+
+ _s._wD('SMSound.resume()');
+ _t.paused = false;
+ _t.playState = 1;
+
+ if (!_t.isHTML5) {
+ if (_iO.isMovieStar && !_iO.serverURL) {
+ // Bizarre Webkit bug (Chrome reported via 8tracks.com dudes): AAC content paused for 30+ seconds(?) will not resume without a reposition.
+ _t.setPosition(_t.position);
+ }
+ // flash method is toggle-based (pause/resume)
+ _flash._pause(_t.sID);
+ } else {
+ _t._setup_html5().play();
+ _start_html5_timer();
+ }
+
+ if (_onplay_called && _iO.onplay) {
+ _iO.onplay.apply(_t);
+ _onplay_called = true;
+ } else if (_iO.onresume) {
+ _iO.onresume.apply(_t);
+ }
+
+ return _t;
+
+ };
+
+ /**
+ * Toggles sound playback.
+ *
+ * @return {SMSound} The SMSound object
+ */
+
+ this.togglePause = function() {
+
+ _s._wD('SMSound.togglePause()');
+
+ if (_t.playState === 0) {
+ _t.play({
+ position: (_fV === 9 && !_t.isHTML5 ? _t.position : _t.position / 1000)
+ });
+ return _t;
+ }
+
+ if (_t.paused) {
+ _t.resume();
+ } else {
+ _t.pause();
+ }
+
+ return _t;
+
+ };
+
+ /**
+ * Sets the panning (L-R) effect.
+ *
+ * @param {number} nPan The pan value (-100 to 100)
+ * @return {SMSound} The SMSound object
+ */
+
+ this.setPan = function(nPan, bInstanceOnly) {
+
+ if (typeof nPan === 'undefined') {
+ nPan = 0;
+ }
+
+ if (typeof bInstanceOnly === 'undefined') {
+ bInstanceOnly = false;
+ }
+
+ if (!_t.isHTML5) {
+ _flash._setPan(_t.sID, nPan);
+ } // else { no HTML5 pan? }
+
+ _t._iO.pan = nPan;
+
+ if (!bInstanceOnly) {
+ _t.pan = nPan;
+ _t.options.pan = nPan;
+ }
+
+ return _t;
+
+ };
+
+ /**
+ * Sets the volume.
+ *
+ * @param {number} nVol The volume value (0 to 100)
+ * @return {SMSound} The SMSound object
+ */
+
+ this.setVolume = function(nVol, _bInstanceOnly) {
+
+ /**
+ * Note: Setting volume has no effect on iOS "special snowflake" devices.
+ * Hardware volume control overrides software, and volume
+ * will always return 1 per Apple docs. (iOS 4 + 5.)
+ * http://developer.apple.com/library/safari/documentation/AudioVideo/Conceptual/HTML-canvas-guide/AddingSoundtoCanvasAnimations/AddingSoundtoCanvasAnimations.html
+ */
+
+ if (typeof nVol === 'undefined') {
+ nVol = 100;
+ }
+
+ if (typeof _bInstanceOnly === 'undefined') {
+ _bInstanceOnly = false;
+ }
+
+ if (!_t.isHTML5) {
+ _flash._setVolume(_t.sID, (_s.muted && !_t.muted) || _t.muted?0:nVol);
+ } else if (_t._a) {
+ // valid range: 0-1
+ _t._a.volume = Math.max(0, Math.min(1, nVol/100));
+ }
+
+ _t._iO.volume = nVol;
+
+ if (!_bInstanceOnly) {
+ _t.volume = nVol;
+ _t.options.volume = nVol;
+ }
+
+ return _t;
+
+ };
+
+ /**
+ * Mutes the sound.
+ *
+ * @return {SMSound} The SMSound object
+ */
+
+ this.mute = function() {
+
+ _t.muted = true;
+
+ if (!_t.isHTML5) {
+ _flash._setVolume(_t.sID, 0);
+ } else if (_t._a) {
+ _t._a.muted = true;
+ }
+
+ return _t;
+
+ };
+
+ /**
+ * Unmutes the sound.
+ *
+ * @return {SMSound} The SMSound object
+ */
+
+ this.unmute = function() {
+
+ _t.muted = false;
+ var hasIO = typeof _t._iO.volume !== 'undefined';
+
+ if (!_t.isHTML5) {
+ _flash._setVolume(_t.sID, hasIO?_t._iO.volume:_t.options.volume);
+ } else if (_t._a) {
+ _t._a.muted = false;
+ }
+
+ return _t;
+
+ };
+
+ /**
+ * Toggles the muted state of a sound.
+ *
+ * @return {SMSound} The SMSound object
+ */
+
+ this.toggleMute = function() {
+
+ return (_t.muted?_t.unmute():_t.mute());
+
+ };
+
+ /**
+ * Registers a callback to be fired when a sound reaches a given position during playback.
+ *
+ * @param {number} nPosition The position to watch for
+ * @param {function} oMethod The relevant callback to fire
+ * @param {object} oScope Optional: The scope to apply the callback to
+ * @return {SMSound} The SMSound object
+ */
+
+ this.onPosition = function(nPosition, oMethod, oScope) {
+
+ // TODO: basic dupe checking?
+
+ _onPositionItems.push({
+ position: nPosition,
+ method: oMethod,
+ scope: (typeof oScope !== 'undefined' ? oScope : _t),
+ fired: false
+ });
+
+ return _t;
+
+ };
+
+ // legacy/backwards-compability: lower-case method name
+ this.onposition = this.onPosition;
+
+ /**
+ * Removes registered callback(s) from a sound, by position and/or callback.
+ *
+ * @param {number} nPosition The position to clear callback(s) for
+ * @param {function} oMethod Optional: Identify one callback to be removed when multiple listeners exist for one position
+ * @return {SMSound} The SMSound object
+ */
+
+ this.clearOnPosition = function(nPosition, oMethod) {
+
+ var i;
+
+ nPosition = parseInt(nPosition, 10);
+
+ if (isNaN(nPosition)) {
+ // safety check
+ return false;
+ }
+
+ for (i=0; i < _onPositionItems.length; i++) {
+
+ if (nPosition === _onPositionItems[i].position) {
+ // remove this item if no method was specified, or, if the method matches
+ if (!oMethod || (oMethod === _onPositionItems[i].method)) {
+ if (_onPositionItems[i].fired) {
+ // decrement "fired" counter, too
+ _onPositionFired--;
+ }
+ _onPositionItems.splice(i, 1);
+ }
+ }
+
+ }
+
+ };
+
+ this._processOnPosition = function() {
+
+ var i, item, j = _onPositionItems.length;
+
+ if (!j || !_t.playState || _onPositionFired >= j) {
+ return false;
+ }
+
+ for (i=j; i--;) {
+ item = _onPositionItems[i];
+ if (!item.fired && _t.position >= item.position) {
+ item.fired = true;
+ _onPositionFired++;
+ item.method.apply(item.scope, [item.position]);
+ }
+ }
+
+ return true;
+
+ };
+
+ this._resetOnPosition = function(nPosition) {
+
+ // reset "fired" for items interested in this position
+ var i, item, j = _onPositionItems.length;
+
+ if (!j) {
+ return false;
+ }
+
+ for (i=j; i--;) {
+ item = _onPositionItems[i];
+ if (item.fired && nPosition <= item.position) {
+ item.fired = false;
+ _onPositionFired--;
+ }
+ }
+
+ return true;
+
+ };
+
+ /**
+ * SMSound() private internals
+ * --------------------------------
+ */
+
+ _applyFromTo = function() {
+
+ var _iO = _t._iO,
+ f = _iO.from,
+ t = _iO.to,
+ start, end;
+
+ end = function() {
+
+ // end has been reached.
+ _s._wD(_t.sID + ': "to" time of ' + t + ' reached.');
+
+ // detach listener
+ _t.clearOnPosition(t, end);
+
+ // stop should clear this, too
+ _t.stop();
+
+ };
+
+ start = function() {
+
+ _s._wD(_t.sID + ': playing "from" ' + f);
+
+ // add listener for end
+ if (t !== null && !isNaN(t)) {
+ _t.onPosition(t, end);
+ }
+
+ };
+
+ if (f !== null && !isNaN(f)) {
+
+ // apply to instance options, guaranteeing correct start position.
+ _iO.position = f;
+
+ // multiShot timing can't be tracked, so prevent that.
+ _iO.multiShot = false;
+
+ start();
+
+ }
+
+ // return updated instanceOptions including starting position
+ return _iO;
+
+ };
+
+ _attachOnPosition = function() {
+
+ var op = _t._iO.onposition;
+
+ // attach onposition things, if any, now.
+
+ if (op) {
+
+ var item;
+
+ for (item in op) {
+ if (op.hasOwnProperty(item)) {
+ _t.onPosition(parseInt(item, 10), op[item]);
+ }
+ }
+
+ }
+
+ };
+
+ _detachOnPosition = function() {
+
+ var op = _t._iO.onposition;
+
+ // detach any onposition()-style listeners.
+
+ if (op) {
+
+ var item;
+
+ for (item in op) {
+ if (op.hasOwnProperty(item)) {
+ _t.clearOnPosition(parseInt(item, 10));
+ }
+ }
+
+ }
+
+ };
+
+ _start_html5_timer = function() {
+
+ if (_t.isHTML5) {
+ _startTimer(_t);
+ }
+
+ };
+
+ _stop_html5_timer = function() {
+
+ if (_t.isHTML5) {
+ _stopTimer(_t);
+ }
+
+ };
+
+ _resetProperties = function() {
+
+ _onPositionItems = [];
+ _onPositionFired = 0;
+ _onplay_called = false;
+
+ _t._hasTimer = null;
+ _t._a = null;
+ _t._html5_canplay = false;
+ _t.bytesLoaded = null;
+ _t.bytesTotal = null;
+ _t.duration = (_t._iO && _t._iO.duration ? _t._iO.duration : null);
+ _t.durationEstimate = null;
+
+ // legacy: 1D array
+ _t.eqData = [];
+
+ _t.eqData.left = [];
+ _t.eqData.right = [];
+
+ _t.failures = 0;
+ _t.isBuffering = false;
+ _t.instanceOptions = {};
+ _t.instanceCount = 0;
+ _t.loaded = false;
+ _t.metadata = {};
+
+ // 0 = uninitialised, 1 = loading, 2 = failed/error, 3 = loaded/success
+ _t.readyState = 0;
+
+ _t.muted = false;
+ _t.paused = false;
+
+ _t.peakData = {
+ left: 0,
+ right: 0
+ };
+
+ _t.waveformData = {
+ left: [],
+ right: []
+ };
+
+ _t.playState = 0;
+ _t.position = null;
+
+ };
+
+ _resetProperties();
+
+ /**
+ * Pseudo-private SMSound internals
+ * --------------------------------
+ */
+
+ this._onTimer = function(bForce) {
+
+ /**
+ * HTML5-only _whileplaying() etc.
+ * called from both HTML5 native events, and polling/interval-based timers
+ * mimics flash and fires only when time/duration change, so as to be polling-friendly
+ */
+
+ var duration, isNew = false, time, x = {};
+
+ if (_t._hasTimer || bForce) {
+
+ // TODO: May not need to track readyState (1 = loading)
+
+ if (_t._a && (bForce || ((_t.playState > 0 || _t.readyState === 1) && !_t.paused))) {
+
+ duration = _t._get_html5_duration();
+
+ if (duration !== _lastHTML5State.duration) {
+
+ _lastHTML5State.duration = duration;
+ _t.duration = duration;
+ isNew = true;
+
+ }
+
+ // TODO: investigate why this goes wack if not set/re-set each time.
+ _t.durationEstimate = _t.duration;
+
+ time = (_t._a.currentTime * 1000 || 0);
+
+ if (time !== _lastHTML5State.time) {
+
+ _lastHTML5State.time = time;
+ isNew = true;
+
+ }
+
+ if (isNew || bForce) {
+
+ _t._whileplaying(time,x,x,x,x);
+
+ }
+
+ return isNew;
+
+ } else {
+
+ // _s._wD('_onTimer: Warn for "'+_t.sID+'": '+(!_t._a?'Could not find element. ':'')+(_t.playState === 0?'playState bad, 0?':'playState = '+_t.playState+', OK'));
+
+ return false;
+
+ }
+
+ }
+
+ };
+
+ this._get_html5_duration = function() {
+
+ var _iO = _t._iO,
+ d = (_t._a ? _t._a.duration*1000 : (_iO ? _iO.duration : undefined)),
+ result = (d && !isNaN(d) && d !== Infinity ? d : (_iO ? _iO.duration : null));
+
+ return result;
+
+ };
+
+ this._setup_html5 = function(oOptions) {
+
+ var _iO = _mixin(_t._iO, oOptions), d = decodeURI,
+ _a = _useGlobalHTML5Audio ? _s._global_a : _t._a,
+ _dURL = d(_iO.url),
+ _oldIO = (_a && _a._t ? _a._t.instanceOptions : null);
+
+ if (_a) {
+
+ if (_a._t) {
+
+ if (!_useGlobalHTML5Audio && _dURL === d(_lastURL)) {
+ // same url, ignore request
+ return _a;
+ } else if (_useGlobalHTML5Audio && _oldIO.url === _iO.url && (!_lastURL || (_lastURL === _oldIO.url))) {
+ // iOS-type reuse case
+ return _a;
+ }
+
+ }
+
+ _s._wD('setting new URL on existing object: ' + _dURL + (_lastURL ? ', old URL: ' + _lastURL : ''));
+
+ /**
+ * "First things first, I, Poppa.." (reset the previous state of the old sound, if playing)
+ * Fixes case with devices that can only play one sound at a time
+ * Otherwise, other sounds in mid-play will be terminated without warning and in a stuck state
+ */
+
+ if (_useGlobalHTML5Audio && _a._t && _a._t.playState && _iO.url !== _oldIO.url) {
+ _a._t.stop();
+ }
+
+ // new URL, so reset load/playstate and so on
+ _resetProperties();
+
+ _a.src = _iO.url;
+ _t.url = _iO.url;
+ _lastURL = _iO.url;
+ _a._called_load = false;
+
+ } else {
+
+ _s._wD('creating HTML5 Audio() element with URL: '+_dURL);
+ _a = new Audio(_iO.url);
+
+ _a._called_load = false;
+
+ // android (seen in 2.3/Honeycomb) sometimes fails first .load() -> .play(), results in playback failure and ended() events?
+ if (_is_android) {
+ _a._called_load = true;
+ }
+
+ if (_useGlobalHTML5Audio) {
+ _s._global_a = _a;
+ }
+
+ }
+
+ _t.isHTML5 = true;
+
+ // store a ref on the track
+ _t._a = _a;
+
+ // store a ref on the audio
+ _a._t = _t;
+
+ _add_html5_events();
+ _a.loop = (_iO.loops>1?'loop':'');
+
+ if (_iO.autoLoad || _iO.autoPlay) {
+
+ _t.load();
+
+ } else {
+
+ // early HTML5 implementation (non-standard)
+ _a.autobuffer = false;
+
+ // standard
+ _a.preload = 'none';
+
+ }
+
+ // boolean instead of "loop", for webkit? - spec says string. http://www.w3.org/TR/html-markup/audio.html#audio.attrs.loop
+ _a.loop = (_iO.loops > 1 ? 'loop' : '');
+
+ return _a;
+
+ };
+
+ _add_html5_events = function() {
+
+ if (_t._a._added_events) {
+ return false;
+ }
+
+ var f;
+
+ function add(oEvt, oFn, bCapture) {
+ return _t._a ? _t._a.addEventListener(oEvt, oFn, bCapture||false) : null;
+ }
+
+ _s._wD(_h5+'adding event listeners: '+_t.sID);
+ _t._a._added_events = true;
+
+ for (f in _html5_events) {
+ if (_html5_events.hasOwnProperty(f)) {
+ add(f, _html5_events[f]);
+ }
+ }
+
+ return true;
+
+ };
+
+ _remove_html5_events = function() {
+
+ // Remove event listeners
+
+ var f;
+
+ function remove(oEvt, oFn, bCapture) {
+ return (_t._a ? _t._a.removeEventListener(oEvt, oFn, bCapture||false) : null);
+ }
+
+ _s._wD(_h5+'removing event listeners: '+_t.sID);
+ _t._a._added_events = false;
+
+ for (f in _html5_events) {
+ if (_html5_events.hasOwnProperty(f)) {
+ remove(f, _html5_events[f]);
+ }
+ }
+
+ };
+
+ /**
+ * Pseudo-private event internals
+ * ------------------------------
+ */
+
+ this._onload = function(nSuccess) {
+
+
+ var fN, loadOK = !!(nSuccess);
+ _s._wD(fN + '"' + _t.sID + '"' + (loadOK?' loaded.':' failed to load? - ' + _t.url), (loadOK?1:2));
+
+ // <d>
+ fN = 'SMSound._onload(): ';
+ if (!loadOK && !_t.isHTML5) {
+ if (_s.sandbox.noRemote === true) {
+ _s._wD(fN + _str('noNet'), 1);
+ }
+ if (_s.sandbox.noLocal === true) {
+ _s._wD(fN + _str('noLocal'), 1);
+ }
+ }
+ // </d>
+
+ _t.loaded = loadOK;
+ _t.readyState = loadOK?3:2;
+ _t._onbufferchange(0);
+
+ if (_t._iO.onload) {
+ _t._iO.onload.apply(_t, [loadOK]);
+ }
+
+ return true;
+
+ };
+
+ this._onbufferchange = function(nIsBuffering) {
+
+ if (_t.playState === 0) {
+ // ignore if not playing
+ return false;
+ }
+
+ if ((nIsBuffering && _t.isBuffering) || (!nIsBuffering && !_t.isBuffering)) {
+ return false;
+ }
+
+ _t.isBuffering = (nIsBuffering === 1);
+ if (_t._iO.onbufferchange) {
+ _s._wD('SMSound._onbufferchange(): ' + nIsBuffering);
+ _t._iO.onbufferchange.apply(_t);
+ }
+
+ return true;
+
+ };
+
+ /**
+ * Notify Mobile Safari that user action is required
+ * to continue playing / loading the audio file.
+ */
+
+ this._onsuspend = function() {
+
+ if (_t._iO.onsuspend) {
+ _s._wD('SMSound._onsuspend()');
+ _t._iO.onsuspend.apply(_t);
+ }
+
+ return true;
+
+ };
+
+ /**
+ * flash 9/movieStar + RTMP-only method, should fire only once at most
+ * at this point we just recreate failed sounds rather than trying to reconnect
+ */
+
+ this._onfailure = function(msg, level, code) {
+
+ _t.failures++;
+ _s._wD('SMSound._onfailure(): "'+_t.sID+'" count '+_t.failures);
+
+ if (_t._iO.onfailure && _t.failures === 1) {
+ _t._iO.onfailure(_t, msg, level, code);
+ } else {
+ _s._wD('SMSound._onfailure(): ignoring');
+ }
+
+ };
+
+ this._onfinish = function() {
+
+ // store local copy before it gets trashed..
+ var _io_onfinish = _t._iO.onfinish;
+
+ _t._onbufferchange(0);
+ _t._resetOnPosition(0);
+
+ // reset some state items
+ if (_t.instanceCount) {
+
+ _t.instanceCount--;
+
+ if (!_t.instanceCount) {
+
+ // remove onPosition listeners, if any
+ _detachOnPosition();
+
+ // reset instance options
+ _t.playState = 0;
+ _t.paused = false;
+ _t.instanceCount = 0;
+ _t.instanceOptions = {};
+ _t._iO = {};
+ _stop_html5_timer();
+
+ }
+
+ if (!_t.instanceCount || _t._iO.multiShotEvents) {
+ // fire onfinish for last, or every instance
+ if (_io_onfinish) {
+ _s._wD('SMSound._onfinish(): "' + _t.sID + '"');
+ _io_onfinish.apply(_t);
+ }
+ }
+
+ }
+
+ };
+
+ this._whileloading = function(nBytesLoaded, nBytesTotal, nDuration, nBufferLength) {
+
+ var _iO = _t._iO;
+
+ _t.bytesLoaded = nBytesLoaded;
+ _t.bytesTotal = nBytesTotal;
+ _t.duration = Math.floor(nDuration);
+ _t.bufferLength = nBufferLength;
+
+ if (!_iO.isMovieStar) {
+
+ if (_iO.duration) {
+ // use options, if specified and larger
+ _t.durationEstimate = (_t.duration > _iO.duration) ? _t.duration : _iO.duration;
+ } else {
+ _t.durationEstimate = parseInt((_t.bytesTotal / _t.bytesLoaded) * _t.duration, 10);
+
+ }
+
+ if (_t.durationEstimate === undefined) {
+ _t.durationEstimate = _t.duration;
+ }
+
+ if (_t.readyState !== 3 && _iO.whileloading) {
+ _iO.whileloading.apply(_t);
+ }
+
+ } else {
+
+ _t.durationEstimate = _t.duration;
+ if (_t.readyState !== 3 && _iO.whileloading) {
+ _iO.whileloading.apply(_t);
+ }
+
+ }
+
+ };
+
+ this._whileplaying = function(nPosition, oPeakData, oWaveformDataLeft, oWaveformDataRight, oEQData) {
+
+ var _iO = _t._iO;
+
+ if (isNaN(nPosition) || nPosition === null) {
+ // flash safety net
+ return false;
+ }
+
+ _t.position = nPosition;
+ _t._processOnPosition();
+
+ if (!_t.isHTML5 && _fV > 8) {
+
+ if (_iO.usePeakData && typeof oPeakData !== 'undefined' && oPeakData) {
+ _t.peakData = {
+ left: oPeakData.leftPeak,
+ right: oPeakData.rightPeak
+ };
+ }
+
+ if (_iO.useWaveformData && typeof oWaveformDataLeft !== 'undefined' && oWaveformDataLeft) {
+ _t.waveformData = {
+ left: oWaveformDataLeft.split(','),
+ right: oWaveformDataRight.split(',')
+ };
+ }
+
+ if (_iO.useEQData) {
+ if (typeof oEQData !== 'undefined' && oEQData && oEQData.leftEQ) {
+ var eqLeft = oEQData.leftEQ.split(',');
+ _t.eqData = eqLeft;
+ _t.eqData.left = eqLeft;
+ if (typeof oEQData.rightEQ !== 'undefined' && oEQData.rightEQ) {
+ _t.eqData.right = oEQData.rightEQ.split(',');
+ }
+ }
+ }
+
+ }
+
+ if (_t.playState === 1) {
+
+ // special case/hack: ensure buffering is false if loading from cache (and not yet started)
+ if (!_t.isHTML5 && _fV === 8 && !_t.position && _t.isBuffering) {
+ _t._onbufferchange(0);
+ }
+
+ if (_iO.whileplaying) {
+ // flash may call after actual finish
+ _iO.whileplaying.apply(_t);
+ }
+
+ }
+
+ return true;
+
+ };
+
+ this._onmetadata = function(oMDProps, oMDData) {
+
+ /**
+ * internal: flash 9 + NetStream (MovieStar/RTMP-only) feature
+ * RTMP may include song title, MovieStar content may include encoding info
+ *
+ * @param {array} oMDProps (names)
+ * @param {array} oMDData (values)
+ */
+
+ _s._wD('SMSound._onmetadata(): "' + this.sID + '" metadata received.');
+
+ var oData = {}, i, j;
+
+ for (i = 0, j = oMDProps.length; i < j; i++) {
+ oData[oMDProps[i]] = oMDData[i];
+ }
+ _t.metadata = oData;
+
+ if (_t._iO.onmetadata) {
+ _t._iO.onmetadata.apply(_t);
+ }
+
+ };
+
+ this._onid3 = function(oID3Props, oID3Data) {
+
+ /**
+ * internal: flash 8 + flash 9 ID3 feature
+ * may include artist, song title etc.
+ *
+ * @param {array} oID3Props (names)
+ * @param {array} oID3Data (values)
+ */
+
+ _s._wD('SMSound._onid3(): "' + this.sID + '" ID3 data received.');
+
+ var oData = [], i, j;
+
+ for (i = 0, j = oID3Props.length; i < j; i++) {
+ oData[oID3Props[i]] = oID3Data[i];
+ }
+ _t.id3 = _mixin(_t.id3, oData);
+
+ if (_t._iO.onid3) {
+ _t._iO.onid3.apply(_t);
+ }
+
+ };
+
+ // flash/RTMP-only
+
+ this._onconnect = function(bSuccess) {
+
+ bSuccess = (bSuccess === 1);
+ _s._wD('SMSound._onconnect(): "'+_t.sID+'"'+(bSuccess?' connected.':' failed to connect? - '+_t.url), (bSuccess?1:2));
+ _t.connected = bSuccess;
+
+ if (bSuccess) {
+
+ _t.failures = 0;
+
+ if (_idCheck(_t.sID)) {
+ if (_t.getAutoPlay()) {
+ // only update the play state if auto playing
+ _t.play(undefined, _t.getAutoPlay());
+ } else if (_t._iO.autoLoad) {
+ _t.load();
+ }
+ }
+
+ if (_t._iO.onconnect) {
+ _t._iO.onconnect.apply(_t, [bSuccess]);
+ }
+
+ }
+
+ };
+
+ this._ondataerror = function(sError) {
+
+ // flash 9 wave/eq data handler
+ // hack: called at start, and end from flash at/after onfinish()
+ if (_t.playState > 0) {
+ _s._wD('SMSound._ondataerror(): ' + sError);
+ if (_t._iO.ondataerror) {
+ _t._iO.ondataerror.apply(_t);
+ }
+ }
+
+ };
+
+ }; // SMSound()
+
+ /**
+ * Private SoundManager internals
+ * ------------------------------
+ */
+
+ _getDocument = function() {
+
+ return (_doc.body || _doc._docElement || _doc.getElementsByTagName('div')[0]);
+
+ };
+
+ _id = function(sID) {
+
+ return _doc.getElementById(sID);
+
+ };
+
+ _mixin = function(oMain, oAdd) {
+
+ // non-destructive merge
+ var o1 = {}, i, o2, o;
+
+ // clone c1
+ for (i in oMain) {
+ if (oMain.hasOwnProperty(i)) {
+ o1[i] = oMain[i];
+ }
+ }
+
+ o2 = (typeof oAdd === 'undefined'?_s.defaultOptions:oAdd);
+ for (o in o2) {
+ if (o2.hasOwnProperty(o) && typeof o1[o] === 'undefined') {
+ o1[o] = o2[o];
+ }
+ }
+ return o1;
+
+ };
+
+ _event = (function() {
+
+ var old = (_win.attachEvent),
+ evt = {
+ add: (old?'attachEvent':'addEventListener'),
+ remove: (old?'detachEvent':'removeEventListener')
+ };
+
+ function getArgs(oArgs) {
+
+ var args = _slice.call(oArgs), len = args.length;
+
+ if (old) {
+ // prefix
+ args[1] = 'on' + args[1];
+ if (len > 3) {
+ // no capture
+ args.pop();
+ }
+ } else if (len === 3) {
+ args.push(false);
+ }
+
+ return args;
+
+ }
+
+ function apply(args, sType) {
+
+ var element = args.shift(),
+ method = [evt[sType]];
+
+ if (old) {
+ element[method](args[0], args[1]);
+ } else {
+ element[method].apply(element, args);
+ }
+
+ }
+
+ function add() {
+
+ apply(getArgs(arguments), 'add');
+
+ }
+
+ function remove() {
+
+ apply(getArgs(arguments), 'remove');
+
+ }
+
+ return {
+ 'add': add,
+ 'remove': remove
+ };
+
+ }());
+
+ /**
+ * Internal HTML5 event handling
+ * -----------------------------
+ */
+
+ function _html5_event(oFn) {
+
+ // wrap html5 event handlers so we don't call them on destroyed sounds
+
+ return function(e) {
+
+ var t = this._t;
+
+ if (!t || !t._a) {
+ // <d>
+ if (t && t.sID) {
+ _s._wD(_h5+'ignoring '+e.type+': '+t.sID);
+ } else {
+ _s._wD(_h5+'ignoring '+e.type);
+ }
+ // </d>
+ return null;
+ } else {
+ return oFn.call(this, e);
+ }
+
+ };
+
+ }
+
+ _html5_events = {
+
+ // HTML5 event-name-to-handler map
+
+ abort: _html5_event(function(e) {
+
+ _s._wD(_h5+'abort: '+this._t.sID);
+
+ }),
+
+ // enough has loaded to play
+
+ canplay: _html5_event(function(e) {
+
+ var t = this._t;
+
+ if (t._html5_canplay) {
+ // this event has already fired. ignore.
+ return true;
+ }
+
+ t._html5_canplay = true;
+ _s._wD(_h5+'canplay: '+t.sID+', '+t.url);
+ t._onbufferchange(0);
+ var position1K = (!isNaN(t.position)?t.position/1000:null);
+
+ // set the position if position was set before the sound loaded
+ if (t.position && this.currentTime !== position1K) {
+ _s._wD(_h5+'canplay: setting position to '+position1K);
+ try {
+ this.currentTime = position1K;
+ } catch(ee) {
+ _s._wD(_h5+'setting position failed: '+ee.message, 2);
+ }
+ }
+
+ // hack for HTML5 from/to case
+ if (t._iO._oncanplay) {
+ t._iO._oncanplay();
+ }
+
+ }),
+
+ load: _html5_event(function(e) {
+
+ var t = this._t;
+
+ if (!t.loaded) {
+ t._onbufferchange(0);
+ // should be 1, and the same
+ t._whileloading(t.bytesTotal, t.bytesTotal, t._get_html5_duration());
+ t._onload(true);
+ }
+
+ }),
+
+ emptied: _html5_event(function(e) {
+
+ _s._wD(_h5+'emptied: '+this._t.sID);
+
+ }),
+
+ ended: _html5_event(function(e) {
+
+ var t = this._t;
+
+ _s._wD(_h5+'ended: '+t.sID);
+ t._onfinish();
+
+ }),
+
+ error: _html5_event(function(e) {
+
+ _s._wD(_h5+'error: '+this.error.code);
+ // call load with error state?
+ this._t._onload(false);
+
+ }),
+
+ loadeddata: _html5_event(function(e) {
+
+ var t = this._t,
+ // at least 1 byte, so math works
+ bytesTotal = t.bytesTotal || 1;
+
+ _s._wD(_h5+'loadeddata: '+this._t.sID);
+
+ // safari seems to nicely report progress events, eventually totalling 100%
+ if (!t._loaded && !_isSafari) {
+ t.duration = t._get_html5_duration();
+ // fire whileloading() with 100% values
+ t._whileloading(bytesTotal, bytesTotal, t._get_html5_duration());
+ t._onload(true);
+ }
+
+ }),
+
+ loadedmetadata: _html5_event(function(e) {
+
+ _s._wD(_h5+'loadedmetadata: '+this._t.sID);
+
+ }),
+
+ loadstart: _html5_event(function(e) {
+
+ _s._wD(_h5+'loadstart: '+this._t.sID);
+ // assume buffering at first
+ this._t._onbufferchange(1);
+
+ }),
+
+ play: _html5_event(function(e) {
+
+ _s._wD(_h5+'play: '+this._t.sID+', '+this._t.url);
+ // once play starts, no buffering
+ this._t._onbufferchange(0);
+
+ }),
+
+ playing: _html5_event(function(e) {
+
+ _s._wD(_h5+'playing: '+this._t.sID);
+
+ // once play starts, no buffering
+ this._t._onbufferchange(0);
+
+ }),
+
+ progress: _html5_event(function(e) {
+
+ var t = this._t;
+
+ if (t.loaded) {
+ return false;
+ }
+
+ var i, j, str, buffered = 0,
+ isProgress = (e.type === 'progress'),
+ ranges = e.target.buffered,
+
+ // firefox 3.6 implements e.loaded/total (bytes)
+ loaded = (e.loaded||0),
+
+ total = (e.total||1);
+
+ if (ranges && ranges.length) {
+
+ // if loaded is 0, try TimeRanges implementation as % of load
+ // https://developer.mozilla.org/en/DOM/TimeRanges
+
+ for (i=ranges.length; i--;) {
+ buffered = (ranges.end(i) - ranges.start(i));
+ }
+
+ // linear case, buffer sum; does not account for seeking and HTTP partials / byte ranges
+ loaded = buffered/e.target.duration;
+
+ // <d>
+ if (isProgress && ranges.length > 1) {
+ str = [];
+ j = ranges.length;
+ for (i=0; i<j; i++) {
+ str.push(e.target.buffered.start(i) +'-'+ e.target.buffered.end(i));
+ }
+ _s._wD(_h5+'progress: timeRanges: '+str.join(', '));
+ }
+
+ if (isProgress && !isNaN(loaded)) {
+ _s._wD(_h5+'progress: '+t.sID+': ' + Math.floor(loaded*100)+'% loaded');
+ }
+ // </d>
+
+ }
+
+ if (!isNaN(loaded)) {
+
+ // if progress, likely not buffering
+ t._onbufferchange(0);
+ t._whileloading(loaded, total, t._get_html5_duration());
+ if (loaded && total && loaded === total) {
+ // in case "onload" doesn't fire (eg. gecko 1.9.2)
+ _html5_events.load.call(this, e);
+ }
+
+ }
+
+ }),
+
+ ratechange: _html5_event(function(e) {
+
+ _s._wD(_h5+'ratechange: '+this._t.sID);
+
+ }),
+
+ suspend: _html5_event(function(e) {
+
+ // download paused/stopped, may have finished (eg. onload)
+ var t = this._t;
+
+ _s._wD(_h5+'suspend: '+t.sID);
+ _html5_events.progress.call(this, e);
+ t._onsuspend();
+
+ }),
+
+ stalled: _html5_event(function(e) {
+
+ _s._wD(_h5+'stalled: '+this._t.sID);
+
+ }),
+
+ timeupdate: _html5_event(function(e) {
+
+ this._t._onTimer();
+
+ }),
+
+ waiting: _html5_event(function(e) {
+
+ var t = this._t;
+
+ // see also: seeking
+ _s._wD(_h5+'waiting: '+t.sID);
+
+ // playback faster than download rate, etc.
+ t._onbufferchange(1);
+
+ })
+
+ };
+
+ _html5OK = function(iO) {
+
+ // Use type, if specified. If HTML5-only mode, no other options, so just give 'er
+ return (!iO.serverURL && (iO.type?_html5CanPlay({type:iO.type}):_html5CanPlay({url:iO.url})||_s.html5Only));
+
+ };
+
+ _html5Unload = function(oAudio) {
+
+ /**
+ * Internal method: Unload media, and cancel any current/pending network requests.
+ * Firefox can load an empty URL, which allegedly destroys the decoder and stops the download.
+ * https://developer.mozilla.org/En/Using_audio_and_video_in_Firefox#Stopping_the_download_of_media
+ * Other UA behaviour is unclear, so everyone else gets an about:blank-style URL.
+ */
+
+ if (oAudio) {
+ // Firefox likes '' for unload, most other UAs don't and fail to unload.
+ oAudio.src = (_is_firefox ? '' : _emptyURL);
+ }
+
+ };
+
+ _html5CanPlay = function(o) {
+
+ /**
+ * Try to find MIME, test and return truthiness
+ * o = {
+ * url: '/path/to/an.mp3',
+ * type: 'audio/mp3'
+ * }
+ */
+
+ if (!_s.useHTML5Audio || !_s.hasHTML5) {
+ return false;
+ }
+
+ var url = (o.url || null),
+ mime = (o.type || null),
+ aF = _s.audioFormats,
+ result,
+ offset,
+ fileExt,
+ item;
+
+ function preferFlashCheck(kind) {
+
+ // whether flash should play a given type
+ return (_s.preferFlash && _hasFlash && !_s.ignoreFlash && (typeof _s.flash[kind] !== 'undefined' && _s.flash[kind]));
+
+ }
+
+ // account for known cases like audio/mp3
+
+ if (mime && _s.html5[mime] !== 'undefined') {
+ return (_s.html5[mime] && !preferFlashCheck(mime));
+ }
+
+ if (!_html5Ext) {
+ _html5Ext = [];
+ for (item in aF) {
+ if (aF.hasOwnProperty(item)) {
+ _html5Ext.push(item);
+ if (aF[item].related) {
+ _html5Ext = _html5Ext.concat(aF[item].related);
+ }
+ }
+ }
+ _html5Ext = new RegExp('\\.('+_html5Ext.join('|')+')(\\?.*)?$','i');
+ }
+
+ // TODO: Strip URL queries, etc.
+ fileExt = (url ? url.toLowerCase().match(_html5Ext) : null);
+
+ if (!fileExt || !fileExt.length) {
+ if (!mime) {
+ return false;
+ } else {
+ // audio/mp3 -> mp3, result should be known
+ offset = mime.indexOf(';');
+ // strip "audio/X; codecs.."
+ fileExt = (offset !== -1?mime.substr(0,offset):mime).substr(6);
+ }
+ } else {
+ // match the raw extension name - "mp3", for example
+ fileExt = fileExt[1];
+ }
+
+ if (fileExt && typeof _s.html5[fileExt] !== 'undefined') {
+ // result known
+ return (_s.html5[fileExt] && !preferFlashCheck(fileExt));
+ } else {
+ mime = 'audio/'+fileExt;
+ result = _s.html5.canPlayType({type:mime});
+ _s.html5[fileExt] = result;
+ // _s._wD('canPlayType, found result: '+result);
+ return (result && _s.html5[mime] && !preferFlashCheck(mime));
+ }
+
+ };
+
+ _testHTML5 = function() {
+
+ if (!_s.useHTML5Audio || typeof Audio === 'undefined') {
+ return false;
+ }
+
+ // double-whammy: Opera 9.64 throws WRONG_ARGUMENTS_ERR if no parameter passed to Audio(), and Webkit + iOS happily tries to load "null" as a URL. :/
+ var a = (typeof Audio !== 'undefined' ? (_isOpera ? new Audio(null) : new Audio()) : null),
+ item, support = {}, aF, i;
+
+ function _cp(m) {
+
+ var canPlay, i, j, isOK = false;
+
+ if (!a || typeof a.canPlayType !== 'function') {
+ return false;
+ }
+
+ if (m instanceof Array) {
+ // iterate through all mime types, return any successes
+ for (i=0, j=m.length; i<j && !isOK; i++) {
+ if (_s.html5[m[i]] || a.canPlayType(m[i]).match(_s.html5Test)) {
+ isOK = true;
+ _s.html5[m[i]] = true;
+
+ // if flash can play and preferred, also mark it for use.
+ _s.flash[m[i]] = !!(_s.preferFlash && _hasFlash && m[i].match(_flashMIME));
+
+ }
+ }
+ return isOK;
+ } else {
+ canPlay = (a && typeof a.canPlayType === 'function' ? a.canPlayType(m) : false);
+ return !!(canPlay && (canPlay.match(_s.html5Test)));
+ }
+
+ }
+
+ // test all registered formats + codecs
+
+ aF = _s.audioFormats;
+
+ for (item in aF) {
+ if (aF.hasOwnProperty(item)) {
+ support[item] = _cp(aF[item].type);
+
+ // write back generic type too, eg. audio/mp3
+ support['audio/'+item] = support[item];
+
+ // assign flash
+ if (_s.preferFlash && !_s.ignoreFlash && item.match(_flashMIME)) {
+ _s.flash[item] = true;
+ } else {
+ _s.flash[item] = false;
+ }
+
+ // assign result to related formats, too
+ if (aF[item] && aF[item].related) {
+ for (i=aF[item].related.length; i--;) {
+ // eg. audio/m4a
+ support['audio/'+aF[item].related[i]] = support[item];
+ _s.html5[aF[item].related[i]] = support[item];
+ _s.flash[aF[item].related[i]] = support[item];
+ }
+ }
+ }
+ }
+
+ support.canPlayType = (a?_cp:null);
+ _s.html5 = _mixin(_s.html5, support);
+
+ return true;
+
+ };
+
+ _strings = {
+
+ // <d>
+ notReady: 'Not loaded yet - wait for soundManager.onload()/onready()',
+ notOK: 'Audio support is not available.',
+ domError: _smc + 'createMovie(): appendChild/innerHTML call failed. DOM not ready or other error.',
+ spcWmode: _smc + 'createMovie(): Removing wmode, preventing known SWF loading issue(s)',
+ swf404: _sm + ': Verify that %s is a valid path.',
+ tryDebug: 'Try ' + _sm + '.debugFlash = true for more security details (output goes to SWF.)',
+ checkSWF: 'See SWF output for more debug info.',
+ localFail: _sm + ': Non-HTTP page (' + _doc.location.protocol + ' URL?) Review Flash player security settings for this special case:\nhttp://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html\nMay need to add/allow path, eg. c:/sm2/ or /users/me/sm2/',
+ waitFocus: _sm + ': Special case: Waiting for focus-related event..',
+ waitImpatient: _sm + ': Getting impatient, still waiting for Flash%s...',
+ waitForever: _sm + ': Waiting indefinitely for Flash (will recover if unblocked)...',
+ needFunction: _sm + ': Function object expected for %s',
+ badID: 'Warning: Sound ID "%s" should be a string, starting with a non-numeric character',
+ currentObj: '--- ' + _sm + '._debug(): Current sound objects ---',
+ waitEI: _smc + 'initMovie(): Waiting for ExternalInterface call from Flash..',
+ waitOnload: _sm + ': Waiting for window.onload()',
+ docLoaded: _sm + ': Document already loaded',
+ onload: _smc + 'initComplete(): calling soundManager.onload()',
+ onloadOK: _sm + '.onload() complete',
+ init: _smc + 'init()',
+ didInit: _smc + 'init(): Already called?',
+ flashJS: _sm + ': Attempting to call Flash from JS..',
+ secNote: 'Flash security note: Network/internet URLs will not load due to security restrictions. Access can be configured via Flash Player Global Security Settings Page: http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html',
+ badRemove: 'Warning: Failed to remove flash movie.',
+ noPeak: 'Warning: peakData features unsupported for movieStar formats',
+ shutdown: _sm + '.disable(): Shutting down',
+ queue: _sm + ': Queueing %s handler',
+ smFail: _sm + ': Failed to initialise.',
+ smError: 'SMSound.load(): Exception: JS-Flash communication failed, or JS error.',
+ fbTimeout: 'No flash response, applying .'+_swfCSS.swfTimedout+' CSS..',
+ fbLoaded: 'Flash loaded',
+ fbHandler: _smc+'flashBlockHandler()',
+ manURL: 'SMSound.load(): Using manually-assigned URL',
+ onURL: _sm + '.load(): current URL already assigned.',
+ badFV: _sm + '.flashVersion must be 8 or 9. "%s" is invalid. Reverting to %s.',
+ as2loop: 'Note: Setting stream:false so looping can work (flash 8 limitation)',
+ noNSLoop: 'Note: Looping not implemented for MovieStar formats',
+ needfl9: 'Note: Switching to flash 9, required for MP4 formats.',
+ mfTimeout: 'Setting flashLoadTimeout = 0 (infinite) for off-screen, mobile flash case',
+ mfOn: 'mobileFlash::enabling on-screen flash repositioning',
+ policy: 'Enabling usePolicyFile for data access'
+ // </d>
+
+ };
+
+ _str = function() {
+
+ // internal string replace helper.
+ // arguments: o [,items to replace]
+ // <d>
+
+ // real array, please
+ var args = _slice.call(arguments),
+
+ // first arg
+ o = args.shift(),
+
+ str = (_strings && _strings[o]?_strings[o]:''), i, j;
+ if (str && args && args.length) {
+ for (i = 0, j = args.length; i < j; i++) {
+ str = str.replace('%s', args[i]);
+ }
+ }
+
+ return str;
+ // </d>
+
+ };
+
+ _loopFix = function(sOpt) {
+
+ // flash 8 requires stream = false for looping to work
+ if (_fV === 8 && sOpt.loops > 1 && sOpt.stream) {
+ _wDS('as2loop');
+ sOpt.stream = false;
+ }
+
+ return sOpt;
+
+ };
+
+ _policyFix = function(sOpt, sPre) {
+
+ if (sOpt && !sOpt.usePolicyFile && (sOpt.onid3 || sOpt.usePeakData || sOpt.useWaveformData || sOpt.useEQData)) {
+ _s._wD((sPre || '') + _str('policy'));
+ sOpt.usePolicyFile = true;
+ }
+
+ return sOpt;
+
+ };
+
+ _complain = function(sMsg) {
+
+ // <d>
+ if (typeof console !== 'undefined' && typeof console.warn !== 'undefined') {
+ console.warn(sMsg);
+ } else {
+ _s._wD(sMsg);
+ }
+ // </d>
+
+ };
+
+ _doNothing = function() {
+
+ return false;
+
+ };
+
+ _disableObject = function(o) {
+
+ var oProp;
+
+ for (oProp in o) {
+ if (o.hasOwnProperty(oProp) && typeof o[oProp] === 'function') {
+ o[oProp] = _doNothing;
+ }
+ }
+
+ oProp = null;
+
+ };
+
+ _failSafely = function(bNoDisable) {
+
+ // general failure exception handler
+
+ if (typeof bNoDisable === 'undefined') {
+ bNoDisable = false;
+ }
+
+ if (_disabled || bNoDisable) {
+ _wDS('smFail', 2);
+ _s.disable(bNoDisable);
+ }
+
+ };
+
+ _normalizeMovieURL = function(smURL) {
+
+ var urlParams = null, url;
+
+ if (smURL) {
+ if (smURL.match(/\.swf(\?.*)?$/i)) {
+ urlParams = smURL.substr(smURL.toLowerCase().lastIndexOf('.swf?') + 4);
+ if (urlParams) {
+ // assume user knows what they're doing
+ return smURL;
+ }
+ } else if (smURL.lastIndexOf('/') !== smURL.length - 1) {
+ // append trailing slash, if needed
+ smURL += '/';
+ }
+ }
+
+ url = (smURL && smURL.lastIndexOf('/') !== - 1 ? smURL.substr(0, smURL.lastIndexOf('/') + 1) : './') + _s.movieURL;
+
+ if (_s.noSWFCache) {
+ url += ('?ts=' + new Date().getTime());
+ }
+
+ return url;
+
+ };
+
+ _setVersionInfo = function() {
+
+ // short-hand for internal use
+
+ _fV = parseInt(_s.flashVersion, 10);
+
+ if (_fV !== 8 && _fV !== 9) {
+ _s._wD(_str('badFV', _fV, _defaultFlashVersion));
+ _s.flashVersion = _fV = _defaultFlashVersion;
+ }
+
+ // debug flash movie, if applicable
+
+ var isDebug = (_s.debugMode || _s.debugFlash?'_debug.swf':'.swf');
+
+ if (_s.useHTML5Audio && !_s.html5Only && _s.audioFormats.mp4.required && _fV < 9) {
+ _s._wD(_str('needfl9'));
+ _s.flashVersion = _fV = 9;
+ }
+
+ _s.version = _s.versionNumber + (_s.html5Only?' (HTML5-only mode)':(_fV === 9?' (AS3/Flash 9)':' (AS2/Flash 8)'));
+
+ // set up default options
+ if (_fV > 8) {
+ // +flash 9 base options
+ _s.defaultOptions = _mixin(_s.defaultOptions, _s.flash9Options);
+ _s.features.buffering = true;
+ // +moviestar support
+ _s.defaultOptions = _mixin(_s.defaultOptions, _s.movieStarOptions);
+ _s.filePatterns.flash9 = new RegExp('\\.(mp3|' + _netStreamTypes.join('|') + ')(\\?.*)?$', 'i');
+ _s.features.movieStar = true;
+ } else {
+ _s.features.movieStar = false;
+ }
+
+ // regExp for flash canPlay(), etc.
+ _s.filePattern = _s.filePatterns[(_fV !== 8?'flash9':'flash8')];
+
+ // if applicable, use _debug versions of SWFs
+ _s.movieURL = (_fV === 8?'soundmanager2.swf':'soundmanager2_flash9.swf').replace('.swf', isDebug);
+
+ _s.features.peakData = _s.features.waveformData = _s.features.eqData = (_fV > 8);
+
+ };
+
+ _setPolling = function(bPolling, bHighPerformance) {
+
+ if (!_flash) {
+ return false;
+ }
+
+ _flash._setPolling(bPolling, bHighPerformance);
+
+ };
+
+ _initDebug = function() {
+
+ // starts debug mode, creating output <div> for UAs without console object
+
+ // allow force of debug mode via URL
+ if (_s.debugURLParam.test(_wl)) {
+ _s.debugMode = true;
+ }
+
+ // <d>
+ if (_id(_s.debugID)) {
+ return false;
+ }
+
+ var oD, oDebug, oTarget, oToggle, tmp;
+
+ if (_s.debugMode && !_id(_s.debugID) && (!_hasConsole || !_s.useConsole || !_s.consoleOnly)) {
+
+ oD = _doc.createElement('div');
+ oD.id = _s.debugID + '-toggle';
+
+ oToggle = {
+ 'position': 'fixed',
+ 'bottom': '0px',
+ 'right': '0px',
+ 'width': '1.2em',
+ 'height': '1.2em',
+ 'lineHeight': '1.2em',
+ 'margin': '2px',
+ 'textAlign': 'center',
+ 'border': '1px solid #999',
+ 'cursor': 'pointer',
+ 'background': '#fff',
+ 'color': '#333',
+ 'zIndex': 10001
+ };
+
+ oD.appendChild(_doc.createTextNode('-'));
+ oD.onclick = _toggleDebug;
+ oD.title = 'Toggle SM2 debug console';
+
+ if (_ua.match(/msie 6/i)) {
+ oD.style.position = 'absolute';
+ oD.style.cursor = 'hand';
+ }
+
+ for (tmp in oToggle) {
+ if (oToggle.hasOwnProperty(tmp)) {
+ oD.style[tmp] = oToggle[tmp];
+ }
+ }
+
+ oDebug = _doc.createElement('div');
+ oDebug.id = _s.debugID;
+ oDebug.style.display = (_s.debugMode?'block':'none');
+
+ if (_s.debugMode && !_id(oD.id)) {
+ try {
+ oTarget = _getDocument();
+ oTarget.appendChild(oD);
+ } catch(e2) {
+ throw new Error(_str('domError')+' \n'+e2.toString());
+ }
+ oTarget.appendChild(oDebug);
+ }
+
+ }
+
+ oTarget = null;
+ // </d>
+
+ };
+
+ _idCheck = this.getSoundById;
+
+ // <d>
+ _wDS = function(o, errorLevel) {
+
+ if (!o) {
+ return '';
+ } else {
+ return _s._wD(_str(o), errorLevel);
+ }
+
+ };
+
+ // last-resort debugging option
+
+ if (_wl.indexOf('sm2-debug=alert') + 1 && _s.debugMode) {
+ _s._wD = function(sText) {window.alert(sText);};
+ }
+
+ _toggleDebug = function() {
+
+ var o = _id(_s.debugID),
+ oT = _id(_s.debugID + '-toggle');
+
+ if (!o) {
+ return false;
+ }
+
+ if (_debugOpen) {
+ // minimize
+ oT.innerHTML = '+';
+ o.style.display = 'none';
+ } else {
+ oT.innerHTML = '-';
+ o.style.display = 'block';
+ }
+
+ _debugOpen = !_debugOpen;
+
+ };
+
+ _debugTS = function(sEventType, bSuccess, sMessage) {
+
+ // troubleshooter debug hooks
+
+ if (typeof sm2Debugger !== 'undefined') {
+ try {
+ sm2Debugger.handleEvent(sEventType, bSuccess, sMessage);
+ } catch(e) {
+ // oh well
+ }
+ }
+
+ return true;
+
+ };
+ // </d>
+
+ _getSWFCSS = function() {
+
+ var css = [];
+
+ if (_s.debugMode) {
+ css.push(_swfCSS.sm2Debug);
+ }
+
+ if (_s.debugFlash) {
+ css.push(_swfCSS.flashDebug);
+ }
+
+ if (_s.useHighPerformance) {
+ css.push(_swfCSS.highPerf);
+ }
+
+ return css.join(' ');
+
+ };
+
+ _flashBlockHandler = function() {
+
+ // *possible* flash block situation.
+
+ var name = _str('fbHandler'),
+ p = _s.getMoviePercent(),
+ css = _swfCSS,
+ error = {type:'FLASHBLOCK'};
+
+ if (_s.html5Only) {
+ return false;
+ }
+
+ if (!_s.ok()) {
+
+ if (_needsFlash) {
+ // make the movie more visible, so user can fix
+ _s.oMC.className = _getSWFCSS() + ' ' + css.swfDefault + ' ' + (p === null?css.swfTimedout:css.swfError);
+ _s._wD(name+': '+_str('fbTimeout')+(p?' ('+_str('fbLoaded')+')':''));
+ }
+
+ _s.didFlashBlock = true;
+
+ // fire onready(), complain lightly
+ _processOnEvents({type:'ontimeout', ignoreInit:true, error:error});
+ _catchError(error);
+
+ } else {
+
+ // SM2 loaded OK (or recovered)
+
+ // <d>
+ if (_s.didFlashBlock) {
+ _s._wD(name+': Unblocked');
+ }
+ // </d>
+
+ if (_s.oMC) {
+ _s.oMC.className = [_getSWFCSS(), css.swfDefault, css.swfLoaded + (_s.didFlashBlock?' '+css.swfUnblocked:'')].join(' ');
+ }
+
+ }
+
+ };
+
+ _addOnEvent = function(sType, oMethod, oScope) {
+
+ if (typeof _on_queue[sType] === 'undefined') {
+ _on_queue[sType] = [];
+ }
+
+ _on_queue[sType].push({
+ 'method': oMethod,
+ 'scope': (oScope || null),
+ 'fired': false
+ });
+
+ };
+
+ _processOnEvents = function(oOptions) {
+
+ // assume onready, if unspecified
+
+ if (!oOptions) {
+ oOptions = {
+ type: 'onready'
+ };
+ }
+
+ if (!_didInit && oOptions && !oOptions.ignoreInit) {
+ // not ready yet.
+ return false;
+ }
+
+ if (oOptions.type === 'ontimeout' && _s.ok()) {
+ // invalid case
+ return false;
+ }
+
+ var status = {
+ success: (oOptions && oOptions.ignoreInit?_s.ok():!_disabled)
+ },
+
+ // queue specified by type, or none
+ srcQueue = (oOptions && oOptions.type?_on_queue[oOptions.type]||[]:[]),
+
+ queue = [], i, j,
+ args = [status],
+ canRetry = (_needsFlash && _s.useFlashBlock && !_s.ok());
+
+ if (oOptions.error) {
+ args[0].error = oOptions.error;
+ }
+
+ for (i = 0, j = srcQueue.length; i < j; i++) {
+ if (srcQueue[i].fired !== true) {
+ queue.push(srcQueue[i]);
+ }
+ }
+
+ if (queue.length) {
+ _s._wD(_sm + ': Firing ' + queue.length + ' '+oOptions.type+'() item' + (queue.length === 1?'':'s'));
+ for (i = 0, j = queue.length; i < j; i++) {
+ if (queue[i].scope) {
+ queue[i].method.apply(queue[i].scope, args);
+ } else {
+ queue[i].method.apply(this, args);
+ }
+ if (!canRetry) {
+ // flashblock case doesn't count here
+ queue[i].fired = true;
+ }
+ }
+ }
+
+ return true;
+
+ };
+
+ _initUserOnload = function() {
+
+ _win.setTimeout(function() {
+
+ if (_s.useFlashBlock) {
+ _flashBlockHandler();
+ }
+
+ _processOnEvents();
+
+ // call user-defined "onload", scoped to window
+
+ if (_s.onload instanceof Function) {
+ _wDS('onload', 1);
+ _s.onload.apply(_win);
+ _wDS('onloadOK', 1);
+ }
+
+ if (_s.waitForWindowLoad) {
+ _event.add(_win, 'load', _initUserOnload);
+ }
+
+ },1);
+
+ };
+
+ _detectFlash = function() {
+
+ // hat tip: Flash Detect library (BSD, (C) 2007) by Carl "DocYes" S. Yestrau - http://featureblend.com/javascript-flash-detection-library.html / http://featureblend.com/license.txt
+
+ if (_hasFlash !== undefined) {
+ // this work has already been done.
+ return _hasFlash;
+ }
+
+ var hasPlugin = false, n = navigator, nP = n.plugins, obj, type, types, AX = _win.ActiveXObject;
+
+ if (nP && nP.length) {
+ type = 'application/x-shockwave-flash';
+ types = n.mimeTypes;
+ if (types && types[type] && types[type].enabledPlugin && types[type].enabledPlugin.description) {
+ hasPlugin = true;
+ }
+ } else if (typeof AX !== 'undefined') {
+ try {
+ obj = new AX('ShockwaveFlash.ShockwaveFlash');
+ } catch(e) {
+ // oh well
+ }
+ hasPlugin = (!!obj);
+ }
+
+ _hasFlash = hasPlugin;
+
+ return hasPlugin;
+
+ };
+
+ _featureCheck = function() {
+
+ var needsFlash, item,
+
+ // iPhone <= 3.1 has broken HTML5 audio(), but firmware 3.2 (iPad) + iOS4 works.
+ isSpecial = (_is_iDevice && !!(_ua.match(/os (1|2|3_0|3_1)/i)));
+
+ if (isSpecial) {
+
+ // has Audio(), but is broken; let it load links directly.
+ _s.hasHTML5 = false;
+
+ // ignore flash case, however
+ _s.html5Only = true;
+
+ if (_s.oMC) {
+ _s.oMC.style.display = 'none';
+ }
+
+ return false;
+
+ }
+
+ if (_s.useHTML5Audio) {
+
+ if (!_s.html5 || !_s.html5.canPlayType) {
+ _s._wD('SoundManager: No HTML5 Audio() support detected.');
+ _s.hasHTML5 = false;
+ return true;
+ } else {
+ _s.hasHTML5 = true;
+ }
+ if (_isBadSafari) {
+ _s._wD(_smc+'Note: Buggy HTML5 Audio in Safari on this OS X release, see https://bugs.webkit.org/show_bug.cgi?id=32159 - '+(!_hasFlash?' would use flash fallback for MP3/MP4, but none detected.':'will use flash fallback for MP3/MP4, if available'),1);
+ if (_detectFlash()) {
+ return true;
+ }
+ }
+ } else {
+
+ // flash needed (or, HTML5 needs enabling.)
+ return true;
+
+ }
+
+ for (item in _s.audioFormats) {
+ if (_s.audioFormats.hasOwnProperty(item)) {
+ if ((_s.audioFormats[item].required && !_s.html5.canPlayType(_s.audioFormats[item].type)) || _s.flash[item] || _s.flash[_s.audioFormats[item].type]) {
+ // flash may be required, or preferred for this format
+ needsFlash = true;
+ }
+ }
+ }
+
+ // sanity check..
+ if (_s.ignoreFlash) {
+ needsFlash = false;
+ }
+
+ _s.html5Only = (_s.hasHTML5 && _s.useHTML5Audio && !needsFlash);
+
+ return (!_s.html5Only);
+
+ };
+
+ _parseURL = function(url) {
+
+ /**
+ * Internal: Finds and returns the first playable URL (or failing that, the first URL.)
+ * @param {string or array} url A single URL string, OR, an array of URL strings or {url:'/path/to/resource', type:'audio/mp3'} objects.
+ */
+
+ var i, j, result = 0;
+
+ if (url instanceof Array) {
+
+ // find the first good one
+ for (i=0, j=url.length; i<j; i++) {
+
+ if (url[i] instanceof Object) {
+ // MIME check
+ if (_s.canPlayMIME(url[i].type)) {
+ result = i;
+ break;
+ }
+
+ } else if (_s.canPlayURL(url[i])) {
+ // URL string check
+ result = i;
+ break;
+ }
+
+ }
+
+ // normalize to string
+ if (url[result].url) {
+ url[result] = url[result].url;
+ }
+
+ return url[result];
+
+ } else {
+
+ // single URL case
+ return url;
+
+ }
+
+ };
+
+
+ _startTimer = function(oSound) {
+
+ /**
+ * attach a timer to this sound, and start an interval if needed
+ */
+
+ if (!oSound._hasTimer) {
+
+ oSound._hasTimer = true;
+
+ if (!_likesHTML5 && _s.html5PollingInterval) {
+
+ if (_h5IntervalTimer === null && _h5TimerCount === 0) {
+
+ _h5IntervalTimer = window.setInterval(_timerExecute, _s.html5PollingInterval);
+
+ }
+
+ _h5TimerCount++;
+
+ }
+
+ }
+
+ };
+
+ _stopTimer = function(oSound) {
+
+ /**
+ * detach a timer
+ */
+
+ if (oSound._hasTimer) {
+
+ oSound._hasTimer = false;
+
+ if (!_likesHTML5 && _s.html5PollingInterval) {
+
+ // interval will stop itself at next execution.
+
+ _h5TimerCount--;
+
+ }
+
+ }
+
+ };
+
+ _timerExecute = function() {
+
+ /**
+ * manual polling for HTML5 progress events, ie., whileplaying() (can achieve greater precision than conservative default HTML5 interval)
+ */
+
+ var i, j;
+
+ if (_h5IntervalTimer !== null && !_h5TimerCount) {
+
+ // no active timers, stop polling interval.
+
+ window.clearInterval(_h5IntervalTimer);
+
+ _h5IntervalTimer = null;
+
+ return false;
+
+ }
+
+ // check all HTML5 sounds with timers
+
+ for (i = _s.soundIDs.length; i--;) {
+
+ if (_s.sounds[_s.soundIDs[i]].isHTML5 && _s.sounds[_s.soundIDs[i]]._hasTimer) {
+
+ _s.sounds[_s.soundIDs[i]]._onTimer();
+
+ }
+
+ }
+
+ };
+
+ _catchError = function(options) {
+
+ options = (typeof options !== 'undefined' ? options : {});
+
+ if (_s.onerror instanceof Function) {
+ _s.onerror.apply(_win, [{type:(typeof options.type !== 'undefined' ? options.type : null)}]);
+ }
+
+ if (typeof options.fatal !== 'undefined' && options.fatal) {
+ _s.disable();
+ }
+
+ };
+
+ _badSafariFix = function() {
+
+ // special case: "bad" Safari (OS X 10.3 - 10.7) must fall back to flash for MP3/MP4
+ if (!_isBadSafari || !_detectFlash()) {
+ // doesn't apply
+ return false;
+ }
+
+ var aF = _s.audioFormats, i, item;
+
+ for (item in aF) {
+ if (aF.hasOwnProperty(item)) {
+ if (item === 'mp3' || item === 'mp4') {
+ _s._wD(_sm+': Using flash fallback for '+item+' format');
+ _s.html5[item] = false;
+ // assign result to related formats, too
+ if (aF[item] && aF[item].related) {
+ for (i = aF[item].related.length; i--;) {
+ _s.html5[aF[item].related[i]] = false;
+ }
+ }
+ }
+ }
+ }
+
+ };
+
+ /**
+ * Pseudo-private flash/ExternalInterface methods
+ * ----------------------------------------------
+ */
+
+ this._setSandboxType = function(sandboxType) {
+
+ // <d>
+ var sb = _s.sandbox;
+
+ sb.type = sandboxType;
+ sb.description = sb.types[(typeof sb.types[sandboxType] !== 'undefined'?sandboxType:'unknown')];
+
+ _s._wD('Flash security sandbox type: ' + sb.type);
+
+ if (sb.type === 'localWithFile') {
+
+ sb.noRemote = true;
+ sb.noLocal = false;
+ _wDS('secNote', 2);
+
+ } else if (sb.type === 'localWithNetwork') {
+
+ sb.noRemote = false;
+ sb.noLocal = true;
+
+ } else if (sb.type === 'localTrusted') {
+
+ sb.noRemote = false;
+ sb.noLocal = false;
+
+ }
+ // </d>
+
+ };
+
+ this._externalInterfaceOK = function(flashDate, swfVersion) {
+
+ // flash callback confirming flash loaded, EI working etc.
+ // flashDate = approx. timing/delay info for JS/flash bridge
+ // swfVersion: SWF build string
+
+ if (_s.swfLoaded) {
+ return false;
+ }
+
+ var e, eiTime = new Date().getTime();
+
+ _s._wD(_smc+'externalInterfaceOK()' + (flashDate?' (~' + (eiTime - flashDate) + ' ms)':''));
+ _debugTS('swf', true);
+ _debugTS('flashtojs', true);
+ _s.swfLoaded = true;
+ _tryInitOnFocus = false;
+
+ if (_isBadSafari) {
+ _badSafariFix();
+ }
+
+ // complain if JS + SWF build/version strings don't match, excluding +DEV builds
+ // <d>
+ if (!swfVersion || swfVersion.replace(/\+dev/i,'') !== _s.versionNumber.replace(/\+dev/i, '')) {
+
+ e = _sm + ': Fatal: JavaScript file build "' + _s.versionNumber + '" does not match Flash SWF build "' + swfVersion + '" at ' + _s.url + '. Ensure both are up-to-date.';
+
+ // escape flash -> JS stack so this error fires in window.
+ setTimeout(function versionMismatch() {
+ throw new Error(e);
+ }, 0);
+
+ // exit, init will fail with timeout
+ return false;
+
+ }
+ // </d>
+
+ if (_isIE) {
+ // IE needs a timeout OR delay until window.onload - may need TODO: investigating
+ setTimeout(_init, 100);
+ } else {
+ _init();
+ }
+
+ };
+
+ /**
+ * Private initialization helpers
+ * ------------------------------
+ */
+
+ _createMovie = function(smID, smURL) {
+
+ if (_didAppend && _appendSuccess) {
+ // ignore if already succeeded
+ return false;
+ }
+
+ function _initMsg() {
+ _s._wD('-- SoundManager 2 ' + _s.version + (!_s.html5Only && _s.useHTML5Audio?(_s.hasHTML5?' + HTML5 audio':', no HTML5 audio support'):'') + (!_s.html5Only ? (_s.useHighPerformance?', high performance mode, ':', ') + (( _s.flashPollingInterval ? 'custom (' + _s.flashPollingInterval + 'ms)' : 'normal') + ' polling') + (_s.wmode?', wmode: ' + _s.wmode:'') + (_s.debugFlash?', flash debug mode':'') + (_s.useFlashBlock?', flashBlock mode':'') : '') + ' --', 1);
+ }
+
+ if (_s.html5Only) {
+
+ // 100% HTML5 mode
+ _setVersionInfo();
+
+ _initMsg();
+ _s.oMC = _id(_s.movieID);
+ _init();
+
+ // prevent multiple init attempts
+ _didAppend = true;
+
+ _appendSuccess = true;
+
+ return false;
+
+ }
+
+ // flash path
+ var remoteURL = (smURL || _s.url),
+ localURL = (_s.altURL || remoteURL),
+ swfTitle = 'JS/Flash audio component (SoundManager 2)',
+ oEmbed, oMovie, oTarget = _getDocument(), tmp, movieHTML, oEl, extraClass = _getSWFCSS(),
+ s, x, sClass, side = 'auto', isRTL = null,
+ html = _doc.getElementsByTagName('html')[0];
+
+ isRTL = (html && html.dir && html.dir.match(/rtl/i));
+ smID = (typeof smID === 'undefined'?_s.id:smID);
+
+ function param(name, value) {
+ return '<param name="'+name+'" value="'+value+'" />';
+ }
+
+ // safety check for legacy (change to Flash 9 URL)
+ _setVersionInfo();
+ _s.url = _normalizeMovieURL("inc/SoundManager2/swf/");
+ smURL = _s.url;
+
+ _s.wmode = (!_s.wmode && _s.useHighPerformance ? 'transparent' : _s.wmode);
+
+ if (_s.wmode !== null && (_ua.match(/msie 8/i) || (!_isIE && !_s.useHighPerformance)) && navigator.platform.match(/win32|win64/i)) {
+ /**
+ * extra-special case: movie doesn't load until scrolled into view when using wmode = anything but 'window' here
+ * does not apply when using high performance (position:fixed means on-screen), OR infinite flash load timeout
+ * wmode breaks IE 8 on Vista + Win7 too in some cases, as of January 2011 (?)
+ */
+ _wDS('spcWmode');
+ _s.wmode = null;
+ }
+
+ oEmbed = {
+ 'name': smID,
+ 'id': smID,
+ 'src': smURL,
+ 'width': side,
+ 'height': side,
+ 'quality': 'high',
+ 'allowScriptAccess': _s.allowScriptAccess,
+ 'bgcolor': _s.bgColor,
+ 'pluginspage': _http+'www.macromedia.com/go/getflashplayer',
+ 'title': swfTitle,
+ 'type': 'application/x-shockwave-flash',
+ 'wmode': _s.wmode,
+ // http://help.adobe.com/en_US/as3/mobile/WS4bebcd66a74275c36cfb8137124318eebc6-7ffd.html
+ 'hasPriority': 'true'
+ };
+
+ if (_s.debugFlash) {
+ oEmbed.FlashVars = 'debug=1';
+ }
+
+ if (!_s.wmode) {
+ // don't write empty attribute
+ delete oEmbed.wmode;
+ }
+
+ if (_isIE) {
+
+ // IE is "special".
+ oMovie = _doc.createElement('div');
+ movieHTML = [
+ '<object id="' + smID + '" data="' + smURL + '" type="' + oEmbed.type + '" title="' + oEmbed.title +'" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="' + _http+'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="' + oEmbed.width + '" height="' + oEmbed.height + '">',
+ param('movie', smURL),
+ param('AllowScriptAccess', _s.allowScriptAccess),
+ param('quality', oEmbed.quality),
+ (_s.wmode? param('wmode', _s.wmode): ''),
+ param('bgcolor', _s.bgColor),
+ param('hasPriority', 'true'),
+ (_s.debugFlash ? param('FlashVars', oEmbed.FlashVars) : ''),
+ '</object>'
+ ].join('');
+
+ } else {
+
+ oMovie = _doc.createElement('embed');
+ for (tmp in oEmbed) {
+ if (oEmbed.hasOwnProperty(tmp)) {
+ oMovie.setAttribute(tmp, oEmbed[tmp]);
+ }
+ }
+
+ }
+
+ _initDebug();
+ extraClass = _getSWFCSS();
+ oTarget = _getDocument();
+
+ if (oTarget) {
+
+ _s.oMC = (_id(_s.movieID) || _doc.createElement('div'));
+
+ if (!_s.oMC.id) {
+
+ _s.oMC.id = _s.movieID;
+ _s.oMC.className = _swfCSS.swfDefault + ' ' + extraClass;
+ s = null;
+ oEl = null;
+
+ if (!_s.useFlashBlock) {
+ if (_s.useHighPerformance) {
+ // on-screen at all times
+ s = {
+ 'position': 'fixed',
+ 'width': '8px',
+ 'height': '8px',
+ // >= 6px for flash to run fast, >= 8px to start up under Firefox/win32 in some cases. odd? yes.
+ 'bottom': '0px',
+ 'left': '0px',
+ 'overflow': 'hidden'
+ };
+ } else {
+ // hide off-screen, lower priority
+ s = {
+ 'position': 'absolute',
+ 'width': '6px',
+ 'height': '6px',
+ 'top': '-9999px',
+ 'left': '-9999px'
+ };
+ if (isRTL) {
+ s.left = Math.abs(parseInt(s.left,10))+'px';
+ }
+ }
+ }
+
+ if (_isWebkit) {
+ // soundcloud-reported render/crash fix, safari 5
+ _s.oMC.style.zIndex = 10000;
+ }
+
+ if (!_s.debugFlash) {
+ for (x in s) {
+ if (s.hasOwnProperty(x)) {
+ _s.oMC.style[x] = s[x];
+ }
+ }
+ }
+
+ try {
+ if (!_isIE) {
+ _s.oMC.appendChild(oMovie);
+ }
+ oTarget.appendChild(_s.oMC);
+ if (_isIE) {
+ oEl = _s.oMC.appendChild(_doc.createElement('div'));
+ oEl.className = _swfCSS.swfBox;
+ oEl.innerHTML = movieHTML;
+ }
+ _appendSuccess = true;
+ } catch(e) {
+ throw new Error(_str('domError')+' \n'+e.toString());
+ }
+
+ } else {
+
+ // SM2 container is already in the document (eg. flashblock use case)
+ sClass = _s.oMC.className;
+ _s.oMC.className = (sClass?sClass+' ':_swfCSS.swfDefault) + (extraClass?' '+extraClass:'');
+ _s.oMC.appendChild(oMovie);
+ if (_isIE) {
+ oEl = _s.oMC.appendChild(_doc.createElement('div'));
+ oEl.className = _swfCSS.swfBox;
+ oEl.innerHTML = movieHTML;
+ }
+ _appendSuccess = true;
+
+ }
+
+ }
+
+ _didAppend = true;
+ _initMsg();
+ _s._wD(_smc+'createMovie(): Trying to load ' + smURL + (!_overHTTP && _s.altURL?' (alternate URL)':''), 1);
+
+ return true;
+
+ };
+
+ _initMovie = function() {
+
+ if (_s.html5Only) {
+ _createMovie();
+ return false;
+ }
+
+ // attempt to get, or create, movie
+ // may already exist
+ if (_flash) {
+ return false;
+ }
+
+ // inline markup case
+ _flash = _s.getMovie(_s.id);
+
+ if (!_flash) {
+ if (!_oRemoved) {
+ // try to create
+ _createMovie(_s.id, _s.url);
+ } else {
+ // try to re-append removed movie after reboot()
+ if (!_isIE) {
+ _s.oMC.appendChild(_oRemoved);
+ } else {
+ _s.oMC.innerHTML = _oRemovedHTML;
+ }
+ _oRemoved = null;
+ _didAppend = true;
+ }
+ _flash = _s.getMovie(_s.id);
+ }
+
+ // <d>
+ if (_flash) {
+ _wDS('waitEI');
+ }
+ // </d>
+
+ if (_s.oninitmovie instanceof Function) {
+ setTimeout(_s.oninitmovie, 1);
+ }
+
+ return true;
+
+ };
+
+ _delayWaitForEI = function() {
+
+ setTimeout(_waitForEI, 1000);
+
+ };
+
+ _waitForEI = function() {
+
+ if (_waitingForEI) {
+ return false;
+ }
+
+ _waitingForEI = true;
+ _event.remove(_win, 'load', _delayWaitForEI);
+
+ if (_tryInitOnFocus && !_isFocused) {
+ // giant Safari 3.1 hack - assume mousemove = focus given lack of focus event
+ _wDS('waitFocus');
+ return false;
+ }
+
+ var p;
+ if (!_didInit) {
+ p = _s.getMoviePercent();
+ _s._wD(_str('waitImpatient', (p === 100?' (SWF loaded)':(p > 0?' (SWF ' + p + '% loaded)':''))));
+ }
+
+ setTimeout(function() {
+
+ p = _s.getMoviePercent();
+
+ // <d>
+ if (!_didInit) {
+ _s._wD(_sm + ': No Flash response within expected time.\nLikely causes: ' + (p === 0?'Loading ' + _s.movieURL + ' may have failed (and/or Flash ' + _fV + '+ not present?), ':'') + 'Flash blocked or JS-Flash security error.' + (_s.debugFlash?' ' + _str('checkSWF'):''), 2);
+ if (!_overHTTP && p) {
+ _wDS('localFail', 2);
+ if (!_s.debugFlash) {
+ _wDS('tryDebug', 2);
+ }
+ }
+ if (p === 0) {
+ // if 0 (not null), probably a 404.
+ _s._wD(_str('swf404', _s.url));
+ }
+ _debugTS('flashtojs', false, ': Timed out' + _overHTTP?' (Check flash security or flash blockers)':' (No plugin/missing SWF?)');
+ }
+ // </d>
+
+ // give up / time-out, depending
+
+ if (!_didInit && _okToDisable) {
+ if (p === null) {
+ // SWF failed. Maybe blocked.
+ if (_s.useFlashBlock || _s.flashLoadTimeout === 0) {
+ if (_s.useFlashBlock) {
+ _flashBlockHandler();
+ }
+ _wDS('waitForever');
+ } else {
+ // old SM2 behaviour, simply fail
+ _failSafely(true);
+ }
+ } else {
+ // flash loaded? Shouldn't be a blocking issue, then.
+ if (_s.flashLoadTimeout === 0) {
+ _wDS('waitForever');
+ } else {
+ _failSafely(true);
+ }
+ }
+ }
+
+ }, _s.flashLoadTimeout);
+
+ };
+
+ _handleFocus = function() {
+
+ function cleanup() {
+ _event.remove(_win, 'focus', _handleFocus);
+ _event.remove(_win, 'load', _handleFocus);
+ }
+
+ if (_isFocused || !_tryInitOnFocus) {
+ cleanup();
+ return true;
+ }
+
+ _okToDisable = true;
+ _isFocused = true;
+ _s._wD(_smc+'handleFocus()');
+
+ if (_isSafari && _tryInitOnFocus) {
+ _event.remove(_win, 'mousemove', _handleFocus);
+ }
+
+ // allow init to restart
+ _waitingForEI = false;
+
+ cleanup();
+ return true;
+
+ };
+
+ _showSupport = function() {
+
+ var item, tests = [];
+
+ if (_s.useHTML5Audio && _s.hasHTML5) {
+ for (item in _s.audioFormats) {
+ if (_s.audioFormats.hasOwnProperty(item)) {
+ tests.push(item + ': ' + _s.html5[item] + (!_s.html5[item] && _hasFlash && _s.flash[item] ? ' (using flash)' : (_s.preferFlash && _s.flash[item] && _hasFlash ? ' (preferring flash)': (!_s.html5[item] ? ' (' + (_s.audioFormats[item].required ? 'required, ':'') + 'and no flash support)' : ''))));
+ }
+ }
+ _s._wD('-- SoundManager 2: HTML5 support tests ('+_s.html5Test+'): '+tests.join(', ')+' --',1);
+ }
+
+ };
+
+ _initComplete = function(bNoDisable) {
+
+ if (_didInit) {
+ return false;
+ }
+
+ if (_s.html5Only) {
+ // all good.
+ _s._wD('-- SoundManager 2: loaded --');
+ _didInit = true;
+ _initUserOnload();
+ _debugTS('onload', true);
+ return true;
+ }
+
+ var wasTimeout = (_s.useFlashBlock && _s.flashLoadTimeout && !_s.getMoviePercent()),
+ error;
+
+ if (!wasTimeout) {
+ _didInit = true;
+ if (_disabled) {
+ error = {type: (!_hasFlash && _needsFlash ? 'NO_FLASH' : 'INIT_TIMEOUT')};
+ }
+ }
+
+ _s._wD('-- SoundManager 2 ' + (_disabled?'failed to load':'loaded') + ' (' + (_disabled?'security/load error':'OK') + ') --', 1);
+
+ if (_disabled || bNoDisable) {
+ if (_s.useFlashBlock && _s.oMC) {
+ _s.oMC.className = _getSWFCSS() + ' ' + (_s.getMoviePercent() === null?_swfCSS.swfTimedout:_swfCSS.swfError);
+ }
+ _processOnEvents({type:'ontimeout', error:error});
+ _debugTS('onload', false);
+ _catchError(error);
+ return false;
+ } else {
+ _debugTS('onload', true);
+ }
+
+ if (_s.waitForWindowLoad && !_windowLoaded) {
+ _wDS('waitOnload');
+ _event.add(_win, 'load', _initUserOnload);
+ return false;
+ } else {
+ // <d>
+ if (_s.waitForWindowLoad && _windowLoaded) {
+ _wDS('docLoaded');
+ }
+ // </d>
+ _initUserOnload();
+ }
+
+ return true;
+
+ };
+
+ _init = function() {
+
+ _wDS('init');
+
+ // called after onload()
+
+ if (_didInit) {
+ _wDS('didInit');
+ return false;
+ }
+
+ function _cleanup() {
+ _event.remove(_win, 'load', _s.beginDelayedInit);
+ }
+
+ if (_s.html5Only) {
+ if (!_didInit) {
+ // we don't need no steenking flash!
+ _cleanup();
+ _s.enabled = true;
+ _initComplete();
+ }
+ return true;
+ }
+
+ // flash path
+ _initMovie();
+
+ try {
+
+ _wDS('flashJS');
+
+ // attempt to talk to Flash
+ _flash._externalInterfaceTest(false);
+
+ // apply user-specified polling interval, OR, if "high performance" set, faster vs. default polling
+ // (determines frequency of whileloading/whileplaying callbacks, effectively driving UI framerates)
+ _setPolling(true, (_s.flashPollingInterval || (_s.useHighPerformance ? 10 : 50)));
+
+ if (!_s.debugMode) {
+ // stop the SWF from making debug output calls to JS
+ _flash._disableDebug();
+ }
+
+ _s.enabled = true;
+ _debugTS('jstoflash', true);
+
+ if (!_s.html5Only) {
+ // prevent browser from showing cached page state (or rather, restoring "suspended" page state) via back button, because flash may be dead
+ // http://www.webkit.org/blog/516/webkit-page-cache-ii-the-unload-event/
+ _event.add(_win, 'unload', _doNothing);
+ }
+
+ } catch(e) {
+
+ _s._wD('js/flash exception: ' + e.toString());
+ _debugTS('jstoflash', false);
+ _catchError({type:'JS_TO_FLASH_EXCEPTION', fatal:true});
+ // don't disable, for reboot()
+ _failSafely(true);
+ _initComplete();
+
+ return false;
+
+ }
+
+ _initComplete();
+
+ // disconnect events
+ _cleanup();
+
+ return true;
+
+ };
+
+ _domContentLoaded = function() {
+
+ if (_didDCLoaded) {
+ return false;
+ }
+
+ _didDCLoaded = true;
+ _initDebug();
+
+ /**
+ * Temporary feature: allow force of HTML5 via URL params: sm2-usehtml5audio=0 or 1
+ * Ditto for sm2-preferFlash, too.
+ */
+ // <d>
+ (function(){
+
+ var a = 'sm2-usehtml5audio=', l = _wl.toLowerCase(), b = null,
+ a2 = 'sm2-preferflash=', b2 = null, hasCon = (typeof console !== 'undefined' && typeof console.log !== 'undefined');
+
+ if (l.indexOf(a) !== -1) {
+ b = (l.charAt(l.indexOf(a)+a.length) === '1');
+ if (hasCon) {
+ console.log((b?'Enabling ':'Disabling ')+'useHTML5Audio via URL parameter');
+ }
+ _s.useHTML5Audio = b;
+ }
+
+ if (l.indexOf(a2) !== -1) {
+ b2 = (l.charAt(l.indexOf(a2)+a2.length) === '1');
+ if (hasCon) {
+ console.log((b2?'Enabling ':'Disabling ')+'preferFlash via URL parameter');
+ }
+ _s.preferFlash = b2;
+ }
+
+ }());
+ // </d>
+
+ if (!_hasFlash && _s.hasHTML5) {
+ _s._wD('SoundManager: No Flash detected'+(!_s.useHTML5Audio?', enabling HTML5.':'. Trying HTML5-only mode.'));
+ _s.useHTML5Audio = true;
+ // make sure we aren't preferring flash, either
+ // TODO: preferFlash should not matter if flash is not installed. Currently, stuff breaks without the below tweak.
+ _s.preferFlash = false;
+ }
+
+ _testHTML5();
+ _s.html5.usingFlash = _featureCheck();
+ _needsFlash = _s.html5.usingFlash;
+ _showSupport();
+
+ if (!_hasFlash && _needsFlash) {
+ _s._wD('SoundManager: Fatal error: Flash is needed to play some required formats, but is not available.');
+ // TODO: Fatal here vs. timeout approach, etc.
+ // hack: fail sooner.
+ _s.flashLoadTimeout = 1;
+ }
+
+ if (_doc.removeEventListener) {
+ _doc.removeEventListener('DOMContentLoaded', _domContentLoaded, false);
+ }
+
+ _initMovie();
+ return true;
+
+ };
+
+ _domContentLoadedIE = function() {
+
+ if (_doc.readyState === 'complete') {
+ _domContentLoaded();
+ _doc.detachEvent('onreadystatechange', _domContentLoadedIE);
+ }
+
+ return true;
+
+ };
+
+ _winOnLoad = function() {
+ // catch edge case of _initComplete() firing after window.load()
+ _windowLoaded = true;
+ _event.remove(_win, 'load', _winOnLoad);
+ };
+
+ // sniff up-front
+ _detectFlash();
+
+ // focus and window load, init (primarily flash-driven)
+ _event.add(_win, 'focus', _handleFocus);
+ _event.add(_win, 'load', _handleFocus);
+ _event.add(_win, 'load', _delayWaitForEI);
+ _event.add(_win, 'load', _winOnLoad);
+
+
+ if (_isSafari && _tryInitOnFocus) {
+ // massive Safari 3.1 focus detection hack
+ _event.add(_win, 'mousemove', _handleFocus);
+ }
+
+ if (_doc.addEventListener) {
+
+ _doc.addEventListener('DOMContentLoaded', _domContentLoaded, false);
+
+ } else if (_doc.attachEvent) {
+
+ _doc.attachEvent('onreadystatechange', _domContentLoadedIE);
+
+ } else {
+
+ // no add/attachevent support - safe to assume no JS -> Flash either
+ _debugTS('onload', false);
+ _catchError({type:'NO_DOM2_EVENTS', fatal:true});
+
+ }
+
+ if (_doc.readyState === 'complete') {
+ // DOMReady has already happened.
+ setTimeout(_domContentLoaded,100);
+ }
+
+} // SoundManager()
+
+// SM2_DEFER details: http://www.schillmania.com/projects/soundmanager2/doc/getstarted/#lazy-loading
+
+if (typeof SM2_DEFER === 'undefined' || !SM2_DEFER) {
+ soundManager = new SoundManager();
+}
+
+/**
+ * SoundManager public interfaces
+ * ------------------------------
+ */
+
+window.SoundManager = SoundManager; // constructor
+window.soundManager = soundManager; // public API, flash callbacks etc.
+
+}(window)); \ No newline at end of file
diff --git a/Processing-js/libs/inc/SoundManager2/swf/soundmanager2.swf b/Processing-js/libs/inc/SoundManager2/swf/soundmanager2.swf
new file mode 100755
index 0000000..14850f2
--- /dev/null
+++ b/Processing-js/libs/inc/SoundManager2/swf/soundmanager2.swf
Binary files differ
diff --git a/Processing-js/libs/inc/SoundManager2/swf/soundmanager2_debug.swf b/Processing-js/libs/inc/SoundManager2/swf/soundmanager2_debug.swf
new file mode 100755
index 0000000..aa4750a
--- /dev/null
+++ b/Processing-js/libs/inc/SoundManager2/swf/soundmanager2_debug.swf
Binary files differ
diff --git a/Processing-js/libs/inc/SoundManager2/swf/soundmanager2_flash9.swf b/Processing-js/libs/inc/SoundManager2/swf/soundmanager2_flash9.swf
new file mode 100755
index 0000000..2705986
--- /dev/null
+++ b/Processing-js/libs/inc/SoundManager2/swf/soundmanager2_flash9.swf
Binary files differ
diff --git a/Processing-js/libs/inc/SoundManager2/swf/soundmanager2_flash9_debug.swf b/Processing-js/libs/inc/SoundManager2/swf/soundmanager2_flash9_debug.swf
new file mode 100755
index 0000000..243d649
--- /dev/null
+++ b/Processing-js/libs/inc/SoundManager2/swf/soundmanager2_flash9_debug.swf
Binary files differ
diff --git a/Processing-js/libs/inc/SoundManager2/swf/soundmanager2_flash_xdomain.zip b/Processing-js/libs/inc/SoundManager2/swf/soundmanager2_flash_xdomain.zip
new file mode 100755
index 0000000..29737aa
--- /dev/null
+++ b/Processing-js/libs/inc/SoundManager2/swf/soundmanager2_flash_xdomain.zip
Binary files differ
diff --git a/Processing-js/libs/inc/WebMIDIAPI.js b/Processing-js/libs/inc/WebMIDIAPI.js
new file mode 100644
index 0000000..2b3d6f2
--- /dev/null
+++ b/Processing-js/libs/inc/WebMIDIAPI.js
@@ -0,0 +1,421 @@
+/* Copyright 2013 Chris Wilson
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ */
+
+// Initialize the MIDI library.
+(function (global) {
+ 'use strict';
+ var midiIO, _requestMIDIAccess, MIDIAccess, _onReady, MIDIPort, MIDIInput, MIDIOutput, _midiProc;
+
+ function Promise() {
+
+ }
+
+ Promise.prototype.then = function(accept, reject) {
+ this.accept = accept;
+ this.reject = reject;
+ }
+
+ Promise.prototype.succeed = function(access) {
+ if (this.accept)
+ this.accept(access);
+ }
+
+ Promise.prototype.fail = function(error) {
+ if (this.reject)
+ this.reject(error);
+ }
+
+ function _JazzInstance() {
+ this.inputInUse = false;
+ this.outputInUse = false;
+
+ // load the Jazz plugin
+ var o1 = document.createElement("object");
+ o1.id = "_Jazz" + Math.random() + "ie";
+ o1.classid = "CLSID:1ACE1618-1C7D-4561-AEE1-34842AA85E90";
+
+ this.activeX = o1;
+
+ var o2 = document.createElement("object");
+ o2.id = "_Jazz" + Math.random();
+ o2.type="audio/x-jazz";
+ o1.appendChild(o2);
+
+ this.objRef = o2;
+
+ var e = document.createElement("p");
+ e.appendChild(document.createTextNode("This page requires the "));
+
+ var a = document.createElement("a");
+ a.appendChild(document.createTextNode("Jazz plugin"));
+ a.href = "http://jazz-soft.net/";
+
+ e.appendChild(a);
+ e.appendChild(document.createTextNode("."));
+ o2.appendChild(e);
+
+ var insertionPoint = document.getElementById("MIDIPlugin");
+ if (!insertionPoint) {
+ // Create hidden element
+ var insertionPoint = document.createElement("div");
+ insertionPoint.id = "MIDIPlugin";
+ insertionPoint.style.position = "absolute";
+ insertionPoint.style.visibility = "hidden";
+ insertionPoint.style.left = "-9999px";
+ insertionPoint.style.top = "-9999px";
+ document.body.appendChild(insertionPoint);
+ }
+ insertionPoint.appendChild(o1);
+
+ if (this.objRef.isJazz)
+ this._Jazz = this.objRef;
+ else if (this.activeX.isJazz)
+ this._Jazz = this.activeX;
+ else
+ this._Jazz = null;
+ if (this._Jazz) {
+ this._Jazz._jazzTimeZero = this._Jazz.Time();
+ this._Jazz._perfTimeZero = window.performance.now();
+ }
+ }
+
+ _requestMIDIAccess = function _requestMIDIAccess() {
+ var access = new MIDIAccess();
+ return access._promise;
+ };
+
+ // API Methods
+
+ function MIDIAccess() {
+ this._jazzInstances = new Array();
+ this._jazzInstances.push( new _JazzInstance() );
+ this._promise = new Promise;
+
+ if (this._jazzInstances[0]._Jazz) {
+ this._Jazz = this._jazzInstances[0]._Jazz;
+ window.setTimeout( _onReady.bind(this), 3 );
+ } else {
+ window.setTimeout( _onNotReady.bind(this), 3 );
+ }
+ };
+
+ _onReady = function _onReady() {
+ if (this._promise)
+ this._promise.succeed(this);
+ };
+
+ function _onNotReady() {
+ if (this._promise)
+ this._promise.fail( { code: 1 } );
+ };
+
+ MIDIAccess.prototype.inputs = function( ) {
+ if (!this._Jazz)
+ return null;
+ var list=this._Jazz.MidiInList();
+ var inputs = new Array( list.length );
+
+ for ( var i=0; i<list.length; i++ ) {
+ inputs[i] = new MIDIInput( this, list[i], i );
+ }
+ return inputs;
+ }
+
+ MIDIAccess.prototype.outputs = function( ) {
+ if (!this._Jazz)
+ return null;
+ var list=this._Jazz.MidiOutList();
+ var outputs = new Array( list.length );
+
+ for ( var i=0; i<list.length; i++ ) {
+ outputs[i] = new MIDIOutput( this, list[i], i );
+ }
+ return outputs;
+ };
+
+ MIDIInput = function MIDIInput( midiAccess, name, index ) {
+ this._listeners = [];
+ this._midiAccess = midiAccess;
+ this._index = index;
+ this._inLongSysexMessage = false;
+ this._sysexBuffer = new Uint8Array();
+ this.id = "" + index + "." + name;
+ this.manufacturer = "";
+ this.name = name;
+ this.type = "input";
+ this.version = "";
+ this.onmidimessage = null;
+
+ var inputInstance = null;
+ for (var i=0; (i<midiAccess._jazzInstances.length)&&(!inputInstance); i++) {
+ if (!midiAccess._jazzInstances[i].inputInUse)
+ inputInstance=midiAccess._jazzInstances[i];
+ }
+ if (!inputInstance) {
+ inputInstance = new _JazzInstance();
+ midiAccess._jazzInstances.push( inputInstance );
+ }
+ inputInstance.inputInUse = true;
+
+ this._jazzInstance = inputInstance._Jazz;
+ this._input = this._jazzInstance.MidiInOpen( this._index, _midiProc.bind(this) );
+ };
+
+ // Introduced in DOM Level 2:
+ MIDIInput.prototype.addEventListener = function (type, listener, useCapture ) {
+ if (type !== "midimessage")
+ return;
+ for (var i=0; i<this._listeners.length; i++)
+ if (this._listeners[i] == listener)
+ return;
+ this._listeners.push( listener );
+ };
+
+ MIDIInput.prototype.removeEventListener = function (type, listener, useCapture ) {
+ if (type !== "midimessage")
+ return;
+ for (var i=0; i<this._listeners.length; i++)
+ if (this._listeners[i] == listener) {
+ this._listeners.splice( i, 1 ); //remove it
+ return;
+ }
+ };
+
+ MIDIInput.prototype.preventDefault = function() {
+ this._pvtDef = true;
+ };
+
+ MIDIInput.prototype.dispatchEvent = function (evt) {
+ this._pvtDef = false;
+
+ // dispatch to listeners
+ for (var i=0; i<this._listeners.length; i++)
+ if (this._listeners[i].handleEvent)
+ this._listeners[i].handleEvent.bind(this)( evt );
+ else
+ this._listeners[i].bind(this)( evt );
+
+ if (this.onmidimessage)
+ this.onmidimessage( evt );
+
+ return this._pvtDef;
+ };
+
+ MIDIInput.prototype.appendToSysexBuffer = function ( data ) {
+ var oldLength = this._sysexBuffer.length;
+ var tmpBuffer = new Uint8Array( oldLength + data.length );
+ tmpBuffer.set( this._sysexBuffer );
+ tmpBuffer.set( data, oldLength );
+ this._sysexBuffer = tmpBuffer;
+ };
+
+ MIDIInput.prototype.bufferLongSysex = function ( data, initialOffset ) {
+ var j = initialOffset;
+ while (j<data.length) {
+ if (data[j] == 0xF7) {
+ // end of sysex!
+ j++;
+ this.appendToSysexBuffer( data.slice(initialOffset, j) );
+ return j;
+ }
+ j++;
+ }
+ // didn't reach the end; just tack it on.
+ this.appendToSysexBuffer( data.slice(initialOffset, j) );
+ this._inLongSysexMessage = true;
+ return j;
+ };
+
+ _midiProc = function _midiProc( timestamp, data ) {
+ // Have to use createEvent/initEvent because IE10 fails on new CustomEvent. Thanks, IE!
+ var length = 0;
+ var i,j;
+ var isSysexMessage = false;
+
+ // Jazz sometimes passes us multiple messages at once, so we need to parse them out
+ // and pass them one at a time.
+
+ for (i=0; i<data.length; i+=length) {
+ if (this._inLongSysexMessage) {
+ i = this.bufferLongSysex(data,i);
+ if ( data[i-1] != 0xf7 ) {
+ // ran off the end without hitting the end of the sysex message
+ return;
+ }
+ isSysexMessage = true;
+ } else {
+ isSysexMessage = false;
+ switch (data[i] & 0xF0) {
+ case 0x80: // note off
+ case 0x90: // note on
+ case 0xA0: // polyphonic aftertouch
+ case 0xB0: // control change
+ case 0xE0: // channel mode
+ length = 3;
+ break;
+
+ case 0xC0: // program change
+ case 0xD0: // channel aftertouch
+ length = 2;
+ break;
+
+ case 0xF0:
+ switch (data[i]) {
+ case 0xf0: // variable-length sysex.
+ i = this.bufferLongSysex(data,i);
+ if ( data[i-1] != 0xf7 ) {
+ // ran off the end without hitting the end of the sysex message
+ return;
+ }
+ isSysexMessage = true;
+ break;
+
+ case 0xF1: // MTC quarter frame
+ case 0xF3: // song select
+ length = 2;
+ break;
+
+ case 0xF2: // song position pointer
+ length = 3;
+ break;
+
+ default:
+ length = 1;
+ break;
+ }
+ break;
+ }
+ }
+ var evt = document.createEvent( "Event" );
+ evt.initEvent( "midimessage", false, false );
+ evt.receivedTime = parseFloat( timestamp.toString()) + this._jazzInstance._perfTimeZero;
+ if (isSysexMessage || this._inLongSysexMessage) {
+ evt.data = new Uint8Array( this._sysexBuffer );
+ this._sysexBuffer = new Uint8Array(0);
+ this._inLongSysexMessage = false;
+ } else
+ evt.data = new Uint8Array(data.slice(i, length+i));
+ this.dispatchEvent( evt );
+ }
+ };
+
+ MIDIOutput = function MIDIOutput( midiAccess, name, index ) {
+ this._listeners = [];
+ this._midiAccess = midiAccess;
+ this._index = index;
+ this.id = "" + index + "." + name;
+ this.manufacturer = "";
+ this.name = name;
+ this.type = "output";
+ this.version = "";
+
+ var outputInstance = null;
+ for (var i=0; (i<midiAccess._jazzInstances.length)&&(!outputInstance); i++) {
+ if (!midiAccess._jazzInstances[i].outputInUse)
+ outputInstance=midiAccess._jazzInstances[i];
+ }
+ if (!outputInstance) {
+ outputInstance = new _JazzInstance();
+ midiAccess._jazzInstances.push( outputInstance );
+ }
+ outputInstance.outputInUse = true;
+
+ this._jazzInstance = outputInstance._Jazz;
+ this._jazzInstance.MidiOutOpen(this.name);
+ };
+
+ function _sendLater() {
+ this.jazz.MidiOutLong( this.data ); // handle send as sysex
+ }
+
+ MIDIOutput.prototype.send = function( data, timestamp ) {
+ var delayBeforeSend = 0;
+ if (data.length === 0)
+ return false;
+
+ if (timestamp)
+ delayBeforeSend = Math.floor( timestamp - window.performance.now() );
+
+ if (timestamp && (delayBeforeSend>1)) {
+ var sendObj = new Object();
+ sendObj.jazz = this._jazzInstance;
+ sendObj.data = data;
+
+ window.setTimeout( _sendLater.bind(sendObj), delayBeforeSend );
+ } else {
+ this._jazzInstance.MidiOutLong( data );
+ }
+ return true;
+ };
+
+ //init: create plugin
+ if (!window.navigator.requestMIDIAccess)
+ window.navigator.requestMIDIAccess = _requestMIDIAccess;
+
+}(window));
+
+// Polyfill window.performance.now() if necessary.
+(function (exports) {
+ var perf = {}, props;
+
+ function findAlt() {
+ var prefix = ['moz', 'webkit', 'o', 'ms'],
+ i = prefix.length,
+ //worst case, we use Date.now()
+ props = {
+ value: (function (start) {
+ return function () {
+ return Date.now() - start;
+ };
+ }(Date.now()))
+ };
+
+ //seach for vendor prefixed version
+ for (; i >= 0; i--) {
+ if ((prefix[i] + "Now") in exports.performance) {
+ props.value = function (method) {
+ return function () {
+ exports.performance[method]();
+ }
+ }(prefix[i] + "Now");
+ return props;
+ }
+ }
+
+ //otherwise, try to use connectionStart
+ if ("timing" in exports.performance && "connectStart" in exports.performance.timing) {
+ //this pretty much approximates performance.now() to the millisecond
+ props.value = (function (start) {
+ return function() {
+ Date.now() - start;
+ };
+ }(exports.performance.timing.connectStart));
+ }
+ return props;
+ }
+
+ //if already defined, bail
+ if (("performance" in exports) && ("now" in exports.performance))
+ return;
+ if (!("performance" in exports))
+ Object.defineProperty(exports, "performance", {
+ get: function () {
+ return perf;
+ }});
+ //otherwise, performance is there, but not "now()"
+
+ props = findAlt();
+ Object.defineProperty(exports.performance, "now", props);
+}(window)); \ No newline at end of file
diff --git a/Processing-js/libs/inc/base64binary.js b/Processing-js/libs/inc/base64binary.js
new file mode 100644
index 0000000..6e1e558
--- /dev/null
+++ b/Processing-js/libs/inc/base64binary.js
@@ -0,0 +1,80 @@
+/*
+Copyright (c) 2011, Daniel Guerrero
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+ * Neither the name of the Daniel Guerrero nor the
+ names of its contributors may be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL DANIEL GUERRERO BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+var Base64Binary = {
+ _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",
+
+ /* will return a Uint8Array type */
+ decodeArrayBuffer: function(input) {
+ var bytes = Math.ceil( (3*input.length) / 4.0);
+ var ab = new ArrayBuffer(bytes);
+ this.decode(input, ab);
+
+ return ab;
+ },
+
+ decode: function(input, arrayBuffer) {
+ //get last chars to see if are valid
+ var lkey1 = this._keyStr.indexOf(input.charAt(input.length-1));
+ var lkey2 = this._keyStr.indexOf(input.charAt(input.length-1));
+
+ var bytes = Math.ceil( (3*input.length) / 4.0);
+ if (lkey1 == 64) bytes--; //padding chars, so skip
+ if (lkey2 == 64) bytes--; //padding chars, so skip
+
+ var uarray;
+ var chr1, chr2, chr3;
+ var enc1, enc2, enc3, enc4;
+ var i = 0;
+ var j = 0;
+
+ if (arrayBuffer)
+ uarray = new Uint8Array(arrayBuffer);
+ else
+ uarray = new Uint8Array(bytes);
+
+ input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
+
+ for (i=0; i<bytes; i+=3) {
+ //get the 3 octects in 4 ascii chars
+ enc1 = this._keyStr.indexOf(input.charAt(j++));
+ enc2 = this._keyStr.indexOf(input.charAt(j++));
+ enc3 = this._keyStr.indexOf(input.charAt(j++));
+ enc4 = this._keyStr.indexOf(input.charAt(j++));
+
+ chr1 = (enc1 << 2) | (enc2 >> 4);
+ chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
+ chr3 = ((enc3 & 3) << 6) | enc4;
+
+ uarray[i] = chr1;
+ if (enc3 != 64) uarray[i+1] = chr2;
+ if (enc4 != 64) uarray[i+2] = chr3;
+ }
+
+ return uarray;
+ }
+}; \ No newline at end of file
diff --git a/Processing-js/libs/inc/jasmid/LICENSE b/Processing-js/libs/inc/jasmid/LICENSE
new file mode 100644
index 0000000..407a442
--- /dev/null
+++ b/Processing-js/libs/inc/jasmid/LICENSE
@@ -0,0 +1,24 @@
+Copyright (c) 2010, Matt Westcott & Ben Firshman
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * The names of its contributors may not be used to endorse or promote products
+ derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/Processing-js/libs/inc/jasmid/midifile.js b/Processing-js/libs/inc/jasmid/midifile.js
new file mode 100644
index 0000000..5e60e79
--- /dev/null
+++ b/Processing-js/libs/inc/jasmid/midifile.js
@@ -0,0 +1,238 @@
+/*
+class to parse the .mid file format
+(depends on stream.js)
+*/
+function MidiFile(data) {
+ function readChunk(stream) {
+ var id = stream.read(4);
+ var length = stream.readInt32();
+ return {
+ 'id': id,
+ 'length': length,
+ 'data': stream.read(length)
+ };
+ }
+
+ var lastEventTypeByte;
+
+ function readEvent(stream) {
+ var event = {};
+ event.deltaTime = stream.readVarInt();
+ var eventTypeByte = stream.readInt8();
+ if ((eventTypeByte & 0xf0) == 0xf0) {
+ /* system / meta event */
+ if (eventTypeByte == 0xff) {
+ /* meta event */
+ event.type = 'meta';
+ var subtypeByte = stream.readInt8();
+ var length = stream.readVarInt();
+ switch(subtypeByte) {
+ case 0x00:
+ event.subtype = 'sequenceNumber';
+ if (length != 2) throw "Expected length for sequenceNumber event is 2, got " + length;
+ event.number = stream.readInt16();
+ return event;
+ case 0x01:
+ event.subtype = 'text';
+ event.text = stream.read(length);
+ return event;
+ case 0x02:
+ event.subtype = 'copyrightNotice';
+ event.text = stream.read(length);
+ return event;
+ case 0x03:
+ event.subtype = 'trackName';
+ event.text = stream.read(length);
+ return event;
+ case 0x04:
+ event.subtype = 'instrumentName';
+ event.text = stream.read(length);
+ return event;
+ case 0x05:
+ event.subtype = 'lyrics';
+ event.text = stream.read(length);
+ return event;
+ case 0x06:
+ event.subtype = 'marker';
+ event.text = stream.read(length);
+ return event;
+ case 0x07:
+ event.subtype = 'cuePoint';
+ event.text = stream.read(length);
+ return event;
+ case 0x20:
+ event.subtype = 'midiChannelPrefix';
+ if (length != 1) throw "Expected length for midiChannelPrefix event is 1, got " + length;
+ event.channel = stream.readInt8();
+ return event;
+ case 0x2f:
+ event.subtype = 'endOfTrack';
+ if (length != 0) throw "Expected length for endOfTrack event is 0, got " + length;
+ return event;
+ case 0x51:
+ event.subtype = 'setTempo';
+ if (length != 3) throw "Expected length for setTempo event is 3, got " + length;
+ event.microsecondsPerBeat = (
+ (stream.readInt8() << 16)
+ + (stream.readInt8() << 8)
+ + stream.readInt8()
+ )
+ return event;
+ case 0x54:
+ event.subtype = 'smpteOffset';
+ if (length != 5) throw "Expected length for smpteOffset event is 5, got " + length;
+ var hourByte = stream.readInt8();
+ event.frameRate = {
+ 0x00: 24, 0x20: 25, 0x40: 29, 0x60: 30
+ }[hourByte & 0x60];
+ event.hour = hourByte & 0x1f;
+ event.min = stream.readInt8();
+ event.sec = stream.readInt8();
+ event.frame = stream.readInt8();
+ event.subframe = stream.readInt8();
+ return event;
+ case 0x58:
+ event.subtype = 'timeSignature';
+ if (length != 4) throw "Expected length for timeSignature event is 4, got " + length;
+ event.numerator = stream.readInt8();
+ event.denominator = Math.pow(2, stream.readInt8());
+ event.metronome = stream.readInt8();
+ event.thirtyseconds = stream.readInt8();
+ return event;
+ case 0x59:
+ event.subtype = 'keySignature';
+ if (length != 2) throw "Expected length for keySignature event is 2, got " + length;
+ event.key = stream.readInt8(true);
+ event.scale = stream.readInt8();
+ return event;
+ case 0x7f:
+ event.subtype = 'sequencerSpecific';
+ event.data = stream.read(length);
+ return event;
+ default:
+ // console.log("Unrecognised meta event subtype: " + subtypeByte);
+ event.subtype = 'unknown'
+ event.data = stream.read(length);
+ return event;
+ }
+ event.data = stream.read(length);
+ return event;
+ } else if (eventTypeByte == 0xf0) {
+ event.type = 'sysEx';
+ var length = stream.readVarInt();
+ event.data = stream.read(length);
+ return event;
+ } else if (eventTypeByte == 0xf7) {
+ event.type = 'dividedSysEx';
+ var length = stream.readVarInt();
+ event.data = stream.read(length);
+ return event;
+ } else {
+ throw "Unrecognised MIDI event type byte: " + eventTypeByte;
+ }
+ } else {
+ /* channel event */
+ var param1;
+ if ((eventTypeByte & 0x80) == 0) {
+ /* running status - reuse lastEventTypeByte as the event type.
+ eventTypeByte is actually the first parameter
+ */
+ param1 = eventTypeByte;
+ eventTypeByte = lastEventTypeByte;
+ } else {
+ param1 = stream.readInt8();
+ lastEventTypeByte = eventTypeByte;
+ }
+ var eventType = eventTypeByte >> 4;
+ event.channel = eventTypeByte & 0x0f;
+ event.type = 'channel';
+ switch (eventType) {
+ case 0x08:
+ event.subtype = 'noteOff';
+ event.noteNumber = param1;
+ event.velocity = stream.readInt8();
+ return event;
+ case 0x09:
+ event.noteNumber = param1;
+ event.velocity = stream.readInt8();
+ if (event.velocity == 0) {
+ event.subtype = 'noteOff';
+ } else {
+ event.subtype = 'noteOn';
+ }
+ return event;
+ case 0x0a:
+ event.subtype = 'noteAftertouch';
+ event.noteNumber = param1;
+ event.amount = stream.readInt8();
+ return event;
+ case 0x0b:
+ event.subtype = 'controller';
+ event.controllerType = param1;
+ event.value = stream.readInt8();
+ return event;
+ case 0x0c:
+ event.subtype = 'programChange';
+ event.programNumber = param1;
+ return event;
+ case 0x0d:
+ event.subtype = 'channelAftertouch';
+ event.amount = param1;
+ return event;
+ case 0x0e:
+ event.subtype = 'pitchBend';
+ event.value = param1 + (stream.readInt8() << 7);
+ return event;
+ default:
+ throw "Unrecognised MIDI event type: " + eventType
+ /*
+ console.log("Unrecognised MIDI event type: " + eventType);
+ stream.readInt8();
+ event.subtype = 'unknown';
+ return event;
+ */
+ }
+ }
+ }
+
+ stream = Stream(data);
+ var headerChunk = readChunk(stream);
+ if (headerChunk.id != 'MThd' || headerChunk.length != 6) {
+ throw "Bad .mid file - header not found";
+ }
+ var headerStream = Stream(headerChunk.data);
+ var formatType = headerStream.readInt16();
+ var trackCount = headerStream.readInt16();
+ var timeDivision = headerStream.readInt16();
+
+ if (timeDivision & 0x8000) {
+ throw "Expressing time division in SMTPE frames is not supported yet"
+ } else {
+ ticksPerBeat = timeDivision;
+ }
+
+ var header = {
+ 'formatType': formatType,
+ 'trackCount': trackCount,
+ 'ticksPerBeat': ticksPerBeat
+ }
+ var tracks = [];
+ for (var i = 0; i < header.trackCount; i++) {
+ tracks[i] = [];
+ var trackChunk = readChunk(stream);
+ if (trackChunk.id != 'MTrk') {
+ throw "Unexpected chunk - expected MTrk, got "+ trackChunk.id;
+ }
+ var trackStream = Stream(trackChunk.data);
+ while (!trackStream.eof()) {
+ var event = readEvent(trackStream);
+ tracks[i].push(event);
+ //console.log(event);
+ }
+ }
+
+ return {
+ 'header': header,
+ 'tracks': tracks
+ }
+} \ No newline at end of file
diff --git a/Processing-js/libs/inc/jasmid/replayer.js b/Processing-js/libs/inc/jasmid/replayer.js
new file mode 100644
index 0000000..347fa1d
--- /dev/null
+++ b/Processing-js/libs/inc/jasmid/replayer.js
@@ -0,0 +1,96 @@
+var clone = function (o) {
+ if (typeof o != 'object') return (o);
+ if (o == null) return (o);
+ var ret = (typeof o.length == 'number') ? [] : {};
+ for (var key in o) ret[key] = clone(o[key]);
+ return ret;
+};
+
+function Replayer(midiFile, timeWarp, eventProcessor) {
+ var trackStates = [];
+ var beatsPerMinute = 120;
+ var ticksPerBeat = midiFile.header.ticksPerBeat;
+
+ for (var i = 0; i < midiFile.tracks.length; i++) {
+ trackStates[i] = {
+ 'nextEventIndex': 0,
+ 'ticksToNextEvent': (
+ midiFile.tracks[i].length ?
+ midiFile.tracks[i][0].deltaTime :
+ null
+ )
+ };
+ }
+
+ var nextEventInfo;
+ var samplesToNextEvent = 0;
+
+ function getNextEvent() {
+ var ticksToNextEvent = null;
+ var nextEventTrack = null;
+ var nextEventIndex = null;
+
+ for (var i = 0; i < trackStates.length; i++) {
+ if (
+ trackStates[i].ticksToNextEvent != null
+ && (ticksToNextEvent == null || trackStates[i].ticksToNextEvent < ticksToNextEvent)
+ ) {
+ ticksToNextEvent = trackStates[i].ticksToNextEvent;
+ nextEventTrack = i;
+ nextEventIndex = trackStates[i].nextEventIndex;
+ }
+ }
+ if (nextEventTrack != null) {
+ /* consume event from that track */
+ var nextEvent = midiFile.tracks[nextEventTrack][nextEventIndex];
+ if (midiFile.tracks[nextEventTrack][nextEventIndex + 1]) {
+ trackStates[nextEventTrack].ticksToNextEvent += midiFile.tracks[nextEventTrack][nextEventIndex + 1].deltaTime;
+ } else {
+ trackStates[nextEventTrack].ticksToNextEvent = null;
+ }
+ trackStates[nextEventTrack].nextEventIndex += 1;
+ /* advance timings on all tracks by ticksToNextEvent */
+ for (var i = 0; i < trackStates.length; i++) {
+ if (trackStates[i].ticksToNextEvent != null) {
+ trackStates[i].ticksToNextEvent -= ticksToNextEvent
+ }
+ }
+ return {
+ "ticksToEvent": ticksToNextEvent,
+ "event": nextEvent,
+ "track": nextEventTrack
+ }
+ } else {
+ return null;
+ }
+ };
+ //
+ var midiEvent;
+ var temporal = [];
+ //
+ function processEvents() {
+ function processNext() {
+ if ( midiEvent.event.type == "meta" && midiEvent.event.subtype == "setTempo" ) {
+ // tempo change events can occur anywhere in the middle and affect events that follow
+ beatsPerMinute = 60000000 / midiEvent.event.microsecondsPerBeat;
+ }
+ if (midiEvent.ticksToEvent > 0) {
+ var beatsToGenerate = midiEvent.ticksToEvent / ticksPerBeat;
+ var secondsToGenerate = beatsToGenerate / (beatsPerMinute / 60);
+ }
+ var time = (secondsToGenerate * 1000 * timeWarp) || 0;
+ temporal.push([ midiEvent, time]);
+ midiEvent = getNextEvent();
+ };
+ //
+ if (midiEvent = getNextEvent()) {
+ while(midiEvent) processNext(true);
+ }
+ };
+ processEvents();
+ return {
+ "getData": function() {
+ return clone(temporal);
+ }
+ };
+};
diff --git a/Processing-js/libs/inc/jasmid/stream.js b/Processing-js/libs/inc/jasmid/stream.js
new file mode 100644
index 0000000..27c69ba
--- /dev/null
+++ b/Processing-js/libs/inc/jasmid/stream.js
@@ -0,0 +1,69 @@
+/* Wrapper for accessing strings through sequential reads */
+function Stream(str) {
+ var position = 0;
+
+ function read(length) {
+ var result = str.substr(position, length);
+ position += length;
+ return result;
+ }
+
+ /* read a big-endian 32-bit integer */
+ function readInt32() {
+ var result = (
+ (str.charCodeAt(position) << 24)
+ + (str.charCodeAt(position + 1) << 16)
+ + (str.charCodeAt(position + 2) << 8)
+ + str.charCodeAt(position + 3));
+ position += 4;
+ return result;
+ }
+
+ /* read a big-endian 16-bit integer */
+ function readInt16() {
+ var result = (
+ (str.charCodeAt(position) << 8)
+ + str.charCodeAt(position + 1));
+ position += 2;
+ return result;
+ }
+
+ /* read an 8-bit integer */
+ function readInt8(signed) {
+ var result = str.charCodeAt(position);
+ if (signed && result > 127) result -= 256;
+ position += 1;
+ return result;
+ }
+
+ function eof() {
+ return position >= str.length;
+ }
+
+ /* read a MIDI-style variable-length integer
+ (big-endian value in groups of 7 bits,
+ with top bit set to signify that another byte follows)
+ */
+ function readVarInt() {
+ var result = 0;
+ while (true) {
+ var b = readInt8();
+ if (b & 0x80) {
+ result += (b & 0x7f);
+ result <<= 7;
+ } else {
+ /* b is the last byte */
+ return result + b;
+ }
+ }
+ }
+
+ return {
+ 'eof': eof,
+ 'read': read,
+ 'readInt32': readInt32,
+ 'readInt16': readInt16,
+ 'readInt8': readInt8,
+ 'readVarInt': readVarInt
+ }
+} \ No newline at end of file