// do not load in body tag with onload!!
// start with
// <script type="text/javascript" language="JavaScript" src="/snow/snow.js"></script>
// in the last line before </body>
// Configure below to change number of snow to render
var snow_src="";
var snow_no = 15;                 // number of flakes
var snow_dx, snow_xp, snow_yp;    // coordinate and position variables
var snow_am, snow_stx, snow_sty;  // amplitude and step variables
var doc_width = 800, doc_height = 600;

if(document.getElementById || document.layers || document.all) { //only if DHTML
  start_snow();
}

function select_snow(w){
   // needs var snow_source = ""; in parent of page
   parent.snow_source=w;
   location.reload();
}


function get_width_height() {
  if (window.innerWidth){
    doc_width = self.innerWidth;
    doc_height = self.innerHeight;
  }else if(window.document.body){ //IE4
    doc_width = window.document.body.clientWidth;
    doc_height = window.document.body.clientHeight;
  }
}
function start_snow() {
  var dd = new Date();
  //var dd = new Date("1970",2-1,"13");  //debug - allways from 1970!!
  var m = dd.getMonth()+1;
  var d = dd.getDate();
  if(m==10 || m==11){
    if (d/2==Math.floor(d/2)){ //wenn gerader tag
      snow_src="/snow/blatt.gif";
    }else{
      snow_src="/snow/blatt1.gif";
    }
  }
  if(m==12){ //(dec)
    snow_src="/snow/snow.gif";
  }
  if(m==1 || m==2){ //(jan and feb)
    if (d/2==Math.floor(d/2)){ //wenn gerader tag
      snow_src="/snow/snow.gif";
    }else{
      snow_src="/snow/regen.gif";
    }
  }
/*
  if(m==3){
    if (d/2==Math.floor(d/2)){ //wenn gerader tag
      snow_src="/snow/konfetti1.gif";
    }else{
      snow_src="/snow/konfetti2.gif";
    }
  }
*/
  if(m==4){ //(april)
    snow_src="/snow/osterei.gif";
  }
  if(parent){    //wenn im parent ein bild festgelegt
    if(parent.snow_source){
      snow_src=parent.snow_source;
    }
  }
  if(snow_src != "" ){
    start_snow1();
  }
}
function start_snow1() {
  var i

  snow_dx = new Array();
  snow_xp = new Array();
  snow_yp = new Array();
  snow_am = new Array();
  snow_stx = new Array();
  snow_sty = new Array();

  get_width_height();
  for (i = 0; i < snow_no; ++ i) {
    snow_dx[i] = 0;                        // set coordinate variables
    snow_xp[i] = Math.random()*(doc_width-50);  // set position variables
    snow_yp[i] = Math.random()*doc_height;
    snow_am[i] = Math.random()*20;         // set amplitude variables
    snow_stx[i] = 0.02 + Math.random()/10; // set step variables
    snow_sty[i] = 0.7 + Math.random();     // set step variables
    if (document.layers) {                 // set layers
      document.write("<layer name=\"dot"+ i +"\" left=\"15\" top=\"15\" visibility=\"show\"><img src='"+snow_src+"' border=\"0\"></layer>");
    } else {
      document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"><img src='"+snow_src+"' border=\"0\"></div>");
    }
  }
  snow();
}
function snow() {  // main animation function
  var i
  for (i = 0; i < snow_no; ++ i) {  // iterate for every dot
    snow_yp[i] += snow_sty[i];
    if (snow_yp[i] > doc_height-50) {
      snow_xp[i] = Math.random()*(doc_width-snow_am[i]-30);
      snow_yp[i] = 0;
      snow_stx[i] = 0.02 + Math.random()/10;
      snow_sty[i] = 0.7 + Math.random();
      get_width_height();
    }
    snow_dx[i] += snow_stx[i];
    if (document.getElementById) {
      document.getElementById("dot"+i).style.top = snow_yp[i];
      document.getElementById("dot"+i).style.left = snow_xp[i] + snow_am[i]*Math.sin(snow_dx[i]);
    } else if (document.layers) {
      document.layers["dot"+i].top = snow_yp[i];
      document.layers["dot"+i].left = snow_xp[i] + snow_am[i]*Math.sin(snow_dx[i]);
    } else if (document.all) {
      document.all["dot"+i].style.pixelTop = snow_yp[i];
      document.all["dot"+i].style.pixelLeft = snow_xp[i] + snow_am[i]*Math.sin(snow_dx[i]);
    }
  }
  setTimeout("snow()", 20);
}