/*
 * Poelinca Dorin <poelinca@gmail.com>
 * Bizware <www.bizware.com>
 * Retrieves a string from curl.php via Ajax and write`s it inside a tooltip div.
 * 02.august.2008
 * please see the attached mouse.html example on usage
*/
var lastUrl = "da";
var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMouseXY;
var tempX = 0;
var tempY = 0;
var lang = 'en';


function tooltip(url){
	var ajaxRequest;  //The variable that makes Ajax possible!
	
	try{
		//Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
	} catch (e){
		//Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				//Something went wrong
				document.getElementById("mouseOverTooltip").innerHTML = "Your browser doesn`t support ajax";
				return false;
			}
		}
	}
	//Gets data from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			document.getElementById("mouseOverTooltip").innerHTML = ajaxRequest.responseText;
		}
	}
	/*
	 * CHANGE PATH TO curl.php
	 */
	ajaxRequest.open("GET", "http://immobiliere-pelou.com/wp-content/plugins/cs/tooltip.php?tool="+url+"&lang="+lang, true);
	ajaxRequest.send(null); 

} //end function


function getMouseXY(e) {

	if (IE) { // grab the x-y pos.s if browser is IE
    	tempX = event.clientX + document.body.scrollLeft
    	tempY = event.clientY + document.body.scrollTop
  	} else {  // grab the x-y pos.s if browser is NS
    	tempX = e.pageX;
    	tempY = e.pageY;
  	}  
  	// catch possible negative values in NS4
  	if (tempX < 0){tempX = 0}
  	if (tempY < 0){tempY = 0}  
  	
  	return true
} //end function


function showTooltip(event,url) {
	
	//set the loading stuff if the perious url differs
		if ( lastUrl != url ) {
			document.getElementById("mouseOverTooltip").innerHTML = '<center><img src="http://immobiliere-pelou.com/wp-content/plugins/cs/loading.gif" alt="loading" /><br />Loading ...</center>';
			
		}
	//end
	
	//Get mouse coordinates
	//	pos_x = event.offsetX?(event.offsetX):event.pageX-document.getElementById("mouseOverTooltip").offsetLeft;
		pos_x = tempX;
		pos_y = tempY;
    	//pos_y = event.offsetY?(event.offsetY):event.pageY-document.getElementById("mouseOverTooltip").offsetTop;	
	//end

	//Show the tooltip div
		document.getElementById("mouseOverTooltip").style.top = ( pos_y + 20 ) + "px";
		document.getElementById("mouseOverTooltip").style.left = ( pos_x + 10 ) + "px";
		document.getElementById("mouseOverTooltip").style.visibility = "visible";
	//end
	
	//Get the content from the server and write it down in the tooltip div\
		if ( lastUrl != url ) {
			tooltip(url);
			lastUrl = url+"hkuygkugk";
		}
	//end

} //end function

function hideTooltip(event) {
	//Hide the tooltip div
		document.getElementById("mouseOverTooltip").style.visibility = "hidden";
	//end
	
} //end function

function moveTooltip(event) {
	//move the tooltip after the mouse
		pos_x = tempX;
		pos_y = tempY;
		document.getElementById("mouseOverTooltip").style.top = ( pos_y + 20 ) + "px";
		document.getElementById("mouseOverTooltip").style.left = ( pos_x + 10 ) + "px";
	//end
} //end function

