

function _getElement(id)
{
	if (document.getElementById && document.getElementById(id)) {
		return document.getElementById(id);
	}
	else if (document.all && document.all[id]) {
		return document.all[id];
	}
	else {
		return false;
	}
}

function setBlockDisplay(id,display_type)
{
	_getElement(id).style.display = display_type;
}


function setVisibility(id,is_visible) 
{
	_getElement(id).style.visibility = (is_visible) ? 'visible' : 'hidden';
}

function changeVisibility(id)
{
	//if visiblility is not set it will show not hide it
	if (_getElement(id).style.visibility == 'visible')
		setVisibility(id,false);	
	else{
		setVisibility(id,true);	
	}
	return;	
	//alert(_getElement(id).style.visibility.hidden);
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

var last_balloon_content_id;
var last_balloon_relative_to;

function showBalloon(content_id,relative_to)
{
	if (content_id == null) content_id   = last_balloon_content_id;
	if (relative_to == null) relative_to = last_balloon_relative_to;
	
	last_balloon_content_id = content_id;
	last_balloon_relative_to = relative_to;
	
	_getElement('balloon_content').innerHTML =  _getElement(content_id).innerHTML;
	_getElement('balloon').style.visibility = 'visible';
	
	var x = findPosX(_getElement(content_id)) + 1;
	var y = findPosY(_getElement(content_id)) - 2;
	
	var window_width = 0;
	
	if (document.all) {
		window_width=document.body.offsetWidth;
	}
	else if (window.innerWidth) {
		window_width=window.innerWidth - 13;
	}
	
	if (x > (window_width - 220)) {
		x = window_width - 250;
		setBlockDisplay('balloon_arrow_left','none');
		setBlockDisplay('balloon_arrow_right','none');
	}
	else {
		setBlockDisplay('balloon_arrow_left','block');
		setBlockDisplay('balloon_arrow_right','none');
	}
	
	//x = x - (screen.width - 760)/2;
	
	_getElement('balloon').style.left = x + 'px';
	_getElement('balloon').style.top  = y + 'px';
	
	//alert(x);
}

function hideBalloon()
{
	_getElement('balloon').style.visibility = 'hidden';
}
