/* Implémente en partie:
toolTips OpenLayers
Purpose: extends OpenLayers API (toolTips)
Details: http://cataloguesig.c-webhosting.org/exemplesOpenLayers/olToolTips.php
Author:  Van De Casteele Arnaud
Date:   february 2008
Version: 0.1	*/

var cX = 0; var cY = 0; var rX = 0; var rY = 0;

function UpdateCursorPosition(e) {
    cX = e.pageX;
    cY = e.pageY;
}

function UpdateCursorPositionDocAll(e) {
    cX = event.clientX;
    cY = event.clientY;
}

// Positionnement absolu du tooltip ŕ hauteur du curseur de la souris.
function AssignPosition(d) {
    if (self.pageYOffset) {
        rX = self.pageXOffset;
        rY = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop) {
        rX = document.documentElement.scrollLeft;
        rY = document.documentElement.scrollTop;
    }
    else if (document.body) {
        rX = document.body.scrollLeft;
        rY = document.body.scrollTop;
    }
    if (document.all) {
        cX += rX;
        cY += rY;
    }
    d.style.left = (cX + 5) + "px";
    d.style.top = (cY + 5) + "px";
}

function HideContent(d) {
    if (d.length < 1) { return; }
    document.getElementById(d).style.display = "none";
}

function ShowContent(d) {
    if (d.length < 1) { return; }
    var dd = document.getElementById(d);
    AssignPosition(dd);
    dd.style.display = "block";
}

function ReverseContentDisplay(d) {
    if (d.length < 1) { return; }
    var dd = document.getElementById(d);
    AssignPosition(dd);
    if (dd.style.display == "none") { dd.style.display = "block"; }
    else { dd.style.display = "none"; }
}

function toolTips(e) {
    if (document.all) {  UpdateCursorPositionDocAll(e); }
    else { UpdateCursorPosition(e); }
    //Nom du marker						
    tooltipText = this.feature.tooltip;
    fragment = document.createDocumentFragment();
    span = document.createElement("div");
    //creation de l'id et de la class
    span.setAttribute("class", "toolTips");
    span.setAttribute("id", "toolTips_");
    // Creation du node text
    texte = document.createTextNode(tooltipText);

    tooltipTable = document.createElement("table");
    tooltipTable.setAttribute("cellspacing", "0");
    tooltipTable.setAttribute("cellpadding", "0");
    tooltipTable.style.borderCollapse = "collapse";
    tooltipTable.setAttribute("border", "0");
    tooltipTBody = document.createElement("tbody");
    tooltipTable.appendChild(tooltipTBody);
    
    trTop = document.createElement("tr");
    tooltipTBody.appendChild(trTop);

    topLeft = document.createElement("td");
    topLeft.style.padding = "0px";
    topLeft.style.height = "13px";
    topLeft.style.width = "11px";
    topLeft.style.backgroundImage= "url(images/topLeft.gif)";
    topLeft.style.backgroundRepeat= "no-repeat";
    trTop.appendChild(topLeft);
    
    topCenter = document.createElement("td");
    topCenter.style.padding = "0px";
    topCenter.style.height = "13px";
    topCenter.style.backgroundImage = "url(images/topCenter.gif)";
    topCenter.style.backgroundRepeat = "repeat-x";
    trTop.appendChild(topCenter);
    
    topRight= document.createElement("td");
    topRight.setAttribute("class", "tooltipTopRight");
    topRight.style.padding = "0px";
    topRight.style.height = "13px";
    topRight.style.width = "5px";
    topRight.style.backgroundImage = "url(images/topRight.gif)";
    topRight.style.backgroundRepeat = "no-repeat";
    trTop.appendChild(topRight);

    trMiddle = document.createElement("tr");
    tooltipTBody.appendChild(trMiddle);
    
    middleLeft = document.createElement("td");
    middleLeft.style.padding = "0px";
    middleLeft.style.width = "11px";
    middleLeft.style.backgroundImage = "url(images/middleLeft.gif)";
    middleLeft.style.backgroundRepeat = "repeat-y";
    trMiddle.appendChild(middleLeft);
     
    middleCenter = document.createElement("td");
    middleCenter.style.padding = "0px";
    middleCenter.style.backgroundImage = "url(images/middleCenter.gif)";
    middleCenter.style.backgroundRepeat = "repeat";
    trMiddle.appendChild(middleCenter);

    middleRight = document.createElement("td");
    middleRight.style.padding = "0px";
    middleRight.style.width = "5px";
    middleRight.style.backgroundImage = "url(images/middleRight.gif)";
    middleRight.style.backgroundRepeat = "repeat-y";
    trMiddle.appendChild(middleRight);

    trBottom = document.createElement("tr");
    tooltipTBody.appendChild(trBottom);
    
    bottomLeft = document.createElement("td");
    bottomLeft.style.padding = "0px";
    bottomLeft.style.height = "5px";
    bottomLeft.style.width = "11px";
    bottomLeft.style.backgroundImage = "url(images/bottomLeft.gif)";
    bottomLeft.style.backgroundRepeat = "no-repeat";
    trBottom.appendChild(bottomLeft);
    
    bottomCenter = document.createElement("td");
    bottomCenter.style.padding = "0px";
    bottomCenter.style.height = "5px";
    bottomCenter.style.backgroundImage = "url(images/bottomCenter.gif)";
    bottomCenter.style.backgroundRepeat = "repeat-x";
    trBottom.appendChild(bottomCenter);
    
    bottomRight = document.createElement("td");
    bottomRight.style.padding = "0px";
    bottomRight.style.height = "5px";
    bottomRight.style.width = "5px";
    bottomRight.style.backgroundImage = "url(images/bottomRight.gif)";
    bottomRight.style.backgroundRepeat = "no-repeat"; 
    trBottom.appendChild(bottomRight);

    middleCenter.appendChild(texte);

    span.appendChild(tooltipTable);    
    
    fragment.appendChild(span);
    document.body.appendChild(fragment);

    divtoolTips = document.getElementById("toolTips_");
    divtoolTips.style.display = "block";
    divtoolTips.style.position = "absolute"; 
    divtoolTips.style.zIndex = 1000000;
    divtoolTips.style.color = this.fontColor;
    divtoolTips.style.paddingLeft = "5px";
    divtoolTips.style.paddingRight = "5px";
    AssignPosition(divtoolTips);
}

function eraseToolTips() {
    old = document.getElementById("toolTips_");
    if (old != null)
        document.body.removeChild(old);
}

