// Extended Tooltip Javascript
// DEVELOPED BY Philippe Gachoud for PLURIAL 08.2006

/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	CONSTANTS
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

	var TOP_MORE = 7; //Number of pixels under mouse cursor to display DIV
	var LEFT_MORE = 10; //Number of pixels after mouse cursor to display DIV
	var SCROLLBAR_WIDTH = 19; 


/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	MOUSE UTILS
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

	var gPosX = 0, gPosY = 0;
	
	/********************************************************************************
		SETS THE gPosX and gPosY VARIABLES with mouse coordinates
	********************************************************************************/
	function setMouseCoordinates( e ) { 
		// get the mouse position in the div when the user clicks.
		var posx = 0;
		var posy = 0;
		if (!e) 
			var e = window.event;
		if (e.pageX || e.pageY){ //FF & Netscape
			posx = e.pageX;
			posy = e.pageY;
		}else if (e.clientX || e.clientY){ //IE
			posx = e.clientX + document.body.scrollLeft;
			posy = e.clientY + document.body.scrollTop;
		}
		// posx and posy contain the mouse position relative to the document
		// Do something with this information
		gPosX = posx;
		gPosY = posy;
	}//end Function
		
	function popUp( pEvt, pDivId ) {
		var div = document.getElementById( pDivId );
		setMouseCoordinates( pEvt );
		var lNewPosX = gPosX + LEFT_MORE;
		var lNewPosY = gPosY + TOP_MORE;
		div.style.top = lNewPosY + 'px';
		div.style.left = lNewPosX + 'px';
		div.style.display == 'none' ? div.style.display = 'block' : div.style.display = 'none';

		moveIfOutOfWindow( pDivId, lNewPosX, lNewPosY );
		
//		alert('gPosY:' + gPosY + ' gPosX:' + gPosX);
//		alert('gWindowWidth:' + gWindowWidth + ' gWindowHeight:' + gWindowHeight);
	}//end Function


/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	WINDOWS UTILS
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

	var gWindowWidth = 0;
	var gWindowHeight = 0;
	
	/********************************************************************************
		SETS THE gWindowWidth and gWindowHeight VARIABLES
	********************************************************************************/
	function setWindowSizes() {
	  var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth - SCROLLBAR_WIDTH;// with scrollbars
		myHeight = window.innerHeight - SCROLLBAR_WIDTH;// with scrollbars
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	  }
	  gWindowWidth = myWidth;
	  gWindowHeight = myHeight;
	}//end Function
	
	/********************************************************************************
		returns x and y positions of scroll
	********************************************************************************/
	function getScrollXY() {
	  var scrOfX = 0, scrOfY = 0;
	  if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	  }
	  return [ scrOfX, scrOfY ];
	}//End Function


/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	MISCANCELLOUS
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

	/********************************************************************************
	********************************************************************************/
	function moveIfOutOfWindow ( pDivId, pNewPosX, pNewPosY ){
		setWindowSizes();
		var div = document.getElementById( pDivId );
		if ( div != null ){
			//Width
			var lDivWidth = div.offsetWidth;
			if ( pNewPosX < 0 ){
				div.style.left = 0;
			}else if ( (pNewPosX + lDivWidth) > gWindowWidth && gWindowWidth > lDivWidth ){
				var lLeftToMove = gWindowWidth - lDivWidth; //window width - div width
				div.style.left = lLeftToMove.toString() + 'px';
			}
			//Height
			var lDivHeight = div.offsetHeight;
			if ( pNewPosY < 0 ){
				div.style.top = 0;
			}else if ( (pNewPosY + lDivHeight) > gWindowHeight && gWindowHeight > lDivHeight ){
				var lTopToMove = pNewPosY - lDivHeight; //window height - div height
				div.style.top = lTopToMove.toString() + 'px';
			}
		}//end if
	}//end Function

/*@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
	TOOLTIPS
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@*/

	function hideAllDivs(){
		var divsArray = document.getElementsByTagName('div');
		for ( var i=0; i < divsArray.length; i++){
				if (divsArray[i].className == 'tip')
				divsArray[i].style.display = 'none'; 
			}	
	}//End Function
	
	function hideDiv( pDivId ){
			document.getElementById( pDivId ).style.display = 'none';
	}//end Function
	
	function showOnlyThisDiv ( pEvent, pDivId ){
		hideAllDivs();
		popUp ( pEvent, pDivId );
	}//end Function


