var offsetX = -50;	// x offset of tooltip
var offsetY = 20;		// y offset of tooltip
var ie = document.all;
var ns6 = document.getElementById && !document.all;
var enableTip = false;

function ieBody() {
	return(document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body;
}

function getTooltip(message, colorBG, msgWidth) {
	if(ie || ns6) {
		if(typeof msgWidth != "undefined") {
			tooltipObject.style.width = msgWidth + "px";
		}
		if(typeof colorBG != "undefined" && colorBG != "") {
			tooltipObject.style.backgroundColor = colorBG;
		}

		tooltipObject.innerHTML = message;
		tooltipObject.style.textAlign = "justify";
		enableTip = true;
		return false
	}
}

function positionTip(e) {
	if(enableTip) {
		var curX = (ns6) ? e.pageX : event.clientX + ieBody().scrollLeft;
		var curY = (ns6) ? e.pageY : event.clientY + ieBody().scrollTop;

		// determine how close the mouse is to the corner of the window
		var rightedge = ie && !window.opera ? ieBody().clientWidth - event.clientX - offsetX : window.innerWidth - e.clientX - offsetX - 20;
		var bottomedge = ie && !window.opera ? ieBody().clientHeight - event.clientY - offsetY : window.innerHeight - e.clientY - offsetY - 20;

		var leftedge = (offsetX < 0) ? offsetX * (-1) : -1000;

		// if the horizontal distance isn't enough to accomodate the width of the context menu
		if(rightedge < tooltipObject.offsetWidth) {
			// move the horizontal position of the menu to the left by it's width
			tooltipObject.style.left = ie ? ieBody().scrollLeft + event.clientX - tooltipObject.offsetWidth + "px" : window.pageXOffset + e.clientX - tooltipObject.offsetWidth + "px";
		}
		else if(curX < leftedge) {
			tooltipObject.style.left = "5px";
		}
		else {
			// position the horizontal position of the menu where the mouse is positioned
			tooltipObject.style.left = curX + offsetX + "px";
		}

		// same concept with the vertical position
//		if(bottomedge < tooltipObject.offsetHeight) {
//			tooltipObject.style.top = ie ? ieBody().scrollTop + event.clientY - tooltipObject.offsetHeight - offsetY + "px" : window.pageYOffset + e.clientY - tooltipObject.offsetHeight - offsetY + "px";
//		}
//		else {
			tooltipObject.style.top = curY + offsetY + "px";
			tooltipObject.style.visibility = "visible";
//		}
	}
}

function remTooltip() {
	if(ie || ns6) {
		enableTip = false;
		tooltipObject.style.visibility = "hidden";
		tooltipObject.style.left = "-1000px";
		tooltipObject.style.backgroundColor = "";
		tooltipObject.style.width = "";
	}
}

function initTooltip() {
	document.onmousemove = positionTip;
}

function setTooltip (whichTip) {
	var myTooltips = "";
	var myColor = "#004d3d";
	var myWidth = 330;

	switch (whichTip) {
		
		case "siteTracking":
			myTooltips = 'The path each visitor took to navigate the site beginning with the page of arrival through the final page visited. Every new session is treated as its own entry even if the visitor has accessed the site earlier the same day.';
			getTooltip(myTooltips, myColor, myWidth);
			break;
			
		case "pageHitCount":
			myTooltips = 'The number of times a particular page was visited. This report shows both the number of hits and the number of unique hits as well as displays the date of the last hit.';
			getTooltip(myTooltips, myColor, myWidth);
			break;
		
		case "linkHitCount":
			myTooltips = 'The number of times a particular link was clicked. These are links which point to either a local hypertext document or an external web site. These stats do not include those links which point to a document unless the document is contained on an external site.';
			getTooltip(myTooltips, myColor, myWidth);
			break;
			
		case "docHitCount":
			myTooltips = 'The number of times a particular document was viewed. These are links which point to the many document types including (but not limited to): .pdf, .doc, .xls, .ppt, .jpg, etc. These stats do not include those links which point to hypertext documents.';
			getTooltip(myTooltips, myColor, myWidth);
			break;
		
		case "emailHitCount":
			myTooltips = 'The number of times a particular email address was clicked. Also included are the name of the page from which the email address was clicked, the name of the person to whom the email is being sent and said recipient\'s email address.';
			getTooltip(myTooltips, myColor, myWidth);
			break;
			
		case "ipList":
			myTooltips = 'A listing of each distinct IP address that has thus far visited the site. Also included is whether or not the IP address is that of a UO campus computer.';
			getTooltip(myTooltips, myColor, myWidth);
			break;
			
		case "contactSent":
			myTooltips = 'All online contact form submissions and their respective data. Included are:<ul class=\"tooltips\"><li>sender name, email, and IP address</li><li>content of submission</li><li>date of submission</li>';
			getTooltip(myTooltips, myColor, myWidth);
			break;
			
		case "emailSent":
			myTooltips = 'All online email submissions and their respective data. Included are:<ul class=\"tooltips\"><li>sender name, email, and IP address</li><li>recipient name and email</li><li>content of submission</li><li>date of submission</li>';
			getTooltip(myTooltips, myColor, myWidth);
			break;
			
		case "siteSearches":
			myTooltips = 'All site searches that have thus far been executed. Returns the query searched for, the textual result, the number of results found, the frequency of that particular search query, and the date the query was last searched.';
			getTooltip(myTooltips, myColor, myWidth);
			break;
			
		case "siteSearchFollows":
			myTooltips = 'These are the stats which pertain to a particular search query and the number of times a resulting page was visited based on that search.';
			getTooltip(myTooltips, myColor, myWidth);
			break;
	
		default:
			break;
		
	}
	
}