//--------------------------------------------------
//Info Bubble Script - display rollover popup info
//--------------------------------------------------
//Use onmouseover="showInfoBubble(this);" to display bubble, text will be taken from the 'title' parameter (bubble size will adjust to length of the text)
//Use onmouseout="hideInfoBubble(this);" to hide bubble
//Alternatively, use initInfoBubbble(); to enable info bubble for all tags ('a', 'div', 'img) that have a 'title' parameter defined

function updateInfoBubblePosition(e) {
	var posX = 0;
	var posY = 0;
	var infoObj = document.getElementById('infoBubble');
	
	if (!e) var e = window.event;
	if (e.pageX || e.pageY) 	{
		posX = e.pageX;
		posY = e.pageY;
	}
	else if (e.clientX || e.clientY) 	{
		posX = e.clientX + document.body.scrollLeft
			+ document.documentElement.scrollLeft;
		posY = e.clientY + document.body.scrollTop
			+ document.documentElement.scrollTop;
	}					
	
	infoObj.style.left = (posX-0) + 'px';
	infoObj.style.top = (posY+20) + 'px';			
}

function showInfoBubble(targetObj){
		
	var infoObj = document.getElementById('infoBubble');
	var childNodeObj = infoObj.childNodes;
	var infoInnerObj = childNodeObj[0];
	var infoInnerContent = targetObj.title;
	
	// Detect if the browser is IE or not.
	var IE = document.all?true:false

	// Set up for mouse capture, a special case if not IE
	if (!IE) {
		document.captureEvents(Event.MOUSEMOVE)
	}
	document.onmousemove = updateInfoBubblePosition;
	
	// If IE -- force a position update immediately
	if (IE) {
		var e=window.event;
		updateInfoBubblePosition(e);
	}
	
	// set wrap or nowrap to text depending on the length
	if (infoInnerContent.length > 35){
		infoObj.style.width = '175px';
		infoObj.style.whiteSpace = 'normal';
	}
	else{
		infoObj.style.width = '';
		infoObj.style.whiteSpace = 'nowrap';
	}
	
	//display infoBubble, get text from 'title', remove text from 'title' to prevent triggering the default info bubble
	infoInnerObj.innerHTML = infoInnerContent + '<div class="infoBubbleShadow"></div>';		
	infoObj.title = targetObj.title;
	targetObj.title = '';
	infoObj.style.display = 'block';		
	
}

function hideInfoBubble(targetObj){
	var infoObj = document.getElementById('infoBubble');
		  			
	//hide infoBubble, replcae 'title' with the text
	infoObj.style.display = 'none';	
	targetObj.title = infoObj.title;	
	
	// Detect if the browser is IE or not.
	var IE = document.all?true:false

	// Remove mouse capture, a special case if not IE
	if (!IE) {
		document.releaseEvents(Event.MOUSEMOVE);
	}
	document.onmousemove = null;
}	

function initInfoBubbble(){
	var objects = new Array();
	var targetTags = new Array('a', 'div', 'img');
	
	for (i=0; i<targetTags.length; i++){
		
		//get all objects with the target tag name
		objects = document.body.getElementsByTagName(targetTags[i]);
		
		//define onmouseover and onmouseout events for all tag objects with contents in 'title'
		for (j=0; j<objects.length; j++){
			if (objects[j].title.length > 0){
				objects[j].onmouseover = function onmouseover() {showInfoBubble(this)};
				objects[j].onmouseout = function onmouseout() {hideInfoBubble(this)};
			}
		}
	}
}