var imgArray = new Array(10);
function initImage() {
    if(!document.getElementById) return;
    for(i = 0; i < imgArray.length; i++) {
        var img = document.createElement("IMG");
        img.src = "images/common/snow.gif";
        img.width = 20; img.height = 20;
        img.style.position = "absolute";
        img.style.left = scrollLeft() +
           Math.floor(Math.random()
              * (winWidth() - img.width)) + "px";
        img.style.top = scrollTop() +
           Math.floor(Math.random()
              * (winHeight() - img.height)) + "px";
        document.body.appendChild(img);
        imgArray[i] = img;
    }
    setTimeout("fallLeaves()", 50);
}

function initImage_spring() {
    if(!document.getElementById) return;
    for(i = 0; i < imgArray.length; i++) {
        var img = document.createElement("IMG");
        img.src = "images/common/sakura1-1.gif";
        img.width = 20; img.height = 20;
        img.style.position = "absolute";
        img.style.left = scrollLeft() +
           Math.floor(Math.random()
              * (winWidth() - img.width)) + "px";
        img.style.top = scrollTop() +
           Math.floor(Math.random()
              * (winHeight() - img.height)) + "px";
        document.body.appendChild(img);
        imgArray[i] = img;
    }
    setTimeout("fallLeaves()", 50);
}



function fallLeaves () {
    for(i = 0; i < imgArray.length; i++) {
        var img = imgArray[i];
        var x = parseInt(img.style.left);
        var y = parseInt(img.style.top);
        y += 2 + Math.floor(Math.random() * 2);
        if(y > scrollTop() + winHeight() - img.height) {
             y = scrollTop();
             x = scrollLeft() +
                Math.floor(Math.random() * winWidth());
        }
        else {
            x += Math.floor(Math.sin(y/40)*2);
            if(x < scrollLeft()) x = scrollLeft();
            else if(x > scrollLeft()
                         + winWidth() - img.width)
               x = scrollLeft() + winWidth() - img.width;
        }
        img.style.left = x + "px";
        img.style.top = y + "px";
    }
    setTimeout("fallLeaves()", 50);
}

function winWidth () {
    if(window.innerWidth)
        return window.innerWidth;
    if(document.compatMode == "CSS1Compat")
        return document.body.parentNode.clientWidth;
    if(document.body.clientWidth)
        return document.body.clientWidth;
    return 600;
}
function winHeight () {
    if(window.innerHeight)
        return window.innerHeight;
    if(document.compatMode == "CSS1Compat")
        return document.body.parentNode.clientHeight;
    if(document.body.clientHeight)
        return document.body.clientHeight;
    return 400;
}
function scrollLeft () {
    if(window.pageXOffset)
        return window.pageXOffset;
    if(document.compatMode == "CSS1Compat")
        return document.body.parentNode.scrollLeft;
    if(document.body.scrollLeft)
        return document.body.scrollLeft;
    return 0;
}
function scrollTop () {
    if(window.pageYOffset)
        return window.pageYOffset;
    if(document.compatMode == "CSS1Compat")
        return document.body.parentNode.scrollTop;
    if(document.body.scrollTop)
        return document.body.scrollTop;
    return 0;
}
