/* Creo l'effetto della nevicata per SAFARI e CROME con il CSS3 */
function snow() {
	var space = document.getElementById('snow');
	const STYLE_TAG = "left: P_LEFTpx; -webkit-animation-duration: P_TIMEs; -webkit-animation-delay: P_DELAYs;";
	const INNER_TAG = "-webkit-animation-duration: P_TIMEs; opacity:P_ALPHA; height:P_HEIGHTpx; width:P_WIDTHpx;-webkit-border-radius:P_BORDERpx"
	var el, inner, str, size;
	var elArray = [];

	/* è molto interessante notare che non uso più il SetTimout per le animazioni
	 * ma stampo una serie di movimenti con il CSS3 che poi ci penserà lui a eseguirli */
	for (var i = 0; i < 250; i++) {
		// Create parent element
		el = document.createElement('div');
		el.setAttribute('class', 'snow');
		str = STYLE_TAG.replace(/P_LEFT/, Math.round((Math.random()*2400)-600).toString()); // 1600 è il range del left della nevicata.
		str = str.replace(/P_TIME/, (Math.random()*4 + 4).toString());
		str = str.replace(/P_DELAY/, (Math.random()*8).toString());
		el.setAttribute('style', str);

		// Create inner element
		inner = document.createElement('div');
		inner.setAttribute('class', 'inner');	
		str = INNER_TAG.replace(/P_TIME/, (Math.random()*2 + 1).toString());	
		str = str.replace(/P_ALPHA/, (Math.random()*0.9+0.1).toString());
		size = (Math.random()*6+1).toString();
		str = str.replace(/P_HEIGHT|P_WIDTH/g, size);
		str = str.replace(/P_BORDER/, size/2);
		inner.setAttribute('style', str);
		el.appendChild(inner);

		elArray.push(el);
		space.appendChild(el)
	}
}
