//unique id, passed into the player itself AND the proxy
var uid = new Date().getTime();
var flashProxy = new FlashProxy(uid, 'flash/JavaScriptFlashGateway.swf');

//the track click event
function trackClick(e) {
	//call the actionscript function via the proxy
	flashProxy.call('jsPlayTrack', e);
}

//the jquery ready function is unstable in IE7
onloadsAdd( "$('span.play').css( {_cursor:'hand', cursor:'pointer'} ).click( function() { trackClick( $(this).attr('id') ) } );" );
	
/*
 * Icon Management
 * In page track icon management
 */
var prevTrackId = 0;

function updateTrackIcons(id) {
	//alert("click");
	if (prevTrackId != 0) {
		document.getElementById(prevTrackId).setAttribute("class", "play");
		document.getElementById(prevTrackId).setAttribute("className", "play");
	}
	
	//switch the icon to 'play'
	document.getElementById(id).setAttribute("class", "nowplaying");
	document.getElementById(id).setAttribute("className", "nowplaying");
	
	prevTrackId = id;
}

function asPlayTrack(trackID) {	
	//show the current track playing
	updateTrackIcons(trackID);
}	

function asPauseTrack() {
	if (prevTrackId != 0) {
		document.getElementById(prevTrackId).setAttribute("class", "play");
		document.getElementById(prevTrackId).setAttribute("className", "play");
	}
}
