var selected = 0;
var playing = 0;
var loaded = 0;
function playsong(o,id,load) {
	if (playing) {
		var stopbut = getobj('stopc-'+playing);
		hideobj(stopbut);
		unhide('playc-' + playing);
		playing = 0;
	}
	if (selected) {
		var selbut = getobj('stopc-'+selected);
		selbut.parentNode.parentNode.className = '';
	}
	var player = getobj('musicplayer');
	if (	player
	&&	(	player.sendEvent
		||	player.loadFile
		)
	) {
		hideobj(o);
		unhide('stopc-' + id);
		var oldstyle = false;
		if (loaded != load) {
			if (player.loadFile) {
				oldstyle = true;
				player.loadFile(load);
			} else {
				player.sendEvent('LOAD',{file:load});
			}
			loaded = load;
		}
		if (!playing) {
			if (oldstyle) {
				player.sendEvent('playpause');
			} else {
				player.sendEvent('PLAY','true');
			}
		}
		o.parentNode.parentNode.className = 'hilited';
		playing = selected = id;
	}
}
function getUpdate(type,prm1,prm2) {
	if (type != 'state') {
		return;
	}
	var playo = getobj('playc-'+selected);
	if (!playo) {
		return;
	}
	var pauso = getobj('stopc-'+selected);
	if (!pauso) {
		return;
	}
	if (prm1 == 2) {
		// play
		if (!playing) {
			unhideobj(pauso);
			hideobj(playo);
			playing = selected;
		}
	} else if (prm1 == 0) {
		// stop
		if (playing) {
			unhideobj(playo);
			hideobj(pauso);
			playing = 0;
		}
	}
}
function stopsong(o,id) {
	if (!playing) {
		return;
	}
	hideobj(o);
	unhide('playc-' + id);
	var player = getobj('musicplayer');
	if (player) {
		if (player.loadFile) {
			player.sendEvent('playpause');
		} else {
			player.sendEvent('PLAY','false');
		}
	}
	playing = 0;
}

