﻿// JavaScript Document
// Script écrit par Altan. Visitez son site!
// Modif par WF-SIP  novembre 2010

var doc_width ;
var doc_height ;
if( typeof( window.innerWidth ) == 'number' ) {
  doc_width = window.innerWidth;
  doc_height = window.innerHeight;
  }
else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
  doc_width = document.documentElement.clientWidth;
  doc_height = document.documentElement.clientHeight;
  }
else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
  doc_width = document.body.clientWidth;
  doc_height = document.body.clientHeight;
  }

var mtop ; // marge top
var mlef ; // marge gauche
var mbot ; // limite basse
var larg ; // largeur de mon anim

// Fin Modif  

// Réglages et déclaration des variables
var no = 15 ; // nombre de flocons à tomber
var speed = 50; // Vitesse ou tombe les flocons

var dx, xp, yp; // Coordonnées de positionnement
var am, stx, sty; // amplitude and step variables

dx = new Array();  // tableau des coordonnées en largeur
xp = new Array();  // tableau des coordonnées en largeur
yp = new Array();  // tableau des coordonnées en hauteur
am = new Array();  // tableau des coordonnées 
stx = new Array(); // tableau des coordonnées 
sty = new Array(); // tableau des coordonnées 
var i=0; 

mtop = 340 ;
mlef = (doc_width-968)/2 ;
mbot = 660 ;
larg = 380 ;

// creation des flocons dans des div
for (i = 0; i < no ; ++ i) {

	 // définition coordonnées en largeur
	 dx[i] = Math.floor(Math.random() * (mlef+larg) ) + 20 ;
	if ( dx[i] > (mlef + larg) ) { dx[i] = dx[i] - (larg +5 )};
	if ( dx[i] < mlef) { dx[i] = mlef + 10 };
	
	yp[i] =  (Math.random()*200) + mtop ;  // définition de la position en hauteur
	
	am[i] = Math.random()*1 ;
	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; opacity:0.80 ; filter:alpha(opacity=80); Z-INDEX: 50; ");
		document.write("VISIBILITY: visible; color:#fff; width: 0px; float: left; \"> &bull; </div>"); 
	} else {
		document.write("<div id=\"dot"+ i +"\" style=\"POSITION:absolute; opacity:0.80 ; filter:alpha(opacity=80); Z-INDEX: 50; ");
		document.write("VISIBILITY: visible; color:#fff; width: 10px; float: left;  \"> <img   style='width:0px;'> &bull; </div>");
 	} 
}
//  fin creation des div


function snow() { 
	for (i = 0; i < no; ++ i) {
		
		//deplacement vertical
		sty[i] = 0.2 + Math.random()*3;
		yp[i] += sty[i] ;

		//deplacement horizontal
		stx[i] =    0.08 + Math.random()/10 ;
		dx[i]  += stx[i] + am[i]*Math.sin(dx[i]) ;

		test=Math.floor(Math.random()*1000) ;

		//tant que dans la page

		//if (yp[i] < 600 && test>1) {
		if (yp[i] < mbot && test>1) {
			document.getElementById("dot"+i).style.top = Math.floor(yp[i])+"px" ;
			if (dx[i] < doc_width - 5) document.getElementById("dot"+i).style.left = dx[i]+"px" ;
			} else { //sinon on le remet en haut
				// yp[i]= 0 ;
				yp[i]= mtop ;
				dx[i] = mlef + Math.floor(Math.random() * larg) + 5 ;
			}
		}
		setTimeout("snow()", speed);
	}

snow();

