/****  javascript functions for modules with floating layers ***/

/**** based on:
* Cool DHTML tooltip script- © Dynamic Drive DHTML code library (www.dynamicdrive.com) *
*****/

var fl_enableFloat = false;
var fl_currentFloatID = "";

var fl_ie = document.all
var fl_ns6 = document.getElementById && !document.all

function fl_ietruebody(){
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}	
function fl_floatContentOn(id) {
	fl_enableFloat = true;
	fl_currentFloatID = id;
}
function fl_floatContentOff() {
	var d = $(fl_currentFloatID);
	d.style.display = "none";
	fl_enableFloat = false;
	fl_currentFloatID = "";
}
function fl_positionFloat(e) {
	if(fl_enableFloat) {
		var offsetxpoint = 10;
		var offsetypoint = 10;
		
		var curX=(fl_ns6)?e.pageX : event.clientX+fl_ietruebody().scrollLeft;
		var curY=(fl_ns6)?e.pageY : event.clientY+fl_ietruebody().scrollTop;
		var d = $(fl_currentFloatID);

		d.style.position = "absolute";
		d.style.width = "300px";

		//Find out how close the mouse is to the corner of the window
		var rightedge=fl_ie&&!window.opera? fl_ietruebody().clientWidth-event.clientX-offsetxpoint : window.innerWidth-e.clientX-offsetxpoint-20
		var bottomedge=fl_ie&&!window.opera? fl_ietruebody().clientHeight-event.clientY-offsetypoint : window.innerHeight-e.clientY-offsetypoint-20
		var leftedge=(offsetxpoint<0)? offsetxpoint*(-1) : -1000

		//if the horizontal distance isn't enough to accomodate the width of the context menu
		if (rightedge<d.offsetWidth)
			//move the horizontal position of the menu to the left by it's width
			d.style.left=fl_ie? fl_ietruebody().scrollLeft+event.clientX-d.offsetWidth+"px" : window.pageXOffset+e.clientX-d.offsetWidth+"px"
		else if (curX<leftedge)
			d.style.left="5px"
		else
			//position the horizontal position of the menu where the mouse is positioned
			d.style.left=curX+offsetxpoint+"px"

		//same concept with the vertical position
		if (bottomedge<d.offsetHeight)
			d.style.top=fl_ie? fl_ietruebody().scrollTop+event.clientY-d.offsetHeight-offsetypoint+"px" : window.pageYOffset+e.clientY-d.offsetHeight-offsetypoint+"px"
		else
			d.style.top=curY+offsetypoint+"px"
				
		d.style.display = "block";
	}

}
document.onmousemove=fl_positionFloat;
		
		