//unique id, passed into the player itself AND the proxy
var uid = new Date().getTime();
var flashProxy = new FlashProxy(uid, '/flash/JavaScriptFlashGateway.swf');

var currentTrack = "null";

//the track click event
function trackClick(e) { 
	//we have a diff track
	if (e != currentTrack) {
		//call the actionscript function via the proxy
		flashProxy.call('jsPlayTrack', e);
		currentTrack = e;
	}
	else {
		flashProxy.call('jsStopTrack', e);
		currentTrack = "null";
	}	
}

//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 product icon management
 */
var prevTrackId = "";

function updateTrackIcons(id) {
	if (prevTrackId != "") {
		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");
	}
}
