var no = 15; // Anzahl der Schneeflocken im Fenster
var speed = 40; // je kleiner um so schneller fallen die Bilder
flypic = new Array(); // Platzhalter für die Bilder-Namen
var nop = 5; // Anzahl der Bilder
var picnr; // aktuelle Flocken-Nummer für Berechnung
var ns4up = (document.layers) ? 1 : 0;  // NS4+
var ie4up = (document.all) ? 1 : 0;  // IE4+
var gecko = (document.getElementById) ? 1 : 0;  // Gecko + NS6
var opera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1) && ((document.getElementById) ? 1 : 0);  // Opera
var dx, xp, yp;    // Koordinaten- und Positions-Variablen
var am, stx, sty;  // Schwingungs- und Schrittweiten-Variablen
var i, doc_width, doc_height; // Lauf-Variable, Fenster-Größe

// wichtig fuer MSIE muss leftmargin & topmargin = 0 gesetzt werden
for(i=0;i<nop;i++) { flypic[i]="/pic/snow/sf"+(i+1)+".gif"; }  // die Bilder-Namen

if (ns4up) {
	doc_width_def = self.outerWidth;
	doc_height_def = self.outerHeight;
} else
if (ie4up || opera) {
	doc_width_def = document.body.clientWidth;
	doc_height_def = document.body.clientHeight;
} else
if (gecko) {
	doc_width_def = self.outerWidth;
	doc_height_def = self.outerHeight;
}

doc_width = doc_width_def;
doc_height = doc_height_def;
dx = new Array();
xp = new Array();
yp = new Array();
am = new Array();
stx = new Array();
sty = new Array();

for (i = 0; i < no; ++ i) {  
  picnr = i % nop;   // Berechnung des Bilder-Namens (modulo)
  dx[i] = 0;                        // set coordinate variables
  xp[i] = Math.random()*(doc_width-50);  // 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
  if (ns4up) {                      // set layers
    document.write('<layer name="dot'+i+'" left="15" top="15" visibility="show"><img src="'+flypic[picnr]+'" border="0"></layer>');
  }
  else if (ie4up) {
    document.write('<div id="dot'+i+'" style="POSITION: absolute; Z-INDEX: '+ i +'; VISIBILITY: visible; TOP: 15px; LEFT: 15px;"><img src="'+flypic[picnr]+'" border="0"></div>');
  }
  else if (opera) {
    document.write('<div id="dot'+i+'" style="POSITION: absolute; Z-INDEX: '+ i +'; VISIBILITY: visible; TOP: 15px; LEFT: 15px;"><img src="'+flypic[picnr]+'" border="0"></div>');
  }
  else if (gecko) {
    document.write('<div id="dot'+i+'" style="POSITION: absolute; Z-INDEX: '+ i +'; VISIBILITY: visible; TOP: 15px; LEFT: 15px;"><img src="'+flypic[picnr]+'" border="0"></div>');
  }
}

function snowNS() {  // Netscape main animation function
for (i = 0; i < no; ++ i) {  // iterate for every dot
yp[i] += sty[i];
if (yp[i] > doc_height-50) {
xp[i] = Math.random()*(doc_width-am[i]-30);
yp[i] = 0;
stx[i] = 0.02 + Math.random()/10;
sty[i] = 0.7 + Math.random();
doc_width = doc_width_def;
doc_height = doc_height_def;
}
dx[i] += stx[i];
document.layers["dot"+i].top = yp[i];
document.layers["dot"+i].left = xp[i] + am[i]*Math.sin(dx[i]);
}
setTimeout("snowNS()", speed);
}
function snowIE() {  // IE main animation function
for (i = 0; i < no; ++ i) {  // iterate for every dot
yp[i] += sty[i];
if (yp[i] > doc_height-50) {
xp[i] = Math.random()*(doc_width-am[i]-30);
yp[i] = 0;
stx[i] = 0.02 + Math.random()/10;
sty[i] = 0.7 + Math.random();
doc_width = doc_width_def;
doc_height = doc_height_def;
}
dx[i] += stx[i];
document.all["dot"+i].style.pixelTop = yp[i];
document.all["dot"+i].style.pixelLeft = xp[i] + am[i]*Math.sin(dx[i]);
}
setTimeout("snowIE()", speed);
}

function snowMZ() {  // Gecko main animation function
  for (i = 0; i < no; ++ i) {  // iterate for every dot
    yp[i] += sty[i];
    if (yp[i] > doc_height-50) {
      xp[i] = Math.random()*(doc_width-am[i]-30);
      yp[i] = 0;
      stx[i] = 0.02 + Math.random()/10;
      sty[i] = 0.7 + Math.random();
      doc_width = doc_width_def;
      doc_height = doc_height_def;
    }
    dx[i] += stx[i];
    document.getElementById("dot"+i).style.top = yp[i];
    document.getElementById("dot"+i).style.left = xp[i] + am[i]*Math.sin(dx[i]);
  }
  setTimeout("snowMZ()", speed);
}

if (ns4up) {
	snowNS();
} else
if (ie4up) {
	snowIE();
} else
if (gecko) {
	snowMZ();
} else
if (opera) {
	snowMZ();
}
