/* SoundManager 2: Javascript Sound for the Web -------------------------------------------- http://www.schillmania.com/projects/soundmanager2/ Copyright (c) 2007, Scott Schiller. All rights reserved. Code licensed under the BSD License: http://www.schillmania.com/projects/soundmanager2/license.txt V2.0b.20070415 */ function SoundManager(smURL,smID){var self=this;this.version='V2.0b.20070415';this.url=(smURL||'swf/soundmanager2.swf');this.debugMode=false;this.useConsole=true;this.consoleOnly=false;this.nullURL='data/null.mp3';this.defaultOptions={'autoLoad':false,'stream':true,'autoPlay':false,'onid3':null,'onload':null,'whileloading':null,'onplay':null,'whileplaying':null,'onstop':null,'onfinish':null,'onbeforefinish':null,'onbeforefinishtime':5000,'onbeforefinishcomplete':null,'onjustbeforefinish':null,'onjustbeforefinishtime':200,'multiShot':true,'pan':0,'volume':100} this.allowPolling=true;this.enabled=false;this.o=null;this.id=(smID||'sm2movie');this.oMC=null;this.sounds=[];this.soundIDs=[];this.isIE=(navigator.userAgent.match(/MSIE/));this.isSafari=(navigator.userAgent.match(/safari/i));this.debugID='soundmanager-debug';this._debugOpen=true;this._didAppend=false;this._appendSuccess=false;this._didInit=false;this._disabled=false;this._hasConsole=(typeof console!='undefined'&&typeof console.log!='undefined');this._debugLevels=!self.isSafari?['debug','info','warn','error']:['log','log','log','log'];this.getMovie=function(smID){return self.isIE?window[smID]:(self.isSafari?document[smID+'-embed']:document.getElementById(smID+'-embed'));} this.loadFromXML=function(sXmlUrl){try{self.o._loadFromXML(sXmlUrl);}catch(e){self._failSafely();return true;}} this.createSound=function(oOptions){if(!self._didInit)throw new Error('soundManager.createSound(): Not loaded yet - wait for soundManager.onload() before calling sound-related methods');if(arguments.length==2){oOptions={'id':arguments[0],'url':arguments[1]}} var thisOptions=self._mergeObjects(oOptions);self._writeDebug('soundManager.createSound(): "'+thisOptions.id+'" ('+thisOptions.url+')',1);if(self._idCheck(thisOptions.id,true)){self._writeDebug('sound '+thisOptions.id+' already defined - exiting',2);return false;} self.sounds[thisOptions.id]=new SMSound(self,thisOptions);self.soundIDs[self.soundIDs.length]=thisOptions.id;try{self.o._createSound(thisOptions.id,thisOptions.onjustbeforefinishtime);}catch(e){self._failSafely();return true;} if(thisOptions.autoLoad||thisOptions.autoPlay)self.sounds[thisOptions.id].load(thisOptions);if(thisOptions.autoPlay)self.sounds[thisOptions.id].playState=1;} this.destroySound=function(sID){if(!self._idCheck(sID))return false;for(var i=self.soundIDs.length;i--;){if(self.soundIDs[i]==sID){delete self.soundIDs[i];continue;}} self.sounds[sID].unload();delete self.sounds[sID];} this.load=function(sID,oOptions){if(!self._idCheck(sID))return false;self.sounds[sID].load(oOptions);} this.unload=function(sID){if(!self._idCheck(sID))return false;self.sounds[sID].unload();} this.play=function(sID,oOptions){if(!self._idCheck(sID)){if(typeof oOptions!='Object')oOptions={url:oOptions};if(oOptions&&oOptions.url){self._writeDebug('soundController.play(): attempting to create "'+sID+'"',1);oOptions.id=sID;self.createSound(oOptions);}else{return false;}} self.sounds[sID].play(oOptions);} this.start=this.play;this.setPosition=function(sID,nMsecOffset){if(!self._idCheck(sID))return false;self.sounds[sID].setPosition(nMsecOffset);} this.stop=function(sID){if(!self._idCheck(sID))return false;self._writeDebug('soundManager.stop('+sID+')',1);self.sounds[sID].stop();} this.stopAll=function(){self._writeDebug('soundManager.stopAll()',1);for(var oSound in self.sounds){if(self.sounds[oSound]instanceof SMSound)self.sounds[oSound].stop();}} this.pause=function(sID){if(!self._idCheck(sID))return false;self.sounds[sID].pause();} this.resume=function(sID){if(!self._idCheck(sID))return false;self.sounds[sID].resume();} this.togglePause=function(sID){if(!self._idCheck(sID))return false;self.sounds[sID].togglePause();} this.setPan=function(sID,nPan){if(!self._idCheck(sID))return false;self.sounds[sID].setPan(nPan);} this.setVolume=function(sID,nVol){if(!self._idCheck(sID))return false;self.sounds[sID].setVolume(nVol);} this.setPolling=function(bPolling){if(!self.o||!self.allowPolling)return false;self._writeDebug('soundManager.setPolling('+bPolling+')');self.o._setPolling(bPolling);} this.disable=function(){if(self._disabled)return false;self._disabled=true;self._writeDebug('soundManager.disable(): Disabling all functions - future calls will return false.',1);for(var i=self.soundIDs.length;i--;){self._disableObject(self.sounds[self.soundIDs[i]]);} self.initComplete();self._disableObject(self);} this.getSoundById=function(sID,suppressDebug){if(!sID)throw new Error('SoundManager.getSoundById(): sID is null/undefined');var result=self.sounds[sID];if(!result&&!suppressDebug){self._writeDebug('"'+sID+'" is an invalid sound ID.',2);} return result;} this.onload=function(){soundManager._writeDebug('Warning: soundManager.onload() is undefined.',2);} this.onerror=function(){} this._idCheck=this.getSoundById;this._disableObject=function(o){for(var oProp in o){if(typeof o[oProp]=='function'&&typeof o[oProp]._protected=='undefined')o[oProp]=function(){return false;}} oProp=null;} this._failSafely=function(){var flashCPLink='http://www.macromedia.com/support/documentation/en/flashplayer/help/settings_manager04.html';var fpgssTitle='You may need to whitelist this location/domain eg. file:///C:/ or C:/ or mysite.com, or set ALWAYS ALLOW under the Flash Player Global Security Settings page. Note that this seems to apply only to file system viewing.';var flashCPL='view/edit';var FPGSS='FPGSS';if(!self._disabled){self._writeDebug('soundManager: JS->Flash communication failed. Possible causes: flash/browser security restrictions ('+flashCPL+'), insufficient browser/plugin support, or .swf not found',2);self._writeDebug('Verify that the movie path of '+self.url+' is correct (test link)',1);if(self._didAppend){if(!document.domain){self._writeDebug('Loading from local file system? (document.domain appears to be null, this URL path may need to be added to \'trusted locations\' in '+FPGSS+')',1);self._writeDebug('Possible security/domain restrictions ('+flashCPL+'), should work when served by http on same domain',1);}} self.disable();}} this._createMovie=function(smID,smURL){if(self._didAppend&&self._appendSuccess)return false;if(window.location.href.indexOf('debug=1')+1)self.debugMode=true;self._didAppend=true;var html=['',''];var toggleElement='