function getRandom(a){
  return (Math.round(Math.random()*100000) % a)
}
screen.bufferDepth = 16,
XSNOW={
  NCXP:0,NCXS:0,NHMIN:0,isStop:true,SPA:null,SH:0,SW:0,MT:0,
  NCXO:0,SX:0,L:0,H:0,HS:0,pS:0,mo:0,O:new Array(),P:new Array(),
  pS2:0,xm:0,ym:0,
  init:function(){
    try{
      XSNOW.PN=null;
      XSNOW.NCXP=0;
      XSNOW.NCXS=0;
      XSNOW.NHMIN=0;
      XSNOW.SPA=null;
      XSNOW.SH=200;
      XSNOW.SW=950;
      XSNOW.MT=170 //150;
      XSNOW.NCXO=60;
      XSNOW.L=0;
      XSNOW.H=0;
      XSNOW.HS=0;
      XSNOW.pS=4;
      XSNOW.mo=0;
      XSNOW.O=new Array();
      XSNOW.P=new Array();
      XSNOW.xm=0;
      XSNOW.ym=-10;   
    
      if(!XSNOW.isStop) return false
      XSNOW.pS2=XSNOW.pS / 2,
      XSNOW.SX=Math.round(XSNOW.SW / XSNOW.pS) - 1,
      XSNOW.xm=XSNOW.SW / 2,
  	  XSNOW.isStop=false
  	  XSNOW.SPA = document.getElementById("SNOW")
  	  if(XSNOW.SPA==null){
        var wSnow="<div id='SNOW' "
        wSnow+="style='position:absolute;top:0px;left:0px;background-color:transparent;overflow:hidden;z-Index:1000;'>"
        wSnow+="</div>";
        document.body.innerHTML=wSnow+document.body.innerHTML 
      }
      XSNOW.SPA = document.getElementById("SNOW")
    	XSNOW.resize()
    	for(j=0;j <= XSNOW.SX; j++) XSNOW.P[j] = new XSNOW.PXO(j)
      for(j=0;j<XSNOW.NCXO;j++){
      	XSNOW.O[j] = new XSNOW.CXO(j)
    		setTimeout("XSNOW.O["+j+"].run()",j * 200)
    	}
    }catch(e){}	  
	  
  },
  pereNoel:function(){
      this.le=XSNOW.SW;
      this.height=60;
      this.width=175;
    	var o = document.createElement("img")
    	o.src="/images/divers/Pere_Noel.gif";
    	this.PNS=o.style
  		this.PNS.position="absolute"
  		this.PNS.top=(XSNOW.MT-this.height+8)+"px";
  		this.PNS.width=this.width+"px";
  		this.PNS.height=this.height+"px";
  		this.PNS.left=this.le+"px";
  		this.PNS.background="transparent";
  		XSNOW.SPA.appendChild(o);
  },
  startPN:function(){
      if(XSNOW.PN==null) {XSNOW.PN=new XSNOW.pereNoel()}
      else{ XSNOW.PN.le=XSNOW.SW;XSNOW.PN.PNS.left=XSNOW.PN.le+"px";}
    	XSNOW.movePn()
  },
  movePn:function(){
    XSNOW.PN.le-=3
    var j=Math.round((XSNOW.PN.le+160) / XSNOW.pS) - 1
    if(j<=XSNOW.SX && j>=0) {
      XSNOW.P[j].cH=Math.max(XSNOW.P[j].cH,(XSNOW.MT+8))
      XSNOW.P[j].pH.top = (XSNOW.P[j].cH)+"px"
    }
    XSNOW.PN.PNS.left=XSNOW.PN.le+"px"
    if(XSNOW.PN.le>-175) setTimeout("XSNOW.movePn()",16)
    else                 setTimeout("XSNOW.fond()",1500)
  },
  fondOne:function(i){
      if(XSNOW.P[i].cH==XSNOW.SH-1) XSNOW.NHMIN++
      if(XSNOW.P[i].cH<XSNOW.SH){
        XSNOW.P[i].cH++ 
        XSNOW.P[i].pH.top = (XSNOW.P[i].cH)+"px"
      }
  },
  fond:function(){
    var wI=getRandom(Math.round(XSNOW.SW / XSNOW.pS))
    if(wI>1) {
      XSNOW.fondOne(wI-2)
    }
    if(wI>0) {
      XSNOW.fondOne(wI-1)
    }
    XSNOW.fondOne(wI)
    if(wI < XSNOW.SX) {
      XSNOW.fondOne(wI+1)
    }
    if(wI < XSNOW.SX-1) {
      XSNOW.fondOne(wI+2)
    }  
    if(XSNOW.NHMIN<=XSNOW.SX-40){
      setTimeout(XSNOW.fond,16)
    }else{
      XSNOW.stop()
      //XSNOW.start()
    } 
  },
  PXO:function(x){
  	try{
  		XSNOW.HS += 4 * Math.random() - 2
  		if(XSNOW.HS < 0) XSNOW.HS = 0
  		XSNOW.HS=Math.min(XSNOW.HS,0)
  		this.cH = Math.round(XSNOW.SH - XSNOW.pS - XSNOW.HS)
  		var o = document.createElement("span")
  		o.style.position="absolute"
  		o.style.background="#FFFFFF"
  		XSNOW.SPA.appendChild(o)
  		with(o.style){
  			top  = this.cH+"px";
  			left = (XSNOW.pS * x)+"px";
  			width = XSNOW.pS+"px";
  			height = XSNOW.SH+"px";
  		}
  		this.pH = o.style
  	}catch(e){}
  },
  CXO:function(N){
    try{
      this.pause=false;
    	this.N = N
    	var o = document.createElement("span")
    	o.style.position="absolute"
    	o.style.background="#FFFFFF"
    	XSNOW.SPA.appendChild(o)
    	with(o.style){
    		left = -100+"px"
    		width = XSNOW.pS+"px"
    		height = XSNOW.pS+"px"
    		fontSize = "1px"
    	}
    	this.setPause=function(){
    	  if(!this.pause) {
          XSNOW.NCXP++;
          if(XSNOW.NCXP>=(XSNOW.NCXO-10)) XSNOW.setAllPause()
        }
        this.pause=true;
      };
    	this.isPause=function(){
        var p=this.pause && (parseInt(o.style.top,10)<=0)
        if (p) XSNOW.NCXS++
        if(XSNOW.NCXS==XSNOW.NCXO) {/*Le dernier flocon est tombé*/ setTimeout('XSNOW.startPN()',1000)}
        return p
      
      };
    	this.pO = o.style
    	this.pX = Math.round((Math.random() * XSNOW.SW) / XSNOW.pS)
    	this.pY = 0
    	this.zX = Math.random() - .5
    	this.zY = -2
    	this.run = function (){
    		try{
    			with (this) {
    				try{
    					if(!this.isPause())
    					{
    						if (XSNOW.isStop) {return false}
    						x = Math.round(pX)
    						if (pY > XSNOW.P[x].cH - XSNOW.pS) {
    							if(x > 0 && XSNOW.P[x-1].cH > pY + XSNOW.pS){
    								pX--
    							} else if(x < XSNOW.SX && XSNOW.P[x+1].cH > pY + XSNOW.pS){
                    pX++
    							} else {
    								if(pY < XSNOW.P[x].cH+XSNOW.pS) {
    									XSNOW.P[x].cH -= XSNOW.pS / 2
    									if(x>0) {
    										if(XSNOW.P[x-1].cH > XSNOW.P[x].cH) {
    											XSNOW.P[x-1].cH -= XSNOW.pS / 4
    											XSNOW.P[x-1].pH.top = (XSNOW.P[x-1].cH)+"px"
    										} else XSNOW.P[x].cH -= XSNOW.pS / 4
    									}
    									if(x<XSNOW.SX) {
    										if(XSNOW.P[x+1].cH > XSNOW.P[x].cH) {
    											XSNOW.P[x+1].cH -= XSNOW.pS / 4
    											XSNOW.P[x+1].pH.top = (XSNOW.P[x+1].cH)+"px"
    										} else XSNOW.P[x].cH -= XSNOW.pS / 4
    									}
    									XSNOW.P[x].pH.top = (XSNOW.P[x].cH)+"px"
    								}
    								pX = Math.floor((Math.random() * XSNOW.SW) / XSNOW.pS)
    								pY = -XSNOW.pS
    								if(pY>XSNOW.P[x].cH)pY = -XSNOW.pS
    								zY = -10
    								zX = Math.random()-.5
    							}
    							if(parseInt(XSNOW.P[x].pH.top,10)<=XSNOW.MT) this.setPause()
    						} else {
    							pY += zY
    							if(zY < 1)zY += .05 * (90 - N)
    							pX += zX
    							zX *= .99
    							if(pX < 0)pX = 0; else if(pX > XSNOW.SX)pX = XSNOW.SX ;
    						}
    						pO.left = (pX * XSNOW.pS - XSNOW.pS2) +'px'
    						pO.top  = pY+"px"
    						setTimeout("XSNOW.O["+N+"].run()", 20)
    					}
    				}catch(e){}
    			}
    		}catch(e){}
    	}
    }catch(e){}
  },
  setAllPause:function(){
    for (var i=0;i<XSNOW.NCXO;i++){
      XSNOW.O[i].pause=true
    }
    XSNOW.NCXP=XSNOW.NCXO;
  },
  resize:function(){
    try{
      if(XSNOW.SPA!=undefined && XSNOW.SPA!=null){
    		with(XSNOW.SPA.style){
    			XSNOW.L = left = (Math.round(-1+(document.body.offsetWidth - XSNOW.SW) / 2))+"px";
    			XSNOW.H = top  = 0+"px" //Math.round(-1+(document.body.offsetHeight - SH) / 2)
    			width    = XSNOW.SW+"px"
     			height   = XSNOW.SH+"px"
  	 	 }
  	 	}
  	}catch(e){}
  },
  start:function(){
    if(!XSNOW.isStop) return false
    var d=new Date()
    var wM=d.getMonth()
    var wD=d.getDate()
    if((wM==11 && wD>=15) || (wM==0 && wD<=10)){
	     setTimeout(XSNOW.init,1000) 
	  }
  },
  stop:function(){
    XSNOW.isStop=true
    document.getElementById("SNOW").innerHTML=""
  },
  pause:function(){
    isPause=true
  }
}