function getWindowHeight() {
    var windowHeight=0;
    if (typeof(window.innerHeight)=='number') {
        windowHeight=window.innerHeight;
    } else {
        if (document.documentElement && document.documentElement.clientHeight) {
            windowHeight = document.documentElement.clientHeight;
        } else {
            if (document.body && document.body.clientHeight) {
                windowHeight=document.body.clientHeight;
            }
        }
    }
    return windowHeight;
}
						
function parallax(){
    scrollTopCur = $(document).scrollTop(); // distance par rapport au haut du document
    heightCur = $(document).height();       // hauteur du document 
    windowHeight = getWindowHeight();       // hauteur "utile" de la fenêtre

    $('#cloud1').css(
        "background-position",
        "50% " +
        Math.round(windowHeight - 700 - (scrollTopCur + windowHeight - heightCur) / 8)
        + "px"
    );
    $('#cloud2').css(
        "background-position",
        "50% " +
        Math.round(windowHeight - 570 - (scrollTopCur + windowHeight - heightCur) / 4)
        + "px"
    );
    $('#cloud3').css(
        "background-position", 
        "50% " + 
        Math.round(windowHeight - 500 - (scrollTopCur + windowHeight - heightCur) / 2) 
        + "px"
    );
    $('#plane').css(
        "background-position", 
        "70% " + 
        Math.round(windowHeight - 600 - (scrollTopCur + windowHeight - heightCur) / 2) 
        + "px"
    );
}

$(function(){
    parallax();                     // calcul au chargement de la page
    $(window).scroll(parallax);     // calcul au défilement de la page
    $(window).resize(parallax);     // calcul au redimensionnement de la page
});
