/**
* (c) www.fijiwebdesign.com 
* @package liveusers
* @sub-package JS tooltip Library
* @description Creates a tooltip that is overlayed above the document
*/

var tip_status = true; // global tooltip on/off flag
function tipStatus (status) {
	tip_status = status;
}

/**
* Creates a custom hovering tooltip
* @param object htmlDivElement srcElement of Event
* @param string id of custom tooltip div
* @param string urlencoded html
* @param int top offset of tooltip from srcElement
* @param int left offset of tooltip from srcElement
* @param int width of tooltip div
* @param bool static tooltip or follow cursor
* @param string mouse cursor format(hand, pointer, crosshair, help, wait )
*/
function showTip(el, id, html, top_offset, left_offset, tip_width, cursor_follow, cursor_type) {

	if (!tip_status) return false;
	 
	 // add tooltip to document if not already present
	 var x = false;
	 if (!(x = document.getElementById(id))) {
		x = document.createElement('div');
		x.style.position = 'absolute';
		document.body.appendChild(x);
		x.setAttribute('id', id);
		x = document.getElementById(id);
	 }
	 
	 x.style.position = 'absolute';
	 x.style.width = (tip_width) ? parseInt(tip_width) + 'px' : '240px';
	 var img = document.createElement('img');
	 img.onclick = function() { tipStatus(true); hideTip(''+ id +'', 1); }
	 img.setAttribute('align', 'right');
	 img.src = 'modules/liveusers/images/cancel.gif';
	 x.innerHTML = '';
	 x.appendChild(img);
	 var span = document.createElement('span');
	 span.innerHTML = myUnescape(html);
	 x.appendChild(span);

	 x.style.display = (x.style._display) ? x.style._display : 'block';
	 x.style.zIndex = '1000';

	 var el_h = ( el_h = parseInt(el.style.height)) ? el_h : 0;
	 var el_w = ( el_w = parseInt(el.style.width)) ? el_w : 0;

	 // position
	 x.style.top = (Top(el) + el_h + top_offset)  + 'px';
	 x.style.left = (Left(el) + el_w + left_offset)  + 'px';

	 // mouse cursor
	 if (cursor_type) el.cursor = cursor_type;
	 
	 return true;
}

function hideTip(id, force) {
	if (!tip_status && force != 1) return false;
	var x = document.getElementById(id);
	x.style._display = x.style.display;
	x.style.display = 'none';
	return true;
}

function myUnescape(txt) {
	return decodeURIComponent(txt);
}

function Left(elem){
	var x=0;
	if (elem.calcLeft)
		return elem.calcLeft;
	var oElem=elem;
	while(elem){
		 if ((elem.currentStyle)&& (!isNaN(parseInt(elem.currentStyle.borderLeftWidth)))&&(x!=0))
			x+=parseInt(elem.currentStyle.borderLeftWidth);
		 x+=elem.offsetLeft;
		 elem=elem.offsetParent;
	  }
	oElem.calcLeft=x;
	return x;
}

function Top(elem){
	 var x=0;
	 if (elem.calcTop)
		return elem.calcTop;
	 var oElem=elem;
	 while(elem){
		 if ((elem.currentStyle)&& (!isNaN(parseInt(elem.currentStyle.borderTopWidth)))&&(x!=0))
			x+=parseInt(elem.currentStyle.borderTopWidth);
			x+=elem.offsetTop;
			elem=elem.offsetParent;
	 }
	 oElem.calcTop=x;
	 return x;

}
