
var baloontimeout=false;
var baloons=new Array();
var baloon_exclusive=false;
var curbaloon=false;
var curbaloon_to=false;

function showBaloon(el, offsetX, offsetY, contentelement, canclose, width, height) {
	if (el.id && curbaloon==el.id) {
		clearTimeout(curbaloon_to);
		return;
	} else {
	}
	if (isNaN(offsetX)) offsetX=-100;
	if (isNaN(offsetY)) offsetY=30;
	if (isNaN(width)) width=340;
	if (isNaN(height)) height='auto';
	if (baloon_exclusive && !canclose) return;

	if (canclose) {
		$('baloon_close').show();
		baloon_exclusive=true;
	} else {
		$('baloon_close').hide();
	}
	if ($('baloon').style.display!='none' || curbaloon!=el.id) realyhide();
	if (typeof(contentelement)=='string') $('baloon_content').innerHTML=contentelement;
	else if (typeof(contentelement)=='object' && contentelement.innerHTML) $('baloon_content').innerHTML=contentelement.innerHTML;

	if (baloontimeout) clearTimeout(baloontimeout);
	baloontimeout=false;

	$('baloon').style.width=width;
	$('baloon').style.height=height;

	if (typeof(el)=='object') {
		var tmpleft=(Position.cumulativeOffset(el)[0] + offsetX);
		var tmpright=(Position.cumulativeOffset(el)[1] + offsetY);
		$('baloon').style.left = tmpleft<0 ? 0 : tmpleft;
		$('baloon').style.top = tmpright<0 ? 0 : tmpright;
		if (el.id) curbaloon=el.id;
	} else {
		Position.prepare();
		var wh=$('baloon').getDimensions();
		var tmpleft=Math.round((document.body.clientWidth/2)-(wh.width/2)) + Position.deltaX + offsetX;
		var tmpright=Math.round((document.body.clientHeight/2)-(wh.height/2)) + Position.deltaY + offsetY;
		$('baloon').style.left = tmpleft<0 ? 0 : tmpleft;
		$('baloon').style.top = tmpright<0 ? 0 : tmpright;
	}

	setTimeout("$('baloon').show()", 500);
}

function hideBaloon() {
	//$('debug').innerHTML=$('debug').innerHTML+'hide, ';
	if (!baloon_exclusive) {
		curbaloon_to=setTimeout("realyhide()", 500);
		//$('baloon').hide();
		//$('baloon_content').innerHTML='';
		//curbaloon=false;
	}
}

function realyhide() {
	baloon_exclusive=false;
	clearTimeout(curbaloon_to);
	$('baloon').hide();
	$('baloon_content').innerHTML='';
	curbaloon=false;
	curbaloon_to=false;
}

