/***************************************
musicObject version 2.6.9
written by Chris van Rensburg

© Copyright 1996-1998 Headspace, Inc.
All  Rights Reserved
***************************************/

/*** customizable properties ***/

mo_enabled = true;

mo_requiredMinVersion = '';
mo_silentIfInadequate = false;
mo_showCompatibilityPrompt = true;
mo_ignoreJavaDisabled = false;

mo_debugToJavaConsole = true;
mo_debugToAlert = false;
mo_debugToStatus = true;
mo_ignoreNotReady = true;

/*** global properties & functions ***/

mo_hasBeatnik = false;
mo_BeatnikType = '';
mo_BeatnikVersion = '';
mo_hasCallbackIssue = false;
mo_windowOnloadStr = '';
mo_onloadStored = false;
mo_globalNoteNo = 0;
mo_minFadeInterval = 100;
mo_storedHandlers = 0;
mo_instances = new Array ();

function mo_debug (errorMessage,errorURL,errorLineNo) {
	var errorStr = '\n**** JAVASCRIPT ERROR ****\n    TYPE: ' + errorMessage + '\n    LINE# ' + errorLineNo + '\n    FILE: ' + errorURL + '\n';
	if (mo_debugToJavaConsole && typeof (java) != 'undefined') java.lang.System.out.println (errorStr);
	if (mo_debugToAlert) alert (errorStr);
	if (mo_debugToStatus) window.defaultStatus = errorStr;
	return true;
}

function mo_enableDebug (windowHandle) {
	windowHandle.onerror = mo_debug;
	for (var frameNo = 0; frameNo < windowHandle.frames.length; frameNo++)
		mo_enableDebug (windowHandle.frames [frameNo])
	;
}

mo_enableDebug (top);

function mo_addEventHandler (windowHandle,objectID,eventType,handler) {
	var storedHandlerStr = '';
	if (typeof (objectID [eventType]) == 'function') {
		if (typeof (windowHandle.mo_storedHandlers) == 'undefined') windowHandle.mo_storedHandlers = 0;
		windowHandle.mo_storedHandlers++;
		var storedHandler = 'mo_storedEventHandler' + mo_storedHandlers;
		windowHandle [storedHandler] = objectID [eventType];
		storedHandlerStr = '; return ' + storedHandler + ' (event)';
	}
	objectID [eventType] = windowHandle.eval ('new Function (\'event\',\'' + handler + storedHandlerStr + '\')');
}

function mo_retrieveVersion (appName) {
	var
		versionStr = '',
		numerals = '0123456789',
		charNo = appName.length - 1,
		currentChar,
		inVersion = false,
		parensLevel = 0
	;
	while (charNo >= 0) {
		currentChar = appName.charAt (charNo);
		if (currentChar == ')') {
			parensLevel++;
		} else if (currentChar == '(') {
			parensLevel--;
		} else if (parensLevel == 0) {
			if (inVersion || numerals.indexOf (currentChar) != -1) {
				inVersion = true;
				if (currentChar == ' ') charNo = 0;
					else if (currentChar == '.' || numerals.indexOf (currentChar) != -1) versionStr = currentChar + versionStr;
			}
		}
		charNo--;
	}
	return versionStr;
}

function mo_meetsMinVersion (versionToTest,minRequiredVersion) {
	var
		versionA = mo_retrieveVersion (versionToTest),
		versionB = mo_retrieveVersion (minRequiredVersion)
	;
	if (versionA.length < versionB.length) versionA += '.0.0.0.0.0.0.0.0.0.0.0.0'.substring (0,versionB.length - versionA.length);
	return versionA >= versionB;
}

function mo_hasMinVersion (minRequiredVersion) {
	return mo_meetsMinVersion (mo_BeatnikVersion,minRequiredVersion);
}

function mo_supportedBrowser (_name,_platform,_minVersion) {
	this.name = _name;
	this.platform = _platform;
	this.minVersion = _minVersion;
}

mo_supportedBrowsers = new Array (
	new mo_supportedBrowser ('Netscape','Win32','3.01'),
	new mo_supportedBrowser ('Netscape','MacPPC','3.01')
/*	new mo_supportedBrowser ('Microsoft Internet Explorer','Win32','4.0') */
);

function mo_stringHasAny (sourceStr) {
	for (var argNo = 1; argNo < mo_stringHasAny.arguments.length; argNo++) {
		if (sourceStr.indexOf (mo_stringHasAny.arguments [argNo]) != -1) return true;
	}
	return false;
}

with (navigator) {
	if (mo_stringHasAny (userAgent,'Win95','Windows 95','WinNT','Windows NT','Win98','Windows 98')) {
		mo_platform = 'Win32';
	} else if (userAgent.indexOf ('PPC') != -1) {
		mo_platform = 'MacPPC';
	}
	mo_browserVersion = mo_retrieveVersion (navigator.appVersion);
	mo_browserSupported = false;
	for (mo_browserNo in mo_supportedBrowsers) {
		mo_browser = mo_supportedBrowsers [mo_browserNo];
		if (mo_browser.name == appName && mo_browser.platform == mo_platform && mo_meetsMinVersion (mo_browserVersion,mo_browser.minVersion)) {
			mo_browserSupported = true;
			break;
		}
	}
	if (mo_browserSupported) {
		if (appName == 'Netscape') {
			mo_BeatnikType = 'Plug-in';
			for (mo_pluginNo = 0; mo_pluginNo < plugins.length; mo_pluginNo++) {
				if (plugins [mo_pluginNo].name.indexOf ('Beatnik') != -1 && plugins [mo_pluginNo].name.indexOf ('Stub') == -1) {
					mo_BeatnikVersion = mo_retrieveVersion (plugins [mo_pluginNo].name);
					if (mo_BeatnikVersion == '' && mo_platform == 'Mac') mo_BeatnikVersion = '1.1.7';
					mo_hasBeatnik = true;
					break;
				}
			}
			mo_hasCallbackIssue = mo_browserVersion.indexOf ('4.') == 0 && mo_hasMinVersion ('1.3') && navigator.javaEnabled ();
		} else if (appName == 'Microsoft Internet Explorer') {
			mo_BeatnikType = 'ActiveX';
			document.writeln (
				'<OBJECT ID="mo_testInstance" CLASSID="CLSID:B384F118-18EE-11D1-95C8-00A024330339"' +
				((window.location.href.indexOf ('http://') != 0) ? ' CODEBASE=""' : '') +
				' WIDTH=1 HEIGHT=1>' +
				'<PARAM NAME="HIDDEN" VALUE="TRUE">' +
				'<PARAM NAME="AUTOSTART" VALUE="FALSE">' +
				'</OBJECT>'
			);
			mo_hasBeatnik = typeof (document.mo_testInstance.getVersion) != 'undefined';
			if (mo_hasBeatnik) mo_BeatnikVersion = mo_retrieveVersion (document.mo_testInstance.getVersion ());
		}
	}
}

mo_attrNames = new Array ('SRC','TYPE','WIDTH','HEIGHT','NAME','AUTOSTART','LOOP','VOLUME','ALIGN','HSPACE','VSPACE','BGCOLOR','PLUGINSPAGE','HIDDEN','DISPLAY','MODE','GROOVOID','ONREADY','ONPLAY','ONPAUSE','ONSTOP','ONMETAEVENT','CALLBACKS','METAEVENTS');

mo_attribs = new Array ();

mo_noteNumbers = new Array ();

mo_noteNumbers ['c'] = 0;
mo_noteNumbers ['d'] = 2;
mo_noteNumbers ['e'] = 4;
mo_noteNumbers ['f'] = 5;
mo_noteNumbers ['g'] = 7;
mo_noteNumbers ['a'] = 9;
mo_noteNumbers ['b'] = 11;
	
mo_noteNames = new Array ('C','C#','D','D#','E','F','F#','G','G#','A','A#','B');

function mo_promptClose () {
	if (typeof (mo_promptWindow) == 'object') mo_promptWindow.close ();
	window.focus ();
}

function mo_promptUser (heading,message,okText,okAction,cancelText,cancelAction,showStatus) {
	mo_promptWindow = window.open ('','mo_promptWindow','toolbar=no,location=no,directories=no,status=' + ((showStatus || navigator.appName == 'Microsoft Internet Explorer') ? 'yes' : 'no') + ',menubar=no,scrollbars=no,resizable=yes,width=400,height=300');
	if (typeof (okAction) != 'string' || okAction == '') okAction = 'mo_promptClose ()';
	if (typeof (cancelAction) != 'string' || cancelAction == '') cancelAction = 'mo_promptClose ()';
	if (typeof (heading) != 'string') heading = '';
	with (mo_promptWindow.document) {
		open ('text/html');
		writeln (
			'<HTML><HEAD><TITLE>' + heading + '</TITLE></HEAD><BODY BGCOLOR=002244 TEXT=CCCCCC>' +
			'<FORM><TABLE WIDTH=100% HEIGHT=100% BORDER=1 CELLSPACING=10 CELLPADDING=6 BGCOLOR=000000>'
		);
		if (heading != '') writeln ('<TR><TD ALIGN=CENTER BGCOLOR=0088AA><FONT FACE="ARIAL,HELVETICA,VERDANA" COLOR=000000 SIZE=+2>' + heading + '</FONT></U><BR></TD></TR>');
		writeln (
			'<TR><TD VALIGN=TOP><FONT FACE="ARIAL,HELVETICA,VERDANA">' + message + '<P></FONT>' +
			'<TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=0><TR><TD ALIGN=LEFT>'
		);
		if (typeof (cancelText) == 'string' && cancelText != '')
			writeln ('<INPUT TYPE=button VALUE="' + cancelText + '" ONCLICK="with (window.opener) {' + cancelAction + '}">')
		;
		writeln ('</TD><TD ALIGN=RIGHT>');
		if (typeof (okText) == 'string' && okText != '')
			writeln ('<INPUT TYPE=button VALUE="' + okText + '" ONCLICK="with (window.opener) {' + okAction + '}">')
		;
		writeln ('</TD></TR></TABLE></TD></TR></TABLE></FORM></BODY></HTML>');
		close ();
		if (typeof (Event) != 'undefined') {
			mo_promptWindow.captureEvents (Event.KEYUP);
			mo_promptWindow.onKeyUp = new Function ('event','if (event.which == 13) {' + okAction + '} else if (event.which == 27) {' + cancelAction + '}; return false');
			mo_promptWindow.focus ();
		}
	}
}

function mo_installBeatnik () {
	if (mo_browserSupported) mo_promptWindow = window.open ('http://www.headspace.com/beatnik/player/install-wizard.html','mo_promptWindow','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=no,resizable=no,width=400,height=300');
}

function mo_indexOf (sourceStr,searchStr,startPos) {
	var result = sourceStr.indexOf (searchStr,startPos);
	if (result != -1) return result; else return sourceStr.length;
}

function mo_voice_free () {
	with (this) {
		if (musicObjectID.ready) {
			musicObjectID.playerID.noteOff (channelNo,noteNo,127);
			clearTimeout (noteOffTimeout);
			channelNo = 0;
		}
	}
}

function mo_voice (musicObjectID,channelNo,noteNo) {
	/*** Constructor Variables ***/
	this.musicObjectID = musicObjectID;
	this.channelNo = channelNo;
	this.noteNo = noteNo;

	/*** Instance State Variables ***/
	this.timeStamp = 0;
	this.noteOffTimeout = setTimeout ('',0);

	/*** Object's Exposed Methods ***/
	this.free = mo_voice_free;
}

mo_polyphony = 32;
mo_voices = new Array ();
mo_newVoice = new mo_voice (null,0,0);

for (mo_voiceNo = 0; mo_voiceNo < mo_polyphony; mo_voiceNo++)
	mo_voices [mo_voiceNo] = new mo_voice (null,0,0)
;

function mo_isPlayerCompatible (minVersion,silentIfInadequate,showCompatibilityPrompt) {
	if (mo_browserSupported) {
		if (typeof (silentIfInadequate) == 'boolean') mo_silentIfInadequate = silentIfInadequate;
		if (typeof (showCompatibilityPrompt) == 'boolean')
			mo_showCompatibilityPrompt = showCompatibilityPrompt;
			else showCompatibilityPrompt = mo_showCompatibilityPrompt;
		if (typeof (minVersion) == 'string')
			mo_requiredMinVersion = minVersion;
			else minVersion = mo_requiredMinVersion;
		if (mo_hasBeatnik) {
			if (mo_hasMinVersion (minVersion)) {
				return true;
			} else {
				if (showCompatibilityPrompt) mo_promptUser ('Please Upgrade Beatnik','This page has been optimized for the features of version <FONT COLOR=FFFFFF><B>' + minVersion + ' (or higher)</B></FONT> of the Beatnik Player. The currently installed version in your browser is ' + mo_BeatnikVersion + '.<P>If you choose to IGNORE this message, the page will continue to load normally, but may not function properly as designed by the author.','UPGRADE BEATNIK >>>','mo_installBeatnik ()','IGNORE','mo_promptClose ()');
				return false;
			}
		} else {
			if (showCompatibilityPrompt) mo_promptUser ('Beatnik Enhanced Content !!','This page has been optimized for the audio features of the <FONT COLOR=FFFFFF><B>Beatnik Player</B></FONT>. It appears you do not have the Beatnik Player installed.<P>If you choose to IGNORE this message, the page will continue to load normally, except there will be no Beatnik audio.','INSTALL BEATNIK >>>','mo_installBeatnik ()','IGNORE','mo_promptClose ()');
			return false;
		}
	} else return false;
}

function mo_requireJava () {
	mo_ignoreJavaDisabled = true;
	if (navigator.appName == 'Netscape' && !navigator.javaEnabled ()) {
		mo_promptUser ('Please Enable Java','This page makes use of the interactive audio features of the Beatnik Player. Java is currently not enabled in your browser. In order for the page to function correctly with Beatnik, <FONT COLOR=FFFFFF><B>you must have Java enabled</B></FONT>.<P>This page will continue to load normally, but some interactive audio functionality may be absent.','    OK    ','mo_promptClose ()');
	}
}

/*** musicObject class definition ***/

function mo_null () {
	if (this.ready)
		mo_debug ('Attempted to use a method not supported in this version of the Beatnik Player.',window.location.href,'unknown');
		else if (!mo_ignoreNotReady) mo_debug ('musicObject instance "' + this.objectName + '" is not yet ready for scripting control.',window.location.href,'unknown');
}

function mo_execCallback (callbackFunction) {
	if (typeof (callbackFunction) == 'string') eval (callbackFunction);
		else if (typeof (callbackFunction) == 'function') callbackFunction ();
}

function mo_magicEmbed (embedTag) {
	if (typeof (mo_playerCompatible) != 'boolean') mo_playerCompatible = mo_isPlayerCompatible (mo_requiredMinVersion,null,mo_showCompatibilityPrompt);
	var
		subChar,
		isMethod = typeof (this.playerID) != 'undefined'
	;
	if (!isMethod || typeof (this.playerName) != 'string') {
		for (var attrNo in mo_attrNames) mo_attribs [mo_attrNames [attrNo]] = null;
		with (this) {
			mo_attribs ['TYPE'] = '';

			if (isMethod) {
				this.playerName = objectName + 'Plugin';
				mo_attribs ['NAME'] = playerName;
				var
					prefix = objectName + '.execOn',
					suffix = ' ()'
				;
				mo_attribs ['ONREADY'] = prefix + 'Ready' + suffix;
				mo_attribs ['ONPLAY'] = prefix + 'Play' + suffix;
				mo_attribs ['ONPAUSE'] = prefix + 'Pause' + suffix;
				mo_attribs ['ONSTOP'] = prefix + 'Stop' + suffix;
				mo_attribs ['ONMETAEVENT'] = prefix + 'MetaEvent' + suffix;
				mo_attribs ['METAEVENTS'] = 'FALSE';
			}

			mo_attribs ['AUTOSTART'] = 'TRUE';
			mo_attribs ['WIDTH'] = '144';
			mo_attribs ['HEIGHT'] = '60';
			mo_attribs ['HSPACE'] = '0';
			mo_attribs ['VSPACE'] = '0';
			mo_attribs ['BGCOLOR'] = document.bgColor;
			mo_attribs ['VOLUME'] = '100';
			mo_attribs ['PLUGINSPAGE'] = 'http://www.headspace.com/to/?player';

			var
				tagEndFound = false,
				tagStartPos = 0,
				spacePos = mo_indexOf (embedTag,' ',tagStartPos),
				closePos = mo_indexOf (embedTag,'>',tagStartPos),
				tagNameEndPos = spacePos
			;
			if (closePos < tagNameEndPos) {
				tagNameEndPos = closePos;
				tagEndFound = true;
			}
			var tagName = embedTag.substring (tagStartPos + 1,tagNameEndPos).toUpperCase ();
			
			if (tagName == 'EMBED') {
				var attrStartPos = tagNameEndPos;
				while (!tagEndFound) {
					var attrFound = false;
					while (!tagEndFound && !attrFound) {
						subChar = embedTag.charAt (attrStartPos);
						if (subChar != ' ') {
							if (subChar == '>') tagEndFound = true;
								else attrFound = true;
						} else attrStartPos++;
					}
					if (attrFound) {
						var
							equalPos = mo_indexOf (embedTag,'=',attrStartPos),
							spacePos = mo_indexOf (embedTag,' ',attrStartPos),
							closePos = mo_indexOf (embedTag,'>',attrStartPos),
							attrNameEndPos = equalPos,
							hasValue = true
						;
						if (spacePos < attrNameEndPos) {
							attrNameEndPos = spacePos;
							hasValue = false;
						}
						if (closePos < attrNameEndPos) {
							attrNameEndPos = closePos;
							hasValue = false;
							tagEndFound = true;
						}
						var
							attrName = embedTag.substring (attrStartPos,attrNameEndPos).toUpperCase (),
							attrValuePos = attrNameEndPos + 1,
							attrValue = ''
						;
						if (hasValue) {
							var
								charCount = 0,
								attrValueEndFound = false,
								quoteChar = '',
								inEscape = false
							;
							while (!attrValueEndFound && !tagEndFound) {
								subChar = embedTag.charAt (attrValuePos);
								if (subChar == '"' || subChar == "'") {
									if (charCount == 0) {
										quoteChar = subChar;
										subChar = '';
									} else if (subChar == quoteChar && !inEscape) {
										attrValueEndFound = true;
										subChar = '';
									}
								} else if (subChar == ' ') {
									if (quoteChar == '') {
										attrValueEndFound = true;
										subChar = '';
									}
								} else if (subChar == '>') {
									if (quoteChar == '') {
										attrValueEndFound = true;
										tagEndFound = true;
										subChar = '';
									}
								} else if (subChar == '\\') {
									if (!inEscape) {
										inEscape = true;
										subChar = '';
									} else inEscape = false;
								}
								if (subChar != '\\') inEscape = false;
								attrValue += subChar;
								attrValuePos++;
								charCount++;
							}
						}
						attrStartPos = attrValuePos;
						mo_attribs [attrName] = attrValue;
						if (attrName == 'SRC' && mo_attribs ['TYPE'] == '') mo_attribs ['TYPE'] = 'audio/rmf';
					}
				}
			}

			if (mo_attribs ['SRC'] == '') mo_attribs ['SRC'] = null;
			if (mo_attribs ['TYPE'] == '') mo_attribs ['TYPE'] = 'audio/rmf';
			if (mo_attribs ['HIDDEN'] == '') mo_attribs ['HIDDEN'] = 'TRUE';
			if (isMethod) {
				if (mo_attribs ['NAME'] == '') mo_attribs ['NAME'] = playerName;
				playerName = mo_attribs ['NAME'];
			}

			if (isMethod) {
				if (mo_hasCallbackIssue) {
					mo_attribs ['CALLBACKS'] = 'FALSE';
					delayAutostart = mo_attribs ['AUTOSTART'].toUpperCase () == 'TRUE';
					mo_attribs ['AUTOSTART'] = 'FALSE';
					if (!mo_onloadStored) {
						mo_onloadStored = true;
						mo_addEventHandler (window,window,'onload','eval (mo_windowOnloadStr)');
					}
					mo_windowOnloadStr += objectName + '.enable ();';
				}
				this.volume = mo_attribs ['VOLUME'] - 0;
			}

			with (document) {
				if (mo_enabled && mo_browserSupported && mo_hasBeatnik && (mo_playerCompatible || !mo_silentIfInadequate)) {
					if (mo_BeatnikType == 'Plug-in') {
						var newEmbedTag = '<EMBED';
						for (var attrNo in mo_attrNames) {
							if (mo_attribs [mo_attrNames [attrNo]] != null) {
								newEmbedTag += ' ' + mo_attrNames [attrNo];
								if (mo_attribs [mo_attrNames [attrNo]] != '')
									newEmbedTag += '="' + mo_attribs [mo_attrNames [attrNo]] + '"'
								;
							}
						}
						newEmbedTag += '>';
						writeln (newEmbedTag);
						if (isMethod && !mo_ignoreJavaDisabled) mo_requireJava ();
					} else if (mo_BeatnikType == 'ActiveX') {
						if (isMethod) {
							var callbacks = new Array ('OnReady','OnPlay','OnPause','OnStop','OnMetaEvent');
							for (var callbackNo in callbacks) {
								var
									callbackHandler = mo_attribs [callbacks [callbackNo].toUpperCase ()],
									scriptEvent = callbacks [callbackNo] + ' ' + callbackHandler.substring (callbackHandler.indexOf ('('))
								;
								writeln ('<SCRIPT LANGUAGE=JavaScript FOR="' + playerName + '" EVENT="' + scriptEvent + '">' + callbackHandler + '</SCRIPT>');
							}
						}
						writeln ('<OBJECT ID="' + mo_attribs ['NAME'] + '" WIDTH=' + mo_attribs ['WIDTH'] + ' HEIGHT=' + mo_attribs ['HEIGHT'] + ' CLASSID="CLSID:B384F118-18EE-11D1-95C8-00A024330339" CODEBASE="http://download.headspace.com/beatnik-player/beatnik-player-131-win-ps.cab">');
						for (var attrNo in mo_attrNames) {
							if (mo_attribs [mo_attrNames [attrNo]] != null)
								writeln ('<PARAM NAME="' + mo_attrNames [attrNo] + '" VALUE="' + mo_attribs [mo_attrNames [attrNo]] + '">')
							;
						}
						writeln ('</OBJECT>');
					}
				} else {
					var tableDims = ' WIDTH=' + mo_attribs ['WIDTH'] + ' HEIGHT=' + mo_attribs ['HEIGHT'] + ' HSPACE=' + mo_attribs ['HSPACE'] + ' VSPACE=' + mo_attribs ['VSPACE'] + ((mo_attribs ['ALIGN'] != null) ? (' ALIGN=' + mo_attribs ['ALIGN']) : 'LEFT');
					if (mo_enabled && mo_browserSupported && (mo_attribs ['HIDDEN'] == null || mo_attribs ['HIDDEN'].toUpperCase () != 'TRUE')) {
						writeln ('<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR=FFFFFF' + tableDims + '><TR ALIGN=CENTER VALIGN=CENTER><TD><A HREF="javascript://" ONCLICK="mo_installBeatnik (); return false"><FONT FACE="ARIAL,HELVETICA,VERDANA" COLOR=000000>' + (mo_hasBeatnik ? 'Upgrade' : 'Get') + ' Beatnik!</FONT></A></TD></TR></TABLE>');
					} else {
						writeln ('<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0' + tableDims + '><TR><TD></TD></TR></TABLE>');
					}
				}
			}
		}
	}
}

function mo_stubEmbed (stubURL) {
	this.magicEmbed ('<EMBED' + ((typeof (stubURL) != 'string') ? '' : (' SRC="' + stubURL + '"')) + ' WIDTH=2 HEIGHT=2 HIDDEN AUTOSTART=TRUE LOOP=TRUE>');
}

function mo_preloadEmbed (fileURL,extraAttr) {
	if (typeof (extraAttr) != 'string') extraAttr = '';
	this.magicEmbed ('<EMBED SRC="' + fileURL + '" WIDTH=2 HEIGHT=2 HIDDEN AUTOSTART=FALSE LOOP=FALSE VOLUME=100 ' + extraAttr + '>');
}

function mo_play (p1,p2) {
	with (this) {
		endVolumeFade ();
		if (typeof (p2) == 'string') {
			if (p2.indexOf ('.') == -1 && p2.indexOf ('groovoid://') != 0) p2 = 'groovoid://' + p2;
			if (typeof (p1) == 'string') p1 = (p1 == 'auto') ? (p2.indexOf ('groovoid://Background-') == 0) : (p1 == 'yes');
			playerID.play (p1,p2);
		} else if (typeof (p1) == 'boolean' || typeof (p1) == 'number') {
			playerID.play (p1);
		} else if (typeof (p1) == 'string') {
			play ('auto',p1);
		} else {
			if (!playerID.isPlaying ()) playerID.play ();
		}
	}
}

function mo_stop (fade) {
	with (this) {
		if (typeof (fade) == 'undefined' || fade == null) {
			endVolumeFade ();
			playerID.stop ();
		} else {
			if (isPaused ()) {
				endVolumeFade ();
				playerID.stop ();
			} else {
				fadeVolume (null,0,fade,objectName + '.stop ()');
			}
		}
	}
}

function mo_stopAll () {
	with (this) {
		endVolumeFade ();
		playerID.stopAll ();
	}
}

function mo_pause (fade) {
	with (this) {
		endVolumeFade ();
		if (isPaused ()) {
			playerID.pause ();
			if (typeof (fade) == 'number') fadeVolume (0,100,fade);
		} else {
			if (typeof (fade) != 'number') playerID.pause ();
				else fadeVolume (null,0,fade,objectName + '.pause ()');
		}
	}
}

function mo_endVolumeFade () {
	with (this) {
		if (volFade_inProgress) {
			clearTimeout (volFade_timeout);
			volFade_inProgress = false;
			mo_execCallback (volFade_endCallback);
			if (volFade_restoreVolume) setVolume (volFade_fromVolume);
		}
	}
}

function mo_execVolumeFade () {
	with (this) {
		volFade_volume += volFade_step;
		setVolume (Math.round (volFade_volume));
		volFade_timeElapsed += volFade_interval;
		mo_execCallback (volFade_advanceCallback);
		if (volFade_timeElapsed >= volFade_time) {
			setVolume (volFade_toVolume);
			endVolumeFade ();
		} else {
			volFade_timeout = setTimeout (objectName + '.execVolumeFade ()',volFade_interval);
		}
	}
}

function mo_fadeVolume (fromVolume,toVolume,fadeTime,fadeEndCallback,fadeAdvanceCallback) {
	with (this) {
		if (typeof (fromVolume) != 'number') fromVolume = getVolume ();
		if (typeof (toVolume) != 'number') toVolume = 0;
		if (typeof (fadeTime) == 'boolean') fadeTime = fadeTime ? 1000:0;
		if (typeof (fadeTime) != 'number') fadeTime = 1000;
		if (
			volFade_inProgress &&
			toVolume == volFade_toVolume &&
			fadeTime == volFade_time
		) {
			volFade_endCallback = fadeEndCallback;
			volFade_advanceCallback = fadeAdvanceCallback;
		} else {
			volFade_restoreVolume = typeof (fadeEndCallback) == 'string' && (fadeEndCallback.indexOf ('.stop ()') != -1 || fadeEndCallback.indexOf ('.pause ()') != -1);
			endVolumeFade ();
			if (fadeTime != 0 && fadeTime < mo_minFadeInterval)
				fadeTime = Math.round (fadeTime / mo_minFadeInterval) * mo_minFadeInterval
			;
			if (fadeTime == 0 || toVolume == fromVolume) {
				if (!volFade_restoreVolume)	setVolume (toVolume);
				mo_execCallback (fadeEndCallback);
			} else {
				volFade_fromVolume = fromVolume;
				volFade_toVolume = toVolume;
				volFade_time = fadeTime;
				volFade_endCallback = fadeEndCallback;
				volFade_advanceCallback = fadeAdvanceCallback;
				volFade_timeElapsed = 0;
				volFade_volume = fromVolume;
				volFade_inProgress = true;
				volFade_interval = Math.max (Math.ceil (volFade_time / Math.abs (toVolume - fromVolume)),mo_minFadeInterval);
				volFade_step = (toVolume - fromVolume) / (volFade_time / volFade_interval);
				setVolume (fromVolume);
				volFade_timeout = setTimeout (objectName + '.execVolumeFade ()',volFade_interval);
			}
		}
	}
}

function mo_fadeTo (toValue,fadeTime,fadeEndCallback,fadeAdvanceCallback) {
	this.fadeVolume (null,toValue,fadeTime,fadeEndCallback,fadeAdvanceCallback);
}

function mo_enable () {
	with (this) {
		if (playerID == null) {
			if (typeof (window [playerName]) == 'object') {
				playerID = window [playerName];
			} else if (typeof (document [playerName]) == 'object') {
				playerID = document [playerName];
			} else {
				for (var formNo in document.forms) {
					formHandle = document.forms [formNo];
					if (typeof (formHandle [playerName]) == 'object') {
						playerID = formHandle [playerName];
						break;
					}
				}
			}
			if (playerID != null) {
				if (mo_hasCallbackIssue) playerID.enableCallbacks (true);
			} else {
				setTimeout (objectName + '.enable ()',500);
			}
		}
	}
}

function mo_execOnReady () {
	with (this) {
		if (ready) {
			mo_execCallback (onLoadFunction);
		} else {
			enable ();
			ready = playerID != null;
			if (ready) {
				defineMethodsMO ('getAutostart','getChannelMute','getChannelSolo','getController','getInfo','getLoop','getPanelDisplay','getPanelMode','getProgram','getReverbType','getTempo','getTranspose','getTrackMute','getTrackSolo','getVolume','isPaused','isPlaying','setAutostart','setChannelSolo','setController','setGlobalMute','setLoop','setPanelDisplay','setPanelMode','setReverbType','setTempo','setTrackMute','setTrackSolo','setTranspose','setVolume','fadeTo','noteOff','noteOn','pause','play','playGroovoid','setChannelMute','setProgram','stop','fadeVolume','notesOff');
				fadeFromTo = fadeVolume;
				playGroovoid = play;
				playNote = noteOn;
				if (mo_BeatnikVersion == '') mo_BeatnikVersion = mo_retrieveVersion (playerID.getVersion () + '');
				if (mo_hasMinVersion ('1.3'))
					defineMethodsMO ('doMenuItem','engageAudio','getFileSize','getPlayLength','getPosition','getTransposable','setEndTime','setPosition','setStartTime','setTransposable','stopAll')
				;
				if (typeof (onMetaEventFunction) == 'function') playerID.enableMetaEvents (true);
				if (delayAutostart) {
					setAutostart (true);
					play ();
				}
				mo_execCallback (onReadyFunction);
				mo_execCallback (onLoadFunction);
			} else {
				setTimeout (objectName + '.execOnReady ()',500);
			}
		}
	}
}

function mo_setMonophonic (channelNo,state) {
	with (this) {
		if (channelNo == 0)
			for (var channelCount = 0; channelCount < 16; channelCount++) monophonic [channelCount] = state;
			else monophonic [channelNo - 1] = state;
	}
}

function mo_getMonophonic (channelNo) {return this.monophonic [channelNo - 1]}

function mo_notesOff (_channelNo) {
	with (this) {
		for (var mo_voiceNo = 0; mo_voiceNo < mo_polyphony; mo_voiceNo++) {
			with (mo_voices [mo_voiceNo])
				if (musicObjectID == this && channelNo == _channelNo) free ()
			;
		}
	}
}

function mo_noteOn (_channelNo,p2,p3,p4,p5,p6) {
	var mo_voiceNo;
	with (this) {
		if (p4 != null && p5 != null) {
			if (monophonic [_channelNo - 1]) notesOff (_channelNo);
			if (typeof (p4) == 'string') p4 = getNoteNumber (p4);
			mo_globalNoteNo++;
			with (mo_newVoice) {
				musicObjectID = this;
				timeStamp = mo_globalNoteNo;
				channelNo = _channelNo;
				noteNo = p4;
			}
			var assignToVoiceNo = -1;
			for (mo_voiceNo = 0; mo_voiceNo < mo_polyphony; mo_voiceNo++) {
				with (mo_voices [mo_voiceNo]) {
					if (channelNo == 0) {
						assignToVoiceNo = mo_voiceNo;
						break;
					}
				}
			}
			if (assignToVoiceNo == -1) {
				assignToVoiceNo = 0;
				for (mo_voiceNo = 0; mo_voiceNo < mo_polyphony; mo_voiceNo++) {
					if (mo_voices [mo_voiceNo].timeStamp < mo_voices [assignToVoiceNo].timeStamp)
						assignToVoiceNo = mo_voiceNo
					;
				}
			}
			with (mo_voices [assignToVoiceNo]) {
				musicObjectID = mo_newVoice.musicObjectID;
				timeStamp = mo_newVoice.timeStamp;
				channelNo = mo_newVoice.channelNo;
				noteNo = mo_newVoice.noteNo;
				if (p2 >= 0 && p3 >= 0) playerID.noteOn (channelNo,p2,p3,p4,p5);
					else playerID.noteOn (channelNo,p4,p5);
				if (p6 != null) noteOffTimeout = setTimeout ('mo_voices [' + assignToVoiceNo + '].free ()',p6);
			}
		} else {
			noteOn (_channelNo,-1,-1,p2,p3,p4);
		}
	}
}

function mo_noteOff (_channelNo,_noteNo) {
	with (this) {
		if (_noteNo == null) {
			notesOff (_channelNo);
		} else {
			if (typeof (_noteNo) == 'string') _noteNo = getNoteNumber (_noteNo);
			for (var mo_voiceNo = 0; mo_voiceNo < mo_polyphony; mo_voiceNo++) {
				with (mo_voices [mo_voiceNo]) {
					if (musicObjectID == this && channelNo == _channelNo && noteNo == _noteNo) {
						free ();
						break;
					}
				}
			}
		}
	}
}

function mo_setProgram (channelNo,p2,p3) {
	with (this) {
		if (p3 != null) playerID.setProgram (channelNo,p2,p3);
			else playerID.setProgram (channelNo,p2);
	}
}

function mo_setChannelMute (channelNo,state) {
	with (this) {
		if (typeof (channelNo) == 'object') {
			for (var channelCount in channelNo)
				playerID.setChannelMute (channelNo [channelCount],state)
			;
		} else if (channelNo == 0) {
			for (var channelCount = 1; channelCount <= 16; channelCount++)
				playerID.setChannelMute (channelCount,state)
			;
		} else {
			playerID.setChannelMute (channelNo,state)
		}
	}
}

function mo_isReady () {return this.ready}

function mo_getNoteNumber (noteName) {
	var
		noteOffset = mo_noteNumbers [noteName.charAt (0).toLowerCase ()],
		result = 0,
		sharpFlatOffset = 0
	;
	if (noteOffset != null) {
		var sharpFlatPos = noteName.indexOf ('b',1);
		if (sharpFlatPos == -1) {
			sharpFlatPos = noteName.indexOf ('#',1);
			if (sharpFlatPos == -1) sharpFlatPos = 0; else sharpFlatOffset = 1;
		} else {
			sharpFlatOffset = -1;
		}
		var octaveNo = noteName.substring (sharpFlatPos + 1) - 0;
		result =  12 + octaveNo * 12 + noteOffset + sharpFlatOffset;
	}
	return Math.floor (result);
}

function mo_getNoteName (noteNumber) {
	return mo_noteNames [noteNumber % 12] + (Math.floor (noteNumber / 12) - 1) + '';
}

function mo_onLoad (onLoadFunction) {this.onLoadFunction = onLoadFunction}
function mo_onPause (onPauseFunction) {this.onPauseFunction = onPauseFunction}
function mo_onPlay (onPlayFunction) {this.onPlayFunction = onPlayFunction}
function mo_onReady (onReadyFunction) {this.onReadyFunction = onReadyFunction}
function mo_onStop (onStopFunction) {this.onStopFunction = onStopFunction}

function mo_onMetaEvent (_onMetaEventFunction) {
	with (this) {
		onMetaEventFunction = _onMetaEventFunction;
		if (ready) playerID.enableMetaEvents (typeof (onMetaEventFunction) == 'function');
	}
}

function mo_execOnPause () {
	with (this) {
		endVolumeFade ();
		mo_execCallback (this.onPauseFunction);
	}
}

function mo_execOnPlay () {
	with (this) {
		setVolume (volume);
		mo_execCallback (onPlayFunction);
	}
}

function mo_execOnStop () {
	with (this) {
		endVolumeFade ();
		mo_execCallback (onStopFunction);
	}
}

function mo_execOnMetaEvent (eventType,eventValue) {
	with (this)
		if (onMetaEventFunction != null) onMetaEventFunction (eventType,eventValue,this)
	;
}

function mo_setVolume (_volume) {
	with (this) {
		volume = _volume;
		playerID.setVolume (_volume);
	}
}

function mo_getPlatform () {return (navigator.userAgent)}
function mo_getVersion () {return mo_BeatnikVersion}
function mo_getVolume () {return this.volume}
function mo_isPaused () {return this.playerID.IsPaused ()}
function mo_isPlaying () {return this.playerID.IsPlaying ()}

/*** Functions mapped directly to the player ***/

mo_directMethods = new Array (
	'doMenuItem (menuItemName)',
	'engageAudio (audioState)',
	'getAutostart ()',
	'getChannelMute (channelNo)',
	'getChannelSolo (channelNo)',
	'getController (channelNo,controllerNo)',
	'getFileSize ()',
	'getInfo (infoField)',
	'getLoop ()',
	'getPanelDisplay ()',
	'getPanelMode ()',
	'getPlayLength ()',
	'getPosition ()',
	'getProgram (channelNo)',
	'getReverbType ()',
	'getTempo ()',
	'getTrackMute (trackNo)',
	'getTrackSolo (trackNo)',
	'getTranspose ()',
	'getTransposable (channelNo)',
	'setAutostart (state)',
	'setChannelSolo (channelNo,state)',
	'setController (channelNo,controllerNo,controllerValue)',
	'setEndTime (endTime)',
	'setGlobalMute (muteState)',
	'setLoop (state)',
	'setPanelDisplay (displayType)',
	'setPanelMode (panelMode)',
	'setPosition (position)',
	'setReverbType (reverbType)',
	'setStartTime (startTime)',
	'setTempo (tempo)',
	'setTrackMute (trackNo,state)',
	'setTrackSolo (trackNo,state)',
	'setTranspose (transpose)',
	'setTransposable (channelNo,state)'
);

for (var mo_methodNo in mo_directMethods) {
	mo_method = mo_directMethods [mo_methodNo];
	eval ('function mo_' + mo_method + ' {' + ((mo_method.indexOf ('get') == 0) ? 'return ' : '') + 'this.playerID.' + mo_method + '}');
}

function mo_defineMethodsNull () {
	for (var argNo = 0; argNo < mo_defineMethodsNull.arguments.length; argNo++)
		this [mo_defineMethodsNull.arguments [argNo]] = mo_null
	;
}

function mo_defineMethodsMO () {
	for (var argNo = 0; argNo < mo_defineMethodsMO.arguments.length; argNo++)
		this [mo_defineMethodsMO.arguments [argNo]] = window ['mo_' + mo_defineMethodsMO.arguments [argNo]]
	;
}

function musicObject (objectName,onReadyFunction) {
	this.objectName = objectName;

	/*** Instance State Variables ***/
	this.delayAutostart = false;
	this.volFade_timeout = setTimeout ('',0);
	this.volFade_step = 0;
	this.volFade_time = 0;
	this.volFade_timeElapsed = 0;
	this.volFade_interval = 0;
	this.volFade_fromVolume = 0;
	this.volFade_volume = 0;
	this.volFade_toVolume = 0;
	this.volFade_endCallback = null;
	this.volFade_inProgress = false;
	this.volFade_restoreVolume = false;
	this.monophonic = new Array (false,false,false,false,false,false,false,false,false,false,false,false,false,false,false);
	this.ready = false;
	this.playerID = null;
	this.onLoadFunction = null;
	this.onMetaEventFunction = null;
	this.onPauseFunction = null;
	this.onPlayFunction = null;
	this.onReadyFunction = onReadyFunction;
	this.onStopFunction = null;

	/*** Method Configuration Methods ***/
	this.defineMethodsNull = mo_defineMethodsNull;
	this.defineMethodsMO = mo_defineMethodsMO;

	/*** Initialisation ***/
	this.defineMethodsNull ('doMenuItem','engageAudio','fadeTo','fadeFromTo','fadeVolume','getAutostart','getChannelMute','getChannelSolo','getController','getFileSize','getInfo','getLoop','getPanelDisplay','getPanelMode','getPlayLength','getPosition','getProgram','getReverbType','getTempo','getTrackMute','getTrackSolo','getTranspose','getTransposable','getVolume','isPaused','isPlaying','noteOff','noteOn','notesOff','pause','play','playGroovoid','playNote','setAutostart','setChannelMute','setChannelSolo','setController','setEndTime','setGlobalMute','setLoop','setPanelDisplay','setPanelMode','setPosition','setProgram','setReverbType','setStartTime','setTempo','setTrackMute','setTrackSolo','setTranspose','setTransposable','setVolume','stop','stopAll');

	this.defineMethodsMO ('enable','endVolumeFade','execOnMetaEvent','execOnPause','execOnPlay','execOnReady','execOnStop','execVolumeFade','getMonophonic','getNoteName','getNoteNumber','getPlatform','getVersion','isReady','magicEmbed','onLoad','onMetaEvent','onPause','onPlay','onStop','preloadEmbed','onReady','setMonophonic','stubEmbed');

	window [this.objectName] = this;
	mo_instances [mo_instances.length] = this;
	return this;
}

/************************************
Beatnik ActionSet - version 1.1.0
written by C. van Rensburg

© Copyright 1997,1998 Headspace, Inc.
All  Rights Reserved
*************************************/

mo_ignoreJavaDisabled = true;
mo_debugToJavaConsole = false;
mo_debugToStatus = false;
B_enabled = mo_isPlayerCompatible ('1.3.2',true,false);

b_actionNames = new Array ();

b_actionNames ['Standard'] = new Array ('pauseGroovoid','playGroovoid','stopGroovoid','pauseMusicFile','playMusicFile','preloadMusicFile','stopMusicFile','playMusicalNote','stopMusicalNote','adjustChannelPan','adjustChannelVolume','setChannelInstrument','setChannelMonophonic','setChannelMute','setChannelPan','setChannelSolo','setChannelVolume','setGlobalMute','setReverbType','adjustPosition','adjustTempo','adjustTransposition','adjustVolume','releasePlayer','setPosition','setTempo','setTransposition','setVolume','showCopyrightInfo','setTrackMute','setTrackSolo');

/*** Implementation section ***/

var
	B_targetID = null,
	B_bankNo,
	B_programNo
;

function B_stripComment (paramToStrip) {
	if (typeof (paramToStrip) == 'number') {
		return paramToStrip;
	} else {
		if (paramToStrip == '' || '0123456789-'.indexOf (paramToStrip.charAt (0)) == -1) {
			return paramToStrip;
		} else {
			var spacePos = paramToStrip.indexOf (' ');
			return ((spacePos == -1) ? paramToStrip : paramToStrip.substring (0,spacePos)) - 0;
		}
	}
}

function B_mapTo127 (value) {return Math.round (value / 100 * 127)}

function B_findTarget (_target,_fileURL) {
	if (B_enabled) {
		var B_playerNo;
		if (_target != '' && (_target.charAt (0) != '[' || _target == '[reserved player]')) {
			if (B_targetID == null || B_targetID.targetName != _target) {
				B_targetID = null;
				for (B_playerNo = 0; B_playerNo < mo_instances.length; B_playerNo++) {
					if (mo_instances [B_playerNo].targetName == _target) {
						B_targetID = mo_instances [B_playerNo];
						break;
					}
				}
			}
		} else {
			B_targetID = null;
		}
		if (B_targetID == null) {
			if (typeof (_fileURL) != 'string') _fileURL = _target;
			for (B_playerNo = 0; B_playerNo < mo_instances.length; B_playerNo++) {
				if (mo_instances [B_playerNo].fileURL == _fileURL) {
					B_targetID = mo_instances [B_playerNo];
					break;
				}
			}
		}
		return (B_targetID != null);
	} else return false;
}

function B_findAvailable () {
	for (var B_playerNo = 0; B_playerNo < mo_instances.length; B_playerNo++) {
		with (mo_instances [B_playerNo]) {
			if (targetName == '' && !isPlaying () && !isPaused ()) {
				B_targetID = mo_instances [B_playerNo];
				onPlay ();
				onPause ();
				onStop ();
				onLoad ();
				if (typeof (B_targetID.metaEventMap) != 'undefined') {
					onMetaEvent ();
					for (var B_eventNo = 0; B_eventNo < metaEventMap.length; B_eventNo++)
						metaEventMap [B_eventNo].active = false
					;
				}
				break;
			}
		}
	}
}

function B_evalPanStr (panStr) {
	panStr = B_stripComment (panStr);
	if (typeof (panStr) == 'number') {
		return panStr;
	} else {
		if (panStr == ')- CENTER -(') {
			return 64;
		} else if (panStr.indexOf ('+') != -1) {
			return Math.round (((panStr.indexOf ('+') - 2) / (panStr.length - 5)) * 127);
		}
	}
}

function B_constrain (newValue,minValue,maxValue) {
	return (newValue < minValue) ? minValue : ((newValue > maxValue) ? maxValue : newValue);
}

function B_bankAndProgram (_iGM,_iSpecial,_iUser,_pGM,_pSpecial) {
	if (_iGM + '' > ' ') {
		B_bankNo = 0;
		B_programNo = B_stripComment (_iGM);
	} else if (_iSpecial + '' > ' ') {
		B_bankNo = 1;
		B_programNo = B_stripComment (_iSpecial);
	} else if (_iUser + '' > ' ') {
		B_bankNo = 2;
		B_programNo = _iUser - 0;
	} else if (_pGM + '' > ' ') {
		B_bankNo = 0;
		B_programNo = 128 + B_stripComment (_pGM);
	} else if (_pSpecial + '' > ' ') {
		B_bankNo = 1;
		B_programNo = 128 + B_stripComment (_pSpecial);
	} else {
		B_bankNo = -1;
	}
}

function B_channelNo (_channelNo) {
	with (B_targetID) {
		if (_channelNo == '[auto]') {
			autoChannelNo = (autoChannelNo % 16) + 1;
			if (autoChannelNo == 10) autoChannelNo = 11;
			B_channelNumber = autoChannelNo;
		} else {
			B_channelNumber = B_stripComment (_channelNo);
		}
	}
}

function B_playFile (_targetName,_looping,_fileURL,_volume) {
	if (B_enabled) {
		if (!B_findTarget (_targetName,_fileURL)) B_findAvailable ();
		if (B_targetID != null) {
			with (B_targetID) {
				if (_targetName != '' && _targetName.charAt (0) != '[') targetName = _targetName;
				setAutostart (true);
				setVolume (B_stripComment (_volume));
				if (fileURL == _fileURL || _fileURL == '') {
					stop ();
					play (_looping == 'yes' || (_looping == 'auto' && fileURL.indexOf ('Background-') == 0));
				} else {
					fileURL = _fileURL;
					play (_looping,fileURL);
				}
			}
		}
	}
}

function B_pauseFile (_targetName,_fileURL,_fadeTime) {
	if (B_findTarget (_targetName,_fileURL)) B_targetID.pause (_fadeTime);
}

function B_stopFile (_targetName,_fileURL,_fadeTime) {
	if (B_findTarget (_targetName,_fileURL)) B_targetID.stop (_fadeTime);
}

b_playGroovoid = B_playFile;
b_pauseGroovoid = B_pauseFile;
b_stopGroovoid = B_stopFile;

b_playMusicFile = B_playFile;
b_pauseMusicFile = B_pauseFile;
b_stopMusicFile = B_stopFile;

function b_preloadMusicFile (_target,_fileURL) {
	if (B_enabled && _fileURL != '') {
		if (!B_findTarget (_target,_fileURL)) B_findAvailable ();
		if (B_targetID != null) {
			with (B_targetID) {
				if (_target != '' && _target.charAt (0) != '[') targetName = _target;
				if (fileURL != _fileURL) {
					fileURL = _fileURL;
					setAutostart (false);
					play (false,_fileURL);
				}
			}
		}
	}
}

function b_playMusicalNote (_target,_channelNo,_iGM,_iSpecial,_iUser,_pGM,_pSpecial,_note,_velocity,_duration,_volume,_pan) {
	if (B_findTarget (_target)) {
		B_channelNo (_channelNo);
		B_bankAndProgram (_iGM,_iSpecial,_iUser,_pGM,_pSpecial);
		with (B_targetID) {
			setController (B_channelNumber,7,B_mapTo127 (B_stripComment (_volume)));
			setController (B_channelNumber,10,B_evalPanStr (_pan));
			if (B_bankNo == -1)
				playNote (B_channelNumber,B_stripComment (_note),B_mapTo127 (B_stripComment (_velocity)),_duration);
				else playNote (B_channelNumber,B_bankNo,B_programNo,B_stripComment (_note),B_mapTo127 (B_stripComment (_velocity)),_duration);
		}
	}
}

function b_stopMusicalNote (_target,_channelNo,_note) {
	if (B_findTarget (_target)) B_targetID.noteOff (B_stripComment (_channelNo),B_stripComment (_note));
}

function b_setGlobalMute (_status) {
	if (B_enabled) mo_instances [0].setGlobalMute (_status == 'Mute');
}

function b_setReverbType (_reverbType) {
	if (B_enabled) mo_instances [0].setReverbType (B_stripComment (_reverbType));
}

function b_setVolume (_target,_volume,_fadeTime) {
	if (B_findTarget (_target)) B_targetID.fadeVolume (null,B_stripComment (_volume),_fadeTime);
}

function b_adjustVolume (_target,_adjustBy,_fadeTime) {
	if (B_findTarget (_target)) {
		with (B_targetID) fadeVolume (null,B_constrain (getVolume () + _adjustBy,0,100),_fadeTime);
	}
}

function b_setTransposition (_target,_transposition) {
	if (B_findTarget (_target)) B_targetID.setTranspose (B_stripComment (_transposition));
}

function b_adjustTransposition (_target,_adjustBy) {
	if (B_findTarget (_target)) {
		with (B_targetID) setTranspose (B_constrain (getTranspose () + B_stripComment (_adjustBy),-48,48));
	}
}

function b_setTempo (_target,_tempo) {
	if (B_findTarget (_target)) B_targetID.setTempo (_tempo);
}

function b_adjustTempo (_target,_adjustBy) {
	if (B_findTarget (_target)) {
		with (B_targetID) setTempo (B_constrain (getTempo () + _adjustBy,10,250));
	}
}

function b_setPosition (_target,_position) {
	if (B_findTarget (_target)) B_targetID.setPosition (_position);
}

function b_adjustPosition (_target,_adjustBy) {
	if (B_findTarget (_target)) {
		with (B_targetID) setPosition (B_constrain (getPosition () + (_adjustBy),0,10000000));
	}
}

function b_showCopyrightInfo (_target) {
	if (B_findTarget (_target)) B_targetID.doMenuItem ('Copyright');
}

function b_releasePlayer (_target) {
	if (B_findTarget (_target)) B_targetID.targetName = '';
}

function b_setChannelInstrument (_target,_channelNo,_iGM,_iSpecial,_iUser,_pGM,_pSpecial) {
	if (B_enabled) {
		B_bankAndProgram (_iGM,_iSpecial,_iUser,_pGM,_pSpecial);
		if (B_findTarget (_target) && B_bankNo != -1)
			B_targetID.setProgram (B_stripComment (_channelNo),B_bankNo,B_programNo)
		;
	}
}

function b_setChannelVolume (_target,_channelNo,_volume) {
	if (B_findTarget (_target))
		B_targetID.setController (B_stripComment (_channelNo),7,B_mapTo127 (B_stripComment (_volume)))
	;
}

function b_adjustChannelVolume (_target,_channelNo,_adjustBy) {
	if (B_findTarget (_target)) {
		with (B_targetID)
			B_channelNo (_channelNo);
			setController (B_channelNumber,7,B_constrain (getController (B_channelNumber,7) + B_mapTo127 (_adjustBy),0,127));
	}
}

function b_setChannelPan (_target,_channelNo,_pan) {
	if (B_findTarget (_target))
		B_targetID.setController (B_stripComment (_channelNo),10,B_evalPanStr (_pan))
	;
}

function b_adjustChannelPan (_target,_channelNo,_adjustBy) {
	if (B_findTarget (_target)) {
		with (B_targetID)
			B_channelNo (_channelNo);
			setController (B_channelNumber,10,B_constrain (getController (B_channelNumber,10) + Math.round (_adjustBy / 200 * 127),0,127));
	}
}

function b_setChannelMute (_target,_channelNo,_status) {
	if (B_findTarget (_target)) {
		_channelNo = B_stripComment (_channelNo);
		if (_status == 'Toggle')
			B_targetID.setChannelMute (_channelNo,!B_targetID.getChannelMute (_channelNo));
			else B_targetID.setChannelMute (_channelNo,_status == 'Mute');
	}
}

function b_setChannelSolo (_target,_channelNo,_status) {
	if (B_findTarget (_target)) {
		_channelNo = B_stripComment (_channelNo);
		if (_status == 'Toggle')
			B_targetID.setChannelSolo (_channelNo,!B_targetID.getChannelSolo (_channelNo));
			else B_targetID.setChannelSolo (_channelNo,_status == 'Solo');
	}
}

function b_setChannelMonophonic (_target,_channelNo,_status) {
	if (B_findTarget (_target)) {
		_channelNo = B_stripComment (_channelNo);
		if (_status == 'Toggle')
			B_targetID.setMonophonic (_channelNo,!B_targetID.getMonophonic (_channelNo));
			else B_targetID.setMonophonic (_channelNo,_status == 'Monophonic');
	}
}

function b_setTrackMute (_target,_trackNo,_status) {
	if (B_findTarget (_target)) {
		if (_status == 'Toggle')
			B_targetID.setTrackMute (_trackNo,!B_targetID.getTrackMute (_trackNo));
			else B_targetID.setTrackMute (_trackNo,_status == 'Mute');
	}
}

function b_setTrackSolo (_target,_trackNo,_status) {
	if (B_findTarget (_target)) {
		if (_status == 'Toggle')
			B_targetID.setTrackSolo (_trackNo,!B_targetID.getTrackSolo (_trackNo));
			else B_targetID.setTrackSolo (_trackNo,_status == 'Solo');
	}
}

/*** Initialisation Section ***/

function b_initialize (stubFileURL,totalPlayers) {
	if (typeof (totalPlayers) != 'number') totalPlayers = 8;
	if (B_enabled) {
		if (typeof (stubFileURL) != 'string') stubFileURL = '';
		var stubSrc = (stubFileURL != '') ? (' SRC="' + stubFileURL + '"') : '';
		for (var B_playerNo = 0; B_playerNo < totalPlayers; B_playerNo++) {
			B_player = new musicObject ('B_playerMO' + mo_instances.length);
			B_player.fileURL = stubFileURL;
			B_player.autoChannelNo = 0;
			B_player.targetName = (B_playerNo == 0) ? '[reserved player]' : '';
			B_player.magicEmbed ('<EMBED' + stubSrc + ' WIDTH=2 HEIGHT=2 HIDDEN AUTOSTART=' + (B_playerNo == 0) + ' VOLUME=100>');
		}
	}
}

/*** LIBRARY HAS LOADED ***/

function b_enablePeer (peerHandle) {
	mo_enableDebug (peerHandle);
	for (var actionSetNo in b_actionNames) {
		var actionSet = b_actionNames [actionSetNo];
		for (var actionNo in actionSet)
			peerHandle ['b_' + actionSet [actionNo]] = window ['b_' + actionSet [actionNo]];
		;
	}
}
