﻿// Skript für Schnnefall

/* Achtung! das Skript nutz jQuery-Funktionalität */

/*  Beispielaufruf der Funktionen
		$(document).ready(function(){
			snow();
			if (hidesnowtime>0){
				setTimeout("hidesnow()", hidesnowtime*1000);
				}
			});
*/


//Configure below to change URL path to the snow image
var snowsrc="./lib/snow.gif"
// Configure below to change number of snow to render
var no = 5;
// Configure whether snow should disappear after x seconds (0=never):
var hidesnowtime = 0;

var dx, xp, yp;    // coordinate and position variables
var am, stx, sty;  // amplitude and step variables
var i

var window_width = $(window).width();
var window_height = $(window).height();

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()*(window_width-50);  // set position variables
				yp[i] = Math.random()*window_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 (i == 0) {
					document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"><img src='"+snowsrc+"' border=\"0\"><\/div>");
				} else {
					document.write("<div id=\"dot"+ i +"\" style=\"POSITION: absolute; Z-INDEX: "+ i +"; VISIBILITY: visible; TOP: 15px; LEFT: 15px;\"><img src='"+snowsrc+"' border=\"0\"><\/div>");
				}
				
}

function snow() {  
	window_width = $(window).width();
	window_height= $(window).height();
	for (i = 0; i < no; ++ i) {  // iterate for every dot
		yp[i] += sty[i];
		if (yp[i] > window_height-30) {
			xp[i] = Math.random()*(window_width-am[i]-30);
			yp[i] = 0;
			stx[i] = 0.02 + Math.random()/10;
			sty[i] = 0.7 + Math.random();
		}
		dx[i] += stx[i];
		document.getElementById("dot"+i).style.top=yp[i]+"px";
		document.getElementById("dot"+i).style.left=xp[i] + am[i]*Math.sin(dx[i])+"px";  
	}
	snowtimer=setTimeout("snow()", 15);
}

function hidesnow(){
	if (window.snowtimer) clearTimeout(snowtimer)
	for (i=0; i<no; i++) document.getElementById("dot"+i).style.visibility="hidden"
}



