	soundManager.onload = function() {
		soundPlayer = new SoundPlayer();

		soundPlayer.playtune(1);
	};

	function SoundPlayer() {

		var self = this;
		var oSM = soundManager;
		
		oSM.defaultOptions = {
		  'autoLoad': false,             // enable automatic loading (otherwise .load() will be called on demand with .play()..)
		  'stream': true,                // allows playing before entire file has loaded (recommended)
		  'autoPlay': false,             // enable playing of file as soon as possible (much faster if "stream" is true)
		  '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
		  'whileplaying': null, 		// function() {self.whileLoading();}, // callback during play (position update)
		  'onstop': null,                // callback for "user stop"
		  'onfinish': function() {self.endtune();},              // callback function for "sound finished playing"
		  'onbeforefinish': null,        // callback for "before sound finished playing (at [time])"
		  'onbeforefinishtime': 5000,    // offset (milliseconds) before end of sound to trigger beforefinish..
		  'onbeforefinishcomplete':null, // function to call when said sound finishes playing
		  'onjustbeforefinish':null,     // callback for [n] msec before end of current sound
		  'onjustbeforefinishtime':200,  // [n] - if not using, set to 0 (or null handler) and event will not fire.
		  'multiShot': true,             // let sounds "restart" or layer on top of each other when played multiple times..
		  'pan': 0,                      // "pan" settings, left-to-right, -100 to 100
		  'volume': 100                  // self-explanatory. 0-100, the latter being the max.
		}			
		
			var tune = Array();

			var tuneCount = 0;		
		
		$$('a[href$=mp3]').each(function(linky) {
			//console.log("---------------------------------"+linky.href+" = " + linky.title);
			tuneCount++;
			oSM.createSound(linky.title, linky.href);	
			tune[tuneCount] = linky.title;
			linky.href = "#";
		});				
		
		this.clicktune = function(gid) {
			for(i=1;i<=tuneCount;i++) {
				if (tune[i] == gid) {
					oSM.stopAll();					
					this.playtune(i);
				};
			};
		};
		
		
		this.track = "";
		this.tuneid = 0;
		
		this.play = function() {
			this.playtune(this.tuneid);
		};
		
		this.playtune = function(tuneid) {
			this.tuneid = tuneid;
			oSM.play(tune[tuneid]);
			$('pagePlayer').setHTML(this._makeHTML("pause"));
		
		}
		
		this.nexttune = function() {
			oSM.stopAll();
			//console.log("nexttune:current="+this.tuneid);
			this.tuneid++
			if (this.tuneid==tune.length) {
				this.tuneid=1;
			}
			//console.log("nexttune:playtune="+this.tuneid);			
			this.playtune(this.tuneid);
		
		}
		
		this.endtune = function() {
			//this.nexttune();
			$('pagePlayer').setHTML(this._makeHTML("play"));			
		}
		
		this.pause = function() {
			oSM.pause(tune[this.tuneid]);
			$('pagePlayer').setHTML(this._makeHTML("resume"));
		} 
		
		this.resume = function() {
			oSM.resume(tune[this.tuneid]);
			$('pagePlayer').setHTML(this._makeHTML("pause"));
		} 
		
		
/*
		this.whileLoading = function() {
			$('pagePlayer').setHTML(this._makeHTML("loading"));
		
		}	
*/
	
		this._makeHTML = function(command) {

			result = "<em>Now Playing</em><br/>"+tune[this.tuneid]+"<br/>&nbsp;(&nbsp;<a href='#' onclick='soundPlayer."+command+"();' class='pagePlayerLink'>"+command+"</a>&nbsp;)";
			result = result + "&nbsp;<a href='#' onclick='soundPlayer.nexttune();' class='pagePlayerLink'>next</a>";
			return result;
		}
	
	};
	

	
