/****************************************
musicObject EXTENSION - Version 1.3.1
written by Chris van Rensburg					  

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

with (navigator) isJavaScript1_1 = 
	userAgent.indexOf ('Mozilla/3.') != -1 ||
	userAgent.indexOf ('Mozilla/4.') != -1 ||
	userAgent.indexOf ('Mozilla/5.') != -1 ||
	userAgent.indexOf ('MSIE 4.') != -1 ||
	userAgent.indexOf ('MSIE 5.') != -1
;

function requireJavaScript1_1 (frameHandle) {
	if (typeof (frameHandle) == 'undefined' || !frameHandle) frameHandle = window;
	if (isJavaScript1_1) {
		return true;
	} else {
		with (frameHandle.document) {
			writeln (
				'<CENTER><BR><BR>' +
				'<TABLE WIDTH=95% BORDER=0 CELLSPACING=0 CELLPADDING=1 BGCOLOR=666666><TR><TD>' +
				'<TABLE WIDTH=100% BORDER=0 CELLSPACING=0 CELLPADDING=8 BGCOLOR=DDDDDD><TR><TD><FONT FACE="Arial,Helvetica,Verdana" COLOR=000000><FONT SIZE=+2>This page has been optimized for JavaScript 1.1 features only supported in <FONT COLOR=FF0000>Netscape Navigator 3.0x or higher</FONT>, and Microsoft <FONT COLOR=FF0000>Internet Explorer 4.0x or higher</FONT>.<P>It can <U>not</U> be shown on Navigator 2.0x or earlier, or Internet Explorer 3.0x or earlier.</FONT><P><CENTER><FONT SIZE=+1>Get the latest version<BR>|<BR></FONT><TABLE BORDER=0 CELLSPACING=0 CELLPADDING=5><TR><TD><FORM METHOD=GET ACTION="http://www.netscape.com" TARGET="_top"><INPUT TYPE=submit VALUE="NETSCAPE NAVIGATOR"></FORM></TD><FORM METHOD=GET ACTION="http://www.microsoft.com" TARGET="_top"><INPUT TYPE=submit VALUE="INTERNET EXPLORER"></FORM><TD></TD></TR></TABLE></FONT></CENTER></TD></TR></TABLE>' +
				'</TD></TR></TABLE>' +
				'</CENTER><BR>'
			);
			return false;
		}
	}
}

/*** random () ***/

function random (range) {
	return Math.round (Math.random () * (range - 1)) + 1;
}

/*** randomPP object class ***/

function randomPP_selectNext () {
	var flagsFound = 0;
	var randomFlag = random (this.flagsRemaining);
	for (var flagNo = 1; flagNo <= this.totalFlags; flagNo++) {
		if (!this.flags [flagNo]) {
			flagsFound++;
			if (flagsFound == randomFlag) {
				randomFlag = flagNo;
				this.flags [randomFlag] = true;
				break;
			}
		}
	}
	this.flagsSelected++;
	this.flagsRemaining--;
	if (this.flagsSelected == this.totalFlags) {
		this.flagsSelected = 0;
		this.flagsRemaining = this.totalFlags;
		for (var flagNo = 1; flagNo <= this.totalFlags; flagNo++) {
			this.flags [flagNo] = false;
		}
	}
	return randomFlag;
}

function randomPP (range) {
	this.flags = new Array (range);
	this.totalFlags = range;
	this.flagsSelected = 0;
	this.flagsRemaining = this.totalFlags;
	this.selectNext = randomPP_selectNext;
	for (var flagNo = 1; flagNo <= this.totalFlags; flagNo++) {
		this.flags [flagNo] = false;
	}
}

/*** randomFromList () ***/

function randomFromList (prefix,suffix) {
	var totalItems = randomFromList.arguments.length - 2;
	if (totalItems == 0) {
		return prefix + suffix;
	} else {
		var randomItemNo = random (totalItems);
		return prefix + randomFromList.arguments [randomItemNo + 1] + suffix;
	}
}

/*** noteObject class definition ***/

function noteObject (bankNo,programNo,noteNo,velocity,duration) {
	this.bankNo = bankNo;
	this.programNo = programNo;
	this.noteNo = noteNo;
	this.velocity = velocity;
	this.duration = duration;
}

/*** urlize () ***/

function urlize (unurlized,caseConversion,spacerChar,illegalCharSubstitute) {
	var
		validChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890',
		validSpacers = '.-_~@#&+',
		result = '',
		inWord = false,
		spacersBetween = false,
		startFound = false
	;
	if (typeof (spacerChar) != 'string' || validSpacers.indexOf (spacerChar) == -1) spacerChar = '-';
	if (typeof (illegalCharSubstitute) != 'string' || validSpacers.indexOf (illegalCharSubstitute) == -1) illegalCharSubstitute = '';
	if (typeof (caseConversion) != 'string') caseConversion = 'lower';

	if (caseConversion == 'upper') {
		unurlized = unurlized.toUpperCase ();
	} else if (caseConversion == 'lower') {
		unurlized = unurlized.toLowerCase ();
	}

	for (var charNo = 0; charNo < unurlized.length; charNo++) {
		var currentChar = unurlized.charAt (charNo);
		if (currentChar == ' ' || validSpacers.indexOf (currentChar) != -1) {
			if (currentChar == ' ') {
				inWord = false;
			} else {
				if (!inWord) spacersBetween = true;
				result += currentChar;
			}
		} else {
			if (!inWord) {
				inWord = true;
				if (startFound && !spacersBetween) result+= spacerChar;
				spacersBetween = false;
			}
			result += (validChars.indexOf (currentChar) != -1) ? currentChar : illegalCharSubstitute;
			if (!startFound) startFound = true;
		}
	}
	return result;
}

/*** xFrame () ***/

function xFrame (functionName,functionParameters) {
	if (top.persist_frame != null) {
		if (top.persist_frame [functionName] != null)
			eval ('top.persist_frame.' + functionName + '(' + functionParameters + ')')
		;
	}
}

/*** randomGroovoid function ***/

function randomGroovoid (groovoidPrefix) {

	var groovoidNames = new Array ('UI-BeepClick1','UI-Chimes','UI-Choice1','UI-Click1','UI-Click2','UI-Click3','UI-Click4','UI-Click5','UI-Click6','UI-Click7','UI-Click8','UI-Click9','UI-Click10','UI-Click11','UI-Click12','UI-Click13','UI-Click14','UI-Click15','UI-Click16','UI-Click17','UI-Click18','UI-CarriageReturn','UI-FunnyBeep','UI-Load1','UI-MouseOver1','UI-MouseOver2','UI-MouseOverDrone1','UI-Notification1','UI-Notification2','UI-Notification3','UI-OpenOrClose1','UI-OpenOrClose2','UI-OpenOrClose3','UI-Question','UI-SimpleClick1','UI-SimpleClick2','UI-SystemBeep','UI-TeletypeBurst2','UI-TypeOneKey','Hits-BlastOff','Hits-Kicker1','Hits-Kicker2','Hits-Kicker5','Hits-LudwigVan','Hits-Magic','Hits-MysteryChime','Hits-SportsOrganCharge','Hits-ZoomAndHit','Fanfare-Arrival','Fanfare-Cascade','Fanfare-CorpSting1','Fanfare-Finished','Fanfare-Horserace','Fanfare-Mars','Fanfare-Majesty','Fanfare-Presenting','Fanfare-Sports','Background-Beeps','Background-Clock','Background-Dubby','Background-Funky','Background-Groove2','Background-InfoPulse','Background-Latin','Background-News','Background-Piano','Background-SimpleTyping','Background-Smooth','Background-StillWaiting','Background-Teletype','Misc-CashRegister','Misc-ThruPhoneRing');

	if (typeof (groovoidPrefix) == 'undefined' || groovoidPrefix == null || groovoidPrefix == '') {
		return groovoidNames [Math.round (Math.random () * (groovoidNames.length - 1))];
	} else {
		var
			matches = new Array (),
			totalMatches = 0
		;
		for (var groovoidNo = 0; groovoidNo < groovoidNames.length; groovoidNo++) {
			if (groovoidNames [groovoidNo].indexOf (groovoidPrefix) == 0) {
				matches [totalMatches] = groovoidNo;
				totalMatches++;
			}
		}
		if (totalMatches == 0) {
			return '';
		} else if (totalMatches == 1) {
			return groovoidNames [matches [0]];
		} else {
			return groovoidNames [matches [Math.round (Math.random () * (totalMatches - 1))]];
		}
	}
}

/*** musicObjectGroup class definition ***/

function mog_play (musicObjectID) {
	with (this) {
		if (musicObjectID.isReady ()) {
			stop ();
			musicObjectID.setAutostart (true);
			musicObjectID.play ();
			lastPlayed = musicObjectID;
		}
	}
}

function mog_stop () {
	with (this) {
		if (lastPlayed == null) {
			for (objNo = 1; objNo <= musicObjects.length; objNo++) musicObjects [objNo - 1].stop ();
		} else {
			lastPlayed.stop ()
		}
	}
}

function mog_isReady () {
	return this.ready;
	with (this) {
		if (!ready) {
			ready = true;
			for (objNo = 1; objNo <= musicObjects.length; objNo++) {
				ready = ready && musicObjects [objNo - 1].isReady ();
				if (!ready) break;
			}
		}
		return ready;
	}
}

function musicObjectGroup () {
	/*** Constructor Properties ***/
	this.musicObjects = new Array ();
	for (argNo = 1; argNo <= musicObjectGroup.arguments.length; argNo++) {
		this.musicObjects [argNo - 1] = musicObjectGroup.arguments [argNo - 1];
	}

	/*** Instance State Variables ***/
	this.lastPlayed = null;
	this.ready = false;
	
	/*** Exposed Methods ***/
	this.play = mog_play;
	this.stop = mog_stop;
	this.isReady = mog_isReady;
}
