/**********************************************************
 TRUCKSTOPCO.com - FONCTIONS DIV_POPUP
 Créé le 5 juillet 2005 par Jean-Bernard Filion
 Dernière modification : 5 juillet 2005
**********************************************************/

/*-------------------------------------------------------*/
// PARAMÈTRES USAGERS /////////////////////////////////////
/*-------------------------------------------------------*/
// - Définition du ID de la div_popup
// - Définition des styles CSS de la div_popup
/*-------------------------------------------------------*/
var div_id = 			"div_pop_up0000";

var div_style = 		"";
	//div_style += 		"width:;";
	//div_style += 		"height:;";
	div_style += 		"padding:5px;";
	div_style += 		"padding-left:8px; padding-right:10px;";
	div_style += 		"color:#21211d;";
	div_style += 		"background-color:#fffde6;";
	div_style += 		"border:1px solid #8f8f8b;";
	div_style += 		"font-size:11px";

/*-------------------------------------------------------*/
// INIT SYSTEM /////////////////////////////////////
/*-------------------------------------------------------*/
var xmouse = 		0;
var ymouse = 		0;
var over_right = 	false;
var over_bottom = 	false;
var isUp =			false;	
var isFX =			false;		// True seulement si lié à Script.aculo.us

init_div_popup();

//Init des paramètres de mouseTracking
IE = document.all ? true : false
if(!IE) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;

/*-------------------------------------------------------*/
// FONCTIONS APPELÉS PAR LA PAGE //////////////////////////
/*-------------------------------------------------------*/
// - afficher_div_popup(str_message)
// - masquer_div_popup()
/*-------------------------------------------------------*/
function afficher_div_popup(str_message){
	deplacer_div_popup();
	valider_position();
	
	$(div_id).innerHTML = str_message;
	
	isUp = true;
	
	if(isFX) Effect.Appear(div_id,{duration: 0.3});
	else	$(div_id).style.display = 'block';
}

//--------------------------------------------------------
function masquer_div_popup(){
	isUp = 						false;
	$(div_id).style.display = 	'none';
	//$(div_id).innerHTML = 		'';
}

/*-------------------------------------------------------*/
// FONCTIONS SYSTÈMES //////////////////////////
/*-------------------------------------------------------*/
// - deplacer_div_popup()
// - getMouseXY(e)
/*-------------------------------------------------------*/
//---------------------------------------------------------------------
function init_div_popup(){
	//Écriture de la DIV
	document.write('<div id="'+div_id+'" style="display:none; position:absolute; top:; left:; right:; bottom:; z-index:99; '+div_style+'">');
	document.write('</div>');
}
//---------------------------------------------------------------------
function valider_position(){
	// Calcul de l'espace
	div_width =		Number($(div_id).style.width.replace(/px/,''));
	div_height = 	Number($(div_id).style.height.replace(/px/,''));
	
	var div_right = 	xmouse + 10 + div_width;
	var div_bottom = 	ymouse + 10 + div_height;
	
	if (document.all){
		margin_right = 		document.body.clientWidth - div_right;
		margin_bottom = 	document.body.clientHeight - div_bottom;
	}else{
		margin_right = 		window.innerWidth - div_right;
		margin_bottom = 	window.innerHeight - div_bottom;
	}
	
	over_right = (margin_right < 75) ? true : false;
	over_bottom = (margin_bottom < 75) ? true : false;
	
}
//---------------------------------------------------------------------
function deplacer_div_popup(){
	
	ypos = 		(ymouse + 10) + 'px';
	xpos = 		(xmouse + 10) + 'px';
	
	//Si l'espace est négatif, il faut overrider
	if (over_right && over_bottom){
		ypos = 		(ymouse - 10 - div_height) + 'px';
		xpos = 		(xmouse - 10 - div_width) + 'px';
	}else if(over_right){
		xpos = 		(xmouse - 10 - div_width) + 'px';
	}else if(over_bottom){
		ypos = 		(ymouse - 15 - div_height) + 'px';
	}

	$(div_id).style.top = ypos;
	$(div_id).style.left = xpos;
}
//---------------------------------------------------------------------
//---------------------------------------------------------------------
function getMouseXY(e){

	if(IE){ 
		tempX = event.clientX + document.documentElement.scrollLeft;
		tempY = event.clientY + document.documentElement.scrollTop;
	
	}else{ 
		tempX = e.pageX;
		tempY = e.pageY;
	}  
	
	// catch possible negative values in NS4
	if(tempX < 0)	tempX = 0;
	if(tempY < 0)	tempY = 0;
  
	xmouse = tempX;
	ymouse = tempY;

	if(isUp) deplacer_div_popup();
	return true;
}