// erstellt von info@marion-schoelzel.de
// Schneeflocken

var timerIDflocke = 0;

var anzFlocken;
var mausxalt = 0;
var mausyalt = 0;
var mausxneu = 0;
var mausyneu = 0;
var mausx;
var mausy;

function schneeflocken(resize) {
   if (resize) {
      if (timerIDflocke) clearInterval(timerIDflocke);
   }
   browser();
   initPosFlocke();
   initMouseMove();
   schriftgroesse = 30;
   for (i = 1; i <= anzFlocken; i++) {
      posy[i] = - (Math.random() * fh);
      posx[i] = (Math.random() * fb) - 55;
      initFlocke(i);
      schneeflocke.left = getPos(posx[i]);
      schneeflocke.top = getPos(posy[i]);
      if (i > 20) schriftgroesse = i/2 + 30;
      schneeflocke.fontSize = getPos(schriftgroesse);
   }
   timerIDflocke = setInterval("BewFlocken()", 55);
}

function BewFlocken() {
   for (i = 1; i <= anzFlocken; i++) {
      if (mausxneu || mausyneu) {
         if (mausxneu > 10) mausxneu = 10;
         if (mausxneu < - 10) mausxneu = - 10;
         if (mausyneu < 1) mausyneu = 1;
         if (mausyneu > 8) mausyneu = 8;
         posx[i] = posx[i] + (mausxneu * Math.random());
         posy[i] = posy[i] + 1 + (mausyneu * Math.random());
      }
      else  {
         posx[i] = posx[i] - Math.random();
         posy[i] = posy[i] + (Math.random() * 3);
      }
      if ((posx[i] > fb - 55) || (posx[i] < 0) || (posy[i] > fh - 55)) {
         posy[i] = - (Math.random() * 55);
         posx[i] = (Math.random() * fb) - 55;
      }
      initFlocke(i);
      schneeflocke.top = getPos(posy[i]);
      schneeflocke.left = getPos(posx[i]);
   }
   if (mausxneu > 0) mausxneu = mausxneu - 0.1;
   if (mausyneu > 0) mausyneu = mausyneu - 0.1;
   if (mausxneu < 0) mausxneu = mausxneu + 0.1;
   if (mausyneu < 0) mausyneu = mausyneu + 0.1;
}

function initLayerFlocke() {
   browser();
   anzFlocken = 40;
   if (fb <= 800) anzFlocken = 30;
   if (fb <= 600) anzFlocken = 25;
   for(i = 1; i <= anzFlocken; i++) {
      document.write("<div id='floeckchen"+i+"' class='flocke'>");
      document.write("*");
      document.write("</div>");
   }
}

function initFlocke(nummer) {
   if (ns) {schneeflocke = eval("document.floeckchen" + nummer); return;}
   if (ie) {schneeflocke = eval("floeckchen" + nummer + ".style"); return;}
   if (dom) {schneeflocke = eval("document.getElementById('floeckchen"+ nummer +"').style"); return;}
}

function initPosFlocke() {
   posx = new Array();
   for (i = 1; i <= anzFlocken; i++) {
      posx[i] = -55;
   }
   posy = new Array();
   for (i = 1; i <= anzFlocken; i++) {
      posy[i] = -55;
   }
}

function MausMove(e) {
   if (!e) e = window.event;
   mausx = e.pageX ? e.pageX : event.x + document.body.scrollLeft;
   mausy = e.pageY ? e.pageY : event.y + document.body.scrollTop;
   mausxneu = mausx - mausxalt;
   mausyneu = mausy - mausyalt;
   mausxalt = mausx;
   mausyalt = mausy;
}

function initMouseMove() {
   if (document.addEventListener) {
      document.addEventListener("mousemove", MausMove, true);
   } else {
      if (document.layers) {
         document.captureEvents(Event.MOUSEMOVE);
      }
      document.onmousemove = MausMove;
   }
}