// Apparition des info-bulles

$(document).ready(function () {
	// Référence aux liens des icones
	var sInfoBulle = "";
	var sClass = "";
	var sWidth = "";
	var sHeight = "";
	var iTop = 0;
	var iLeft = 0;
	
	// Ajout de l'attribut title aux liens des news, aux titres des formulaires de contact et LI
	$('#accueil #news h3 a').attr({title:"Cliquez sur ce titre pour afficher le texte de la nouvelle et fermer celle qui est ouverte."});
	$('#contact h4 a').attr({title:"Utiliser ce formulaire pour nous envoyer un message. Nous vous r&eacute;pondrons rapidement."});
	$('#frmInfos label a').attr({title:"Abonnez-vous aux notes d'information pour &ecirc;tre au courant des nouveaut&eacute;s du site."});
	
	// Recherche des liens du document
	$('a').hover(
		function (e) {
			// Enregistrement du title et suppression pour qu'il ne s'affiche pas
			if ($(this).attr('title') && $(this).attr('class')) {
				sInfoBulle = $(this).attr('title');
				sClass = $(this).attr('class');
				
				$(this).removeAttr("title");
				
				// Création de l'info-bulle
				$("body").append('<div id="infoBulle" class="' + sClass + '">' + sInfoBulle + '</div>');
				
				// Détermination de la taille en fonction du mode
				if (detectQuirksMode()) {
					sWidth = "249px";
					sHeight = "93px";
				}
				else {
					sWidth = "219px";
					sHeight = "63px";
				}
			
				// Détermination de la position en fonction de la classe
				switch (true) {
					case sClass.indexOf("basDroite") != -1:
						iTop = getY(e) + 20;
						iLeft = getX(e) - 10;
						break;
					case sClass.indexOf("basGauche") != -1:
						iTop = getY(e) + 20;
						iLeft = getX(e) - 220;
						break;
					case sClass.indexOf("hautDroite") != -1:
						iTop = getY(e) - 103;
						iLeft = getX(e) - 10;
						break;
					case sClass.indexOf("hautGauche") != -1:
						iTop = getY(e) - 103;
						iLeft = getX(e) - 220;
						break;
				} 
				
				$('#infoBulle').css({width:sWidth}).css({height:sHeight}).css("top", iTop).css("left", iLeft);
			}
		},
		// Réattribution du title et suppression de l'info-bulle
		function () {
			$(this).attr("title", sInfoBulle);
			$('#infoBulle').remove();
		}
	);
});

function detectQuirksMode() {
  if (typeof document.compatMode != "undefined" &&
      /CSS.Compat/.test(document.compatMode)) {
    return false;
  }
  return true;
}

// Find the horizontal position of the cursor
function getX(e) {
    // Normalize the event object
    e = e || window.event;

    // Check for the non-IE position, then the IE position, and finally return 0
    return e.pageX || e.clientX + document.body.scrollLeft || 0;
}

// Find the vertical position of the cursor
function getY(e) {
    // Normalize the event object
    e = e || window.event;

    // Check for the non-IE position, then the IE position, and finally return 0
    return e.pageY || e.clientY + document.body.scrollTop || 0;
}
