_lastPlayIndex=false;
_currPlayIndex=false;

var player;

function playerReady(obj) {
	var id = obj['id'];
	var version = obj['version'];
	var client = obj['client'];
	player = document.getElementById(id);
	// player.addModelListener("STATE","stopPlaylist");
}

function stopPlaylist(obj) {
	if (_listview && obj.newstate=='COMPLETED') {
		stopSong('playbutton_' + _lastPlayIndex, _lastPlayIndex);
	}
}
  
function sendEvent(typ,prm) { 
  player.sendEvent(typ,prm); 
}

function playSong(link, index, player) {
	player=player || 'mediaplayer';
	linkobj=document.getElementById(link);
	if (_lastPlayIndex) {
		var last_player=document.getElementById('playbutton_' + _lastPlayIndex);
		if (last_player) {
			last_player.innerHTML='&gt;';
			last_player.href="javascript:playSong('playbutton_" + _lastPlayIndex + "', '" + _lastPlayIndex + "');"; 
		}
	}
	_lastPlayIndex=index;
	linkobj.href="javascript:stopSong('" + link + "', " + index + ", '" + player + "');";
	linkobj.innerHTML='X';
  sendEvent('ITEM', index - 1);
}

function stopSong(link, index, player) {
	player=player || 'mediaplayer';
	var linkobj=document.getElementById(link);
	linkobj.innerHTML='&gt;';
	linkobj.href="javascript:playSong('" + link + "', " + index + ", '" + player + "');";
	_lastPlayIndex=false;
  sendEvent('STOP', 0);
}

