var inplayer;
function play(id, subid) {
	if (inplayer) {
		var req = new Ask(urlroot + 'gen_ajax.php?target=com_media&q=item&id=' + encodeURIComponent(id) + '&sub=' + Number(subid),
			{handler: showitem, indicator: 'hidden_ajax_busy'});
		$('plunk').innerHTML = '<h2>Loading...</h2>';
		mptab('item');
	} else window.open(urlroot + 'gen_ajax.php?target=com_media&q=player&id=' + encodeURIComponent(id), 'player', 'status=1,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1,width=780,height=550');
}
function showitem(xhr) {
	$('plunk').innerHTML = xhr.responseText;
	execJS($('plunk'), true);
}
function mptab(id) {
	var ufo = $('player_ufo');
	if (ufo) {
		if (id == 'item') ufo.style.visibility = 'visible';
		else ufo.style.visibility = 'hidden';
	}
	document.getElementById('mptab_'+id).style.visibility = 'visible';
	var tabs = ['item','video','audio','galleries','slideshows'];
	for (var tab in tabs) if (tabs[tab] != id) document.getElementById('mptab_'+tabs[tab]).style.visibility = 'hidden';
}
/*function fit() {
	if (!document.getElementById('meta') || !document.getElementById('player')) {
		window.setTimeout(fit, 500);
		return;
	}
	poff = findPos(document.getElementById('player'));
	docH = document.getElementById('meta').offsetHeight + document.getElementById('player').offsetHeight + poff[1];
	
	if (self.innerHeight) winH = self.innerHeight;
	else if (document.documentElement && document.documentElement.clientHeight) winH = document.documentElement.clientHeight;
	else if (document.body) winH = document.body.clientHeight;
	else return;

	if (docH > winH) {
		if (docH+35 < self.screen.height) window.resizeTo(780, docH);
		else window.resizeTo(780, self.screen.height-35);
	}

}*/
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

