// (C) Netlogic, 2003

function CreateBaloon() {
	baloon = document.createElement('DIV');
	baloon.setAttribute('id', 'baloon');

	baloonHeader = document.createElement('DIV');
	baloonHeader.setAttribute('id', 'baloonHeader');
	baloonHeader.setAttribute('class', 'direct');

	baloonBody   = document.createElement('DIV');
	baloonBody.setAttribute('id', 'baloonBody');

	baloonFooter = document.createElement('DIV');
	baloonFooter.setAttribute('id', 'baloonFooter');

	baloonBody.innerText = 'baloon';

	baloon.appendChild(baloonHeader);
	baloon.appendChild(baloonBody);
	baloon.appendChild(baloonFooter);

	baloon.onmouseover   = function(e) { this.style.filter = "Alpha(Opacity='100')"; this.style.cursor = 'pointer'; this.style.MozOpacity = '1';}
	baloon.onmouseout    = function(e) { this.style.filter = "Alpha(Opacity='75')";  this.style.cursor = 'auto'; this.style.MozOpacity = '0.75'; }
	baloon.onselectstart = function(e) { return false; }
	baloon.onclick       = function(e) { this.style.display = 'none'; }

	document.body.appendChild(baloon);

	window.onresize      = function(e) { document.getElementById('baloon').style.display = 'none'; }
}

function getBodyScrollTop()
{
	return self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
}


function ShowBaloon(i, str) {
	var baloon = $('#baloon');
	$('#baloonBody').text(str);
	baloon.css('display', 'block');

	var xleft=0;
	var xtop=0;
	if (i != null) {
		var offset = i.offset();
		xleft = offset.left;
		xtop = offset.top;
		xwidth = i.width();
		xheight = i.height();
	} else {
		xwidth  = 25;
		xheight = 10;
	}
	
	bwidth =  baloon.width();

	w = window;
	xbody  = document.compatMode=='CSS1Compat' ? w.document.documentElement : w.document.body;
	dwidth = xbody.clientWidth  ? xbody.clientWidth   : w.innerWidth;
	bwidth = baloon.width();
	flip = !(xwidth - 10 + xleft + bwidth < dwidth);
	
	var baloon_top = xheight - 10 + xtop;
	baloon.css('top', baloon_top);
	baloon.css('left', xleft + xwidth - (flip ? bwidth : 0)  - 25);

	$('#baloonHeader').addClass(flip ? 'baloonHeaderFlip' : 'baloonHeaderDirect');

	var scrollTop = getBodyScrollTop();
	var scrollNeed = parseInt(baloon_top);
	if (scrollTop > scrollNeed) window.scrollTo(0, scrollNeed - 8);
	
	i.focus();
	return false;
}

function HideBaloon() {
	document.getElementById('baloon').style.display = 'none';
}

 
