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