/**
 * Current audio player
 */
var gmc_audio_player = null;


/**
 * All available audio players
 */
var gmc_audio_players = new Array();


/**
 * Player ready event handler
 */
function playerReady(thePlayer) {
	gmc_audio_player = document.getElementById(thePlayer.id);
	addListeners();
	gmc_audio_players.push(thePlayer);
	//jQuery("#footer").append("<p>addListeners for: " + thePlayer.id + "</p>");
}


/**
 * Event listener for the players
 */
function addListeners() {
	if (gmc_audio_player) { 
		gmc_audio_player.addModelListener("STATE", "stateListener");
	} else {
		setTimeout("addListeners()",100);
	}
}


/**
 * Pause all other players if a new player is started
 */
function stateListener(thePlayer) { //IDLE, BUFFERING, PLAYING, PAUSED, COMPLETED

	currentState = thePlayer.newstate;
	previousState = thePlayer.oldstate;

	if (currentState != "PLAYING") {
		return;
	}

	for (var i = 0; i < gmc_audio_players.length; i++) {
		gmc_audio_player = document.getElementById(gmc_audio_players[i].id);
		if (gmc_audio_player.id != thePlayer.id) {
			gmc_audio_player.sendEvent("STOP");		// stop player
		}
	}

	//jQuery("#footer").append("<p>current state of " + thePlayer.id + ": " + currentState + "<br>previous state: " + previousState + "</p>");
	// stop the other players
	/*if (currentState == "PLAYING") {
		console.log( jQuery(".flashvideo:not(id='" + thePlayer.id + "')").get(0) );
	}*/

}

