/**
* (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
var lvu_cardtimeout = setTimeout('', 500);
 var x = false;
 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,mousedelay,scrolling) {
	clearTimeout(lvu_cardtimeout);
	if (!tip_status) return false;	 
	 // add tooltip to document if not already present	
	 if (!(x = document.getElementById(id))) {
		x = document.createElement('div');
		document.body.appendChild(x);
		x.setAttribute('id', id);
	 	x.style.zIndex = '1000';
		x.style.width = (tip_width) ? parseInt(tip_width) + 'px' : '240px';
		x.style.position = 'absolute';
		//Define Timeout functions
		x.onmouseout = function () {lvu_cardtimeout = setTimeout(function() {hideTip(x.id);}, mousedelay)};
		x.onmouseover = function () {clearTimeout(lvu_cardtimeout)};		
	 } else {
		x = document.getElementById(id);
	 }
	x.innerHTML = html;
	// Make tooltip visible
	cancel_button = document.createElement('div');
	cancel_button.setAttribute('id','cancel_button');
	cancel_button.onclick = function() { tipStatus(true); hideTip(''+ id +'', 1); }
	x.appendChild(cancel_button);
	//Output tooltip content into tooltip container
	x.style.display = (x.style._display) ? x.style._display : 'block';
	// position
	var el_h = ( el_h = parseInt(el.style.height)) ? el_h : 0;
	var el_w = ( el_w = parseInt(el.style.width)) ? el_w : 0;
	
	if (scrolling) {
		el = document.getElementById('lvu_scrollbox');
		x.style.top = (getTop(el) + top_offset) +'px';
		x.style.left = (getLeft(el) + left_offset)+'px';
	} else {
		x.style.top = (getTop(el) + el_h + top_offset)  + 'px';
	 	x.style.left = (getLeft(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);
	clearTimeout(lvu_cardtimeout);
//	if (x.style.display != 'none') x.style._display = x.style.display;
	x.style.display = 'none';
	return true;
}

function myUnescape(txt) {
	return decodeURIComponent(txt);
}

function getLeft(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 getTop(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;

}
