document.write('<link rel="stylesheet" type="text/css" href="css/css_bubblebox.css" />');
document.write('<span id="bubblebox"  class="bubblebox_design" ></span>');

function bubblebox(pageload, param, delay){ 

	bubblebox_load();
	
	//gestion du chargement du contenu par un fichier.
	// @param
	if(!delay) delay=1000;

	if (typeof(askTimer ) != "undefined") {
		clearTimeout(askTimer);
	}
	
	
	askTimer = setTimeout("bubblebox_query('" + pageload + "', '" + param + "')", delay);
	
}

function bubblebox_load(){
	// affiche une mire de chargement
	bubblebox_birth('<div class="bubblebox_loading"><img src="pic/loading.gif" alt="Chargement..."/></div>'); //utilise en texte fixe
}

function bubblebox_timed(pageload, param, delay){
	
	if (typeof(showTimer) != "undefined") {
		clearTimeout(showTimer);
	}
	showTimer = setTimeout("bubblebox('" + pageload + "', '" + param + "')", delay);
	
}

//apparition de la fenetre + appel gestion du mouvement avec souris
function bubblebox_birth(js_text){
	if(js_text!=0)
	document.getElementById("bubblebox").innerHTML =  js_text;
	document.getElementById("bubblebox").style.visibility = "visible";
	document.onmousemove = bubblebox_mouse;
}

//disparition de la fenetre
function bubblebox_die(){
	document.getElementById("bubblebox").style.visibility = "hidden";
	document.getElementById("bubblebox").innerHTML =  '';
	document.onmousemove = null;
}

// appel dynamique d'un fichier (ajax)
function bubblebox_query(pageload, param) {
	
    var xmlHttpReq = false;
    var self = this; 
	// apppel ajax en fonction du navigateur 
    if (window.XMLHttpRequest) { // Mozilla/Safari 
		self.xmlHttpReq = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE 5.5+
		self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}
	
	// @param
    self.xmlHttpReq.open('POST', 'bubblebox.php', true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
    if (self.xmlHttpReq.readyState == 4) {
    	document.getElementById("bubblebox").innerHTML = self.xmlHttpReq.responseText;    	
        }
    }
	
	if(param != '' || param != null){
		
   		qstr = 'ajax=1&pageload=' + pageload + '&' + param;  // NOTE: no '?' before querystring
	}else{
		qstr = 'ajax=1&pageload=' + pageload;
	}
	
    self.xmlHttpReq.send(qstr);
}

//gestion du mouvement avec souris
function bubblebox_mouse(e){
	var x = (navigator.appName.substring(0,3) == "Net") ? e.pageX : event.x+document.body.scrollLeft;
    var y = (navigator.appName.substring(0,3) == "Net") ? e.pageY : event.y+document.body.scrollTop;
	
	
	document.getElementById("bubblebox").style.left = x + 20 + 'px';
	document.getElementById("bubblebox").style.top  = y + 10 +'px';
	/*
    if(document.getElementById("bubblebox").offsetWidth + 20 + x >bubblebox_get_bodyWidth()){
    	document.getElementById("bubblebox").style.left = x  - document.getElementById("bubblebox").offsetWidth - 20 + 'px' ;
    }else{
    	document.getElementById("bubblebox").style.left = x + 20 + 'px';
	}
	
    if(document.getElementById("bubblebox").offsetHeight+y>bubblebox_get_bodyHeight()){
    	document.getElementById("bubblebox").style.top  = bubblebox_get_bodyHeight() - document.getElementById("bubblebox").offsetHeight +'px';
	}else{
    	document.getElementById("bubblebox").style.top  = y + 10 +'px';
	}
	*/
}

function bubblebox_get_bodyHeight(){
	var myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {   
	    myHeight = document.body.clientHeight;
	  }
	return  myHeight;
}

function bubblebox_get_bodyWidth(){
	var myWidth = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    myWidth = window.innerWidth;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    myWidth = document.documentElement.clientWidth;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) { 
	    myWidth = document.body.clientWidth;
	  }
	return  myWidth;
}

