var on_off = 1;
var no = 5;	// 16
var speed = 40;
var snowflake = "pic/starbl.gif";	// "pic/vlocka5.gif";

var ns4up = (document.layers) ? 1 : 0;
var ie4up = (document.all) ? 1 : 0;
var dx, xp, yp, am, stx, sty;
var i, doc_width = 770, doc_height = 100;
if (ns4up) { doc_width = self.innerWidth-150; doc_height = self.innerHeight-50; }


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;
  xp[i] = 50 + Math.random()*(doc_width-50);
  yp[i] = 13 + Math.random()*doc_height;
  am[i] = Math.random()*20;
  stx[i] = 0.02 + Math.random()/10;
  sty[i] = 0.7 + Math.random();
  if (ns4up) {
    document.write("<layer name=\"dot"+ i +"\" left=15 top=15 visibility=\"show\"><img src=\"" + snowflake + "\" 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=\"" + snowflake + "\" border=0></div>");
    }
  }

function snowNS() {
  for (i = 0; i < no; ++ i) {
    yp[i] += sty[i];
    if (yp[i] > doc_height-50) {
      xp[i] = Math.random()*(doc_width-am[i]-30);
      yp[i] = 13;
      stx[i] = 0.02 + Math.random()/10;
      sty[i] = 0.7 + Math.random();
      doc_width = self.innerWidth;
      doc_height = 115; // self.innerHeight;
    }
    dx[i] += stx[i];
    if (on_off == 0) {
      document.layers["dot"+i].top = 20;
      document.layers["dot"+i].left = 20;
      }
    else {
      document.layers["dot"+i].top = yp[i];
      document.layers["dot"+i].left = xp[i] + am[i]*Math.sin(dx[i]);
      }
  }
  if (on_off == 1) setTimeout("snowNS()", speed); else setTimeout("snowNS()", 1000);
}

function snowIE() {

  if (document.body.clientWidth <= 770) { doc_width = document.body.clientWidth; x_offset = 0; }
  else { doc_width = 770; x_offset = (document.body.clientWidth - 770)/2; }

  for (i = 0; i < no; ++ i) {
    yp[i] += sty[i];
    if (yp[i] > doc_height-50) {
      xp[i] = x_offset + Math.random()*(doc_width-am[i]-30);
      yp[i] = 13;
      stx[i] = 0.02 + Math.random()/10;
      sty[i] = 0.7 + Math.random();
			// document.body.clientWidth;
      doc_height = 115; // document.body.clientHeight;
    }
    dx[i] += stx[i];
    if (on_off == 0) {
      document.all["dot"+i].style.pixelTop = 20;
      document.all["dot"+i].style.pixelLeft = 20;
      }
    else {
      document.all["dot"+i].style.pixelTop = yp[i];
      document.all["dot"+i].style.pixelLeft = xp[i] + am[i]*Math.sin(dx[i]);
      }
  }
  if (on_off == 1) setTimeout("snowIE()", speed); else setTimeout("snowIE()", 1000);
}

function zmena() {
  if (on_off == 0) { on_off = 1; return; }
  if (on_off == 1) { on_off = 0; return; }
  }

// if (ns4up) { setTimeout("snowNS", 5000); } else if (ie4up) { setTimeout("snowIE", 5000); }
if (ns4up) { snowNS(); } else if (ie4up) { snowIE(); }
