// window events
window.onresize = setOffsets;
window.onscroll = setOffsets;

// default x & y coordinates
var x_offset = 0;
var y_offset = 0;

// set iframe x & y offset
function setOffsets() {
	// initialize variables
	var thistop   = 0;
	var thisleft  = 0;
	var thiselem  = '';

	if (typeof(hoverframe) == "undefined") { hoverframe = "calendarFrame"; }

	thiselem      = document.getElementById(hoverframe);

	if (document.getBoxObjectFor) {	
		thiselem  = document.getBoxObjectFor(thiselem);
		thistop   = parseInt(thiselem.y) - parseInt(document.body.scrollTop);
		thisleft  = parseInt(thiselem.x) - parseInt(document.body.scrollLeft);
	} else {
		thiselem  = thiselem.getBoundingClientRect();
		thistop   = parseInt(thiselem.top);
		thisleft  = parseInt(thiselem.left);	
	}

	x_offset      = parseInt(document.body.offsetLeft) + parseInt(document.body.scrollLeft) + thisleft;
	y_offset      = parseInt(document.body.offsetTop) + parseInt(document.body.scrollTop) + thistop;
}

// get mouse coordinates
function getMouseCoordinates(e){
	// initialize variables
	var this_x = 0;
	var this_y = 0;

	if (!e) { var e = event; }

	if (e.clientX || e.clientY) {
		this_x = e.clientX + x_offset;
		this_y = e.clientY + y_offset;
	} else if (e.pageX || e.pageY) {
		this_x = e.pageX + x_offset;
		this_y = e.pageY + y_offset;	
	}

	return { x:this_x,y:this_y };
}

// show mouseover html container
function showMouseover(evt,html) {
	// initialize variables
	var mouseCoord = getMouseCoordinates(evt);
	var this_style = "position:absolute;top:" + mouseCoord.y + ";left:" + mouseCoord.x + ";z-index:5;color:#000000;width:297px;";
	var container  = "";
	var x          = hideMouseover();
	
	// create hover container
	container                = document.createElement("DIV");
	container.id             = "hover_container";
	container.align          = "left";
	container.style.position = "absolute";
	container.style.top      = mouseCoord.y;
	container.style.left     = mouseCoord.x;
	container.style.zIndex   = "5";
	container.style.color    = "#000000";
	container.style.width    = "297px";
	container.innerHTML      = html;

	document.body.appendChild(container);
}

// hide mouseover html container
function hideMouseover() {
	// initialize variables
	var x = "";
	
	try {
		document.body.removeChild(document.getElementById("hover_container"));
	} catch (x) {
		// do nothing
	}
	
	return x;
}
