var ap_instances = new Array();

function ap_stopAll(playerID) {
/* -- Does not work and generates too much traffic.
// Query download counter (assumes it exists)
//  Requires jQuery
// TODO: Doesn't quite work. It is out of sync with player which
// may have already incremented the count BUT has a good file OR
// has yet to increment the count that would return a bad file.
  $j.get('/download/is_allowed/stream', function(data){
    if(data.indexOf('no') > -1) {
      location.href=location.href;
    }
  });
*/
	for(var i = 0;i<ap_instances.length;i++) {
		try {
			if(ap_instances[i] != playerID) {
        document.getElementById("audioplayer" + ap_instances[i].toString()).SetVariable("closePlayer", 1);
      }
			else {
        document.getElementById("audioplayer" + ap_instances[i].toString()).SetVariable("closePlayer", 0);
      }
		} catch( errorObject ) {
			// stop any errors
		}
	}
}

function ap_registerPlayers() {
	var objectID;
	var objectTags = document.getElementsByTagName("object");
	for(var i=0;i<objectTags.length;i++) {
		objectID = objectTags[i].id;
		if(objectID.indexOf("audioplayer") == 0) {
			ap_instances[i] = objectID.substring(11, objectID.length);
		}
	}
}

var ap_clearID = setInterval( ap_registerPlayers, 100 );

