/* 
UTILIZZO DELLA FUNZIONE HINT

[collegamento]
<script language="javascript" src="../../../backend/include/js/include/js/hint.js"></script>

[nella pagina]
<div style="display: none; position: absolute;z-index:110; " id="hint"></div>

[funzionamento]
show_hint(valore)  -> chiama la funzione (valore accetta dati in html... anche iframe che caricano altre pagine)

esempio:
onmouseover="show_hint('<div>suuuuca</div>')" onmouseout="hide_hint()"

*/

var offsetfrommouse=[10,20]; 
var displayduration= 5; 
var currentimageheight = 30;

var currentimagewidth = 50;	// maximum image size.
var timer;

function gettrailobj(){
if (document.getElementById)
return document.getElementById("hint").style
}

function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("hint")
}


function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


function hide_hint(){	
	gettrailobj().display= "none";
	document.onmousemove="";
	gettrailobj().left="-500px"
	clearTimeout(timer);
}

function show_hint(value){

	v = value;
	timer = setTimeout("show('"+value+"');",10);
	followmouse();
}
function show(value){

    var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)
	
	docwidth=2000;
	docheight=2000;

	if( (navigator.userAgent.indexOf("Firefox")!=-1 || (navigator.userAgent.indexOf("Opera")==-1 && navigator.appVersion.indexOf("MSIE")!=-1))) {
		document.onmousemove=followmouse;
		gettrailobjnostyle().innerHTML = value;
		gettrailobj().display="block";
	}
}



function followmouse(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	docwidth=3000;
	docheight=3000;

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < currentimagewidth){
			if(navigator.userAgent.indexOf("Firefox")!=-1)	{xcoord = e.pageX - xcoord - currentimagewidth + 2*offsetfrommouse[0]} else{ xcoord = e.pageX - xcoord - currentimagewidth + 6*offsetfrommouse[0] ;} // Move to the left side of the cursor
			} else {
				xcoord += e.pageX;
			}
			if (docheight - e.pageY < (currentimageheight + 110)){
				ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
			} else {
			ycoord += e.pageY;
			}
	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < currentimagewidth){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - currentimagewidth + 2*offsetfrommouse[0]; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight + 110)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(110 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-offsetfrommouse[0]
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
	if(ycoord < 0) { ycoord = ycoord*-1; }
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
	
	document.onclick=hide_hint;
}
