/* - - - - - - - - - - - - - - - - - - - - - - -
 JavaScript
 vendredi 22 février 2008 16:15:29
 HAPedit 3.1.11.111
 - - - - - - - - - - - - - - - - - - - - - - - */
/* Script pour les boîtes flottantes */

var oFlottant=new Array();                          // tableau des objets flottants
var omoveFlottant=false;                            // Flottant en cours de déplacement
var margeFlottant="10,10".split(",");               // position de référence de l'objet flottant en cours de déplacement
var fcloseFlottant=false;                           // flag de demande de "fermeture" d'un flottant (en cours de sélection)
var charcloseFlottant="¯,-".split(",");             // caractères "restaurer / réduire" du bouton
var maxzFlottant=101;                               // Zindex le plus élevé des flottants (celui de la classe flottant + 1

var flot="flot1,flot2,flot3,philippe".split(",");   // liste des identifiants de flottants dans la page

function initFlottant() {
    /* Fonction d'initialisation des flottants, appelée normalement par onload() */
    
    
    // remplissage du tableau de référence
    for (i=0;i<flot.length;i++) {
        o=document.getElementById(flot[i]);
        oFlottant[i]=new Array();
        oFlottant[i][0]=flot[i];    // id
        oFlottant[i][1]=o;          // objet
        oFlottant[i][2]=true;       // affiché ?
    }
}

function searchFlottant(flot) {
    /* fonction de recherche du flottant conteneur de l'objet en référence */
    
    /* tant que l'objet courant n'est pas un flottant, on cherche un objet parent */
    while (flot && flot.className!="flottant") flot=flot.parentNode;
    
    /* on a trouvé un flottant contenant ... c'est lequel parmi ceux enregistrés ? */
    for (i in oFlottant) {
        o=oFlottant[i]
        if (o[1]==flot) return o;
    }
    return false;
}

function searchFlottantById(flot) {
    /* fonction de recherche d'un flottant par son id dans la liste des flottants enregistrés */
    for (i in oFlottant) {
        o=oFlottant[i]
        if (o[0]==flot) return o;
    }
    return false;
}

function closeFlottant(o) {

    /* fonction de fermeture (invisible) d'un flottant */
    fcloseFlottant=true;                // flag de traitement de fermeture en cours
    flot=searchFlottant(o);             // recherche du flottant à fermer
    if (flot) {                         // on l'a trouvé, on le ferme
        flot[1].style.display="none";
        flot[2]=false;
    } else alert('pas trouvé');         // on l'a pas trouvé ... c'est pas normal
}

function openFlottant(oid) {
    /* fonction d'ouverture d'un flottant */
    fcloseFlottant=false;               // annulation de traitement de fermeture
    flot=searchFlottantById(oid);       // recherche du flottant à ouvrir
    if (flot) {                         // on l'a trouvé on l'ouvre
        flot[1].style.display="block";
        flot[2]=true;
    } else alert('pas trouvé');         // on l'a pas trouvé, c'est pas normal
}

function reduceFlottant(o) {
    /* Fonction de réduction/restauration d'un flottant */
    flot=searchFlottant(o);                         // recherche du flottant à traiter
    if (flot) {
        if (flot[1].style.overflow=="hidden") {     // Il est réduit ? on le restaure
            flot[1].style.overflow="visible";
            flot[1].style.height="auto";
            o.innerHTML=charcloseFlottant[1];
        }else{                                      // sinon on le réduit
            o.innerHTML=charcloseFlottant[0];
            flot[1].style.overflow="hidden";
            flot[1].style.height=o.parentNode.offsetHeight+"px";
        }
    }else alert('pas trouvé')                       // on l'a pas trouvé, c'est pas normal
}

function startmoveFlottant(o,e) {
    /* fonction d'initialisation du déplacement d'un flottant */
    omoveFlottant=searchFlottant(o);                            // on cherche le flottant à traiter
    if (omoveFlottant && ! fcloseFlottant) {                    // on l'a trouvé et il est pas en cours de fermeture
        margeFlottant[0]=(e.offsetX) ? e.offsetX:e.layerX;      // on stocke la position relative du clic
        margeFlottant[1]=(e.offsetY) ? e.offsetY:e.layerY;
        if (omoveFlottant[1].style.zIndex<maxzFlottant) {       // on place le flottant "au dessus" des autres
            maxzFlottant++;
            omoveFlottant[1].style.zIndex=maxzFlottant;
        }
    }
}
function moveFlottant(e) {
    /* fonction de déplacement d'un flottant */
    
    if(omoveFlottant) {                             // on a un flottant en cours de déplacement ... ouf
        o=omoveFlottant[1];
        x=(e.x) ? e.x:e.pageX;                      // on calcule sa position relative
        y=(e.y) ? e.y:e.pageY;
        o.style.left=(x-margeFlottant[0])+"px";     // par rapport à la position du clic
        o.style.top=(y-margeFlottant[1])+"px";
    }
}

// on intercepte le mousedown ... pour que le drag marche même si il y a eu des pépins
window.onmousedown=moveFlottant;


