var ap_instances = new Array();

function ap_stopAll(playerID) {
	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 );


$(document).ready(function(){
	
	if($.flash.available != true) return;
	
	$('.player').each(function(i, obj) {
		$(this).flash({
				swf: 'player.swf',
				height: 24,
				width: 290,
				wmode: 'transparent',
				quality: 'high',
				flashvars: {
					playerID: i,
					soundFile: $(this).find('a').attr('href')
				}
			});
		
	});
	
	// $.flash.create(
	// 	{
	// 		swf: 'test_flashvars.swf',
	// 		flashvars: {
	// 			name1: 'jQuery',
	// 			name2: 'SWFObject',
	// 			name3: 'Plugin'
	// 		}
	// 	}
	// 
	// var snippet = $('<object type="application/x-shockwave-flash" data="player.swf" height="24" width="290"><param name="quality" value="high"/><param name="menu" value="false"><param name="wmode" value="transparent"/><param name="movie" value="player.swf"/></object>');
	// 	
	// 	$('a[href$=.mp3]').each(function() {
	// 		console.log(this.href);
	// 	});
	// 	
	//$('<object type="application/x-shockwave-flash" data="player.swf" height="24" width="290"><param name="quality" value="high"/><param name="menu" value="false"><param name="wmode" value="transparent"/><param name="movie" value="player.swf"/></object>');
	
	//<object type="application/x-shockwave-flash" data="audio/player.swf" id="audioplayer1" height="24" width="290"> 

	 
	//<param name="FlashVars" value="playerID=1&amp;soundFile=audio/clip_ra.mp3"> 
	// see if flash is available
	// select anchors with href ending in .mp3
	// iterate through each one and replace with flash player code
	
});
