// Generic JW MP3 player loader helper stuff

// Default auto-start to no
var  auto_start = 'false';

// Array of installed players indexed by player id
var players = new Array();

// Hook to set listener and add new player to array
function playerReady(obj, what) {
	var objid = obj['id'];
	var player = document.getElementById(obj['id']);
	player.addViewListener("PLAY","playTracker");
	player.addViewListener("STOP","playStopper");
	player.addModelListener("STATE","stateMonitor");
	player.addControllerListener("ITEM","itemMonitor");
	players[objid] = player;
};


// Hook to stop all players when one stop is pressed, since
// user could be confused when off-screen player is going
function playStopper(obj, what) {
	for( var i in players ) {
		if( i != obj['id'] ) {
			players[ i ].sendEvent( "STOP" );
		}
	}
	stopped( obj );
};

// Hook to stop any other active player when "play" is pressed
function playTracker(obj) {
	for( var i in players ) {
		if( i != obj['id'] ) {
			players[ i ].sendEvent( "STOP" );
		}
	}
	played( obj );
};

// Dummy functions for includer to override
function stopped( obj ) {}
function played( obj ) {}
function stateMonitor( obj ) {}
function itemMonitor( obj ) {}

// Generate and write flash player code into a named division
function loadPlayer( url, divid ) {
	var s1 = new SWFObject("../player/player.swf", divid + '_flash','400','20','7');
	s1.addParam('allowfullscreen','true');
	s1.addParam('allowscriptaccess','always');
	s1.addParam('backcolor','FF0000');

	var start_option = 'false';
	if( auto_start == 'yes' ) {
		start_option = auto_start;
	}
	s1.addParam('flashvars',"backcolor=#EBE0CD&autostart=" + start_option
		+ "&file=http://www.mckenzieduo.com/sounds/" + url);
	s1.write( divid );
}

