/* currently active player */
var curPlayer;
var curColor;
/* change this to Your preferred color for active player */
var activeColor = '#FFCC33';
/* called automatically everytime the player is initiated */
function playerReady(obj) {
	var player = document.getElementById(obj['id']);
	/* stopAll called when state of the player changes */
	player.addModelListener("STATE", "stopAll");
}
function stopAll(obj) {
	var plCol = document.getElementsByName("productstracks");
	if(plCol.length>1) {
	if(obj.newstate == 'PLAYING') {
		if(curPlayer != null) {
			/* change back background color for
			parent div */
			var parent = document.getElementById(curPlayer.id).parentNode.parentNode.parentNode;
			parent.style.background = curColor;
			/* if PLAY button pressed
			on the player different from the active one,
			then stop current player */
			curPlayer.sendEvent("STOP");
		}
		/* active player is currently played one */
		curPlayer = document.getElementById(obj.id);
		/* remember parent's div background color */
		var parent = document.getElementById(curPlayer.id).parentNode.parentNode.parentNode;
		curColor =  parent.style.backgroundColor;
		/* set active color */
		parent.style.background = activeColor;
	}
	else if(obj.newstate != 'BUFFERING') {
		/* every other situation  clear active player */
		var parent = document.getElementById(curPlayer.id).parentNode.parentNode.parentNode;
		parent.style.background = curColor;
		/* if file track doesn't exist then without
		this one statement below script will not work
		as expected */
		curPlayer.sendEvent("STOP");
		curPlayer = null;
	}
	}
}
