// ------------------- Java Script 4 all pages body ------------------- 

// ---- www.kostenlose-javascripts.de/javascripts/verschiedenes/schneeflocken-mit-bildern.html ----
  // ---- here it is - with a fjew modifications MR 2010 ----
var snowflake;  // array 4 pictures names
var snowcount;  // array 4 pictures count


 // #### main settings => ####
var speed = 25; // speed -> low=fast, high=slow

snowflake = new Array("./images/feste/flake1.gif", "./images/feste/flake2.gif", "./images/feste/flake3.gif"); // MR
snowcount = new Array(3, 4, 5); //MR
 // #### <= main settings ####


var spacerx = 40; // space 2 right MR
var spacery = 65; // space 2 bottom MR

var no = snowcount[0] + snowcount[1] + snowcount[2];  // count of flakes
var snowindex = 0;  // for snowflake[ ]

var dx, xp, yp;    // coordinate and position variables
var am, stx, sty;  // amplitude and step variables

var xx = 0; // counter MR
var i, doc_width, doc_height;
doc_width = 50; // get it later - MR
doc_height = 50; // get it later - MR

dx = new Array();
xp = new Array();
yp = new Array();
am = new Array();
stx = new Array();
sty = new Array();

for (i = 0; i < no; ++ i) {
    dx[i] = 0;                        // set coordinate variables
    xp[i] = Math.random()*(doc_width);  // set position variables
    yp[i] = Math.random()*doc_height;
    am[i] = Math.random()*20;         // set amplitude variables
    stx[i] = 0.02 + Math.random()/10; // set step variables
    sty[i] = 0.7 + Math.random();     // set step variables
    document.write("<div id=\"schneedot"+ i +"\" style=\"position: ");  // MR - keep it simple!
    document.write("absolute; z-index: "+ i +"; visibility: ");
    document.write("visible; top: 15px; left: 15px;\"><img src=\"");
    document.write(snowflake[snowindex] + "\" border=\"0\"></div>");
    if (i==snowcount[0] - 1 || i==snowcount[0] - 1 + snowcount[1]) {
        // ---- use next pic MR
        snowindex++;
    }
}

function snowIE() {  // IE main animation function
    // get width allways 2 avoid horizontal scrolling caused by flakes out of range
    // because of change of window size by user
    doc_width = document.body.clientWidth - spacerx; // MR

    if (xx==0) {
        // get height only once MR
        doc_height = document.body.clientHeight - spacery; // MR
        xx = 1;  // => do never again this
    }

    for (i = 0; i < no; ++ i) {  // iterate for every dot
        yp[i] += sty[i];
        if (yp[i] > doc_height || xp[i] > doc_width || xx == 1) { // MR
            xp[i] = Math.random() * (doc_width-am[i] - 30);
            if (xx == 1) {
                // init first time yp randomly 4 all flakes MR
                yp[i] = Math.random()*(doc_height);
            } else {
                yp[i] = 0;
            }
            stx[i] = 0.02 + Math.random()/10;
            sty[i] = 0.7 + Math.random();
        }
        dx[i] += stx[i];
        document.getElementById("schneedot"+i).style.top = yp[i] + "px";
        document.getElementById("schneedot"+i).style.left = (xp[i] + am[i]*Math.sin(dx[i]))  + "px";
    }
    xx++;  // never again any init
    setTimeout("snowIE()", speed);
}

// ---- start up ----
window.onload = function() {
    // wait to get correct height of DOC  and check real weather condition MR
   snowIE();
}

// ---- END OF SCRIPT ----

