//I5 Category
//ILAnd5 2008
//http://www.iland5.com

var tip_status = true; 
var i5_cardtimeout = setTimeout('', 500);
var x = false;

function i5_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 i5_showTip(el, id, html, top_offset, left_offset, tip_width, cursor_follow, cursor_type, mousedelay, scrolling) {
	clearTimeout(i5_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;
		x.style.position = 'absolute';
		//Define Timeout functions
		x.onmouseout = function () {i5_cardtimeout = setTimeout(function() {i5_hideTip(x.id);}, mousedelay)};
		x.onmouseover = function () {clearTimeout(i5_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() { i5_tipStatus(true); i5_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('i5_scrollbox');
		x.style.top = (i5_getTop(el) + top_offset) +'px';
		x.style.left = (i5_getLeft(el) + left_offset)+'px';
	} else {
		x.style.top = (i5_getTop(el) + el_h + top_offset)  + 'px';
	 	x.style.left = (i5_getLeft(el) + el_w + left_offset)  + 'px';
	 }
	 // mouse cursor
	if (cursor_type) el.cursor = cursor_type;
	
	return true;
}

function i5_hideTip(id, force) {
	if (!tip_status && force != 1) return false;
	var x = document.getElementById(id);
	clearTimeout(i5_cardtimeout);
	x.style.display = 'none';
	return true;
}

function i5_myUnescape(txt) {
	return decodeURIComponent(txt);
}

function i5_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 i5_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;

}
