﻿// ***********************************************************
// Gestion multinavigateur de l'opacité
// ***********************************************************

function cChangeOpacity(opacityPercent, elmt) {
    var targetElmt = elmt
    if (targetElmt.filters) {
        targetElmt.style.filter = "alpha(opacity=" + opacityPercent + ")"
    } else {
        targetElmt.style.setProperty("-moz-opacity", opacityPercent / 100, "");
        targetElmt.style.setProperty("-khtml-opacity", opacityPercent / 100, "");
        targetElmt.style.setProperty("opacity", opacityPercent / 100, "");
    }
}

function cChangeOpacityById(opacityPercent, targetId) {
    var targetElmt = getElement(targetId)
    if (targetElmt.filters) {
        targetElmt.style.filter = "alpha(opacity=" + opacityPercent + ")"
    } else {
        targetElmt.style.setProperty("-moz-opacity", opacityPercent / 100, "");
        targetElmt.style.setProperty("-khtml-opacity", opacityPercent / 100, "");
        targetElmt.style.setProperty("opacity", opacityPercent / 100, "");
    }
}







// ***********************************************************
// Fondu enchainé d'image
// ***********************************************************

function cSwap(ReplaceBy, elmt, speed) {
    
    // ReplaceBy = HTML Frgament
    // elmt = Elément de destination
    // speed = variation sur la vitesse
    if (speed == null || speed == undefined) {
        speed = 10
    }

    var h;
    var cSwapFromElmt = null;
    cSwapFromElmt = elmt.childNodes[0];
    h = String(elmt.childNodes[0].clientHeight).replace("px", "");
    cSwapFromElmt.style.position = "relative";
    cSwapFromElmt.style.top = "0px";
    cSwapFromElmt.style.left = "0px";
    cSwapFromElmt.style.zIndex = 10
    elmt.style.height = Number(h) + "px";
    elmt.style.overflow = "hidden"


    var cSwapToElmt = null
    cSwapToElmt = document.createElement("div")
    cSwapToElmt.style.position = "relative"
    cSwapToElmt.style.top = (-Number(h)) + "px"
    cSwapToElmt.style.left = "0px"
    cSwapToElmt.style.zIndex = 1
    cSwapToElmt.innerHTML = ReplaceBy
    cSwapToElmt.style.display = "block"
    elmt.appendChild(cSwapToElmt)
    cChangeOpacity(0, cSwapToElmt)

    // Ajout WTC
    cSwapToElmt.setAttribute("tag", cSwapToElmt.childNodes[0].getAttribute("tag"));

    var timer = 1
    for (i = 0; i < 101; i++) {
        setTimeout("cSwapFade(" + i + ",'" + elmt.id + "')", (speed * timer));
        timer++;
    }
}

function cSwapFade(opacityPercent, SwarpTargetId) {
    var elmt = getElement(SwarpTargetId)

    if (opacityPercent == 0) {
        elmt.childNodes[1].style.display = "block"
    }
    if (opacityPercent == 100) {
        cChangeOpacity(opacityPercent, elmt.childNodes[1])
        elmt.childNodes[1].style.top = "0px"
        elmt.childNodes[1].style.zIndex = 1
        var elmtChild = elmt.childNodes[0]
        elmt.removeChild(elmtChild)
        return
    }
    cChangeOpacity(100 - opacityPercent, elmt.childNodes[0])
    cChangeOpacity(opacityPercent, elmt.childNodes[1])
}
var isFirst = true;
