ÿþ/ * *   @ l i c e n s e  
   *   D H T M L   S n o w s t o r m !   J a v a S c r i p t - b a s e d   S n o w   f o r   w e b   p a g e s  
   *   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
   *   V e r s i o n   1 . 4 1 . 2 0 1 0 1 1 1 3   ( P r e v i o u s   r e v :   1 . 4 . 2 0 0 9 1 1 1 5 )  
   *   C o p y r i g h t   ( c )   2 0 0 7 ,   S c o t t   S c h i l l e r .   A l l   r i g h t s   r e s e r v e d .  
   *   C o d e   p r o v i d e d   u n d e r   t h e   B S D   L i c e n s e :  
   *   h t t p : / / s c h i l l m a n i a . c o m / p r o j e c t s / s n o w s t o r m / l i c e n s e . t x t  
   * /  
  
 / * g l o b a l   w i n d o w ,   d o c u m e n t ,   n a v i g a t o r ,   c l e a r I n t e r v a l ,   s e t I n t e r v a l   * /  
 / * j s l i n t   w h i t e :   f a l s e ,   o n e v a r :   t r u e ,   p l u s p l u s :   f a l s e ,   u n d e f :   t r u e ,   n o m e n :   t r u e ,   e q e q e q :   t r u e ,   b i t w i s e :   t r u e ,   r e g e x p :   t r u e ,   n e w c a p :   t r u e ,   i m m e d :   t r u e   * /  
  
 v a r   s n o w S t o r m   =   ( f u n c t i o n ( w i n d o w ,   d o c u m e n t )   {  
  
     / /   - - -   c o m m o n   p r o p e r t i e s   - - -  
  
     t h i s . f l a k e s M a x   =   2 5 6 ;                       / /   L i m i t   t o t a l   a m o u n t   o f   s n o w   m a d e   ( f a l l i n g   +   s t i c k i n g )  
     t h i s . f l a k e s M a x A c t i v e   =   1 2 8 ;             / /   L i m i t   a m o u n t   o f   s n o w   f a l l i n g   a t   o n c e   ( l e s s   =   l o w e r   C P U   u s e )  
     t h i s . a n i m a t i o n I n t e r v a l   =   5 0 ;         / /   T h e o r e t i c a l   " m i l i s e c o n d s   p e r   f r a m e "   m e a s u r e m e n t .   2 0   =   f a s t   +   s m o o t h ,   b u t   h i g h   C P U   u s e .   5 0   =   m o r e   c o n s e r v a t i v e ,   b u t   s l o w e r  
     t h i s . e x c l u d e M o b i l e   =   t r u e ;             / /   S n o w   i s   l i k e l y   t o   b e   b a d   n e w s   f o r   m o b i l e   p h o n e s '   C P U s   ( a n d   b a t t e r i e s . )   B y   d e f a u l t ,   b e   n i c e .  
     t h i s . f l a k e B o t t o m   =   n u l l ;                 / /   I n t e g e r   f o r   Y   a x i s   s n o w   l i m i t ,   0   o r   n u l l   f o r   " f u l l - s c r e e n "   s n o w   e f f e c t  
     t h i s . f o l l o w M o u s e   =   t r u e ;                 / /   S n o w   m o v e m e n t   c a n   r e s p o n d   t o   t h e   u s e r ' s   m o u s e  
     t h i s . s n o w C o l o r   =   ' # f f f ' ;                 / /   D o n ' t   e a t   ( o r   u s e ? )   y e l l o w   s n o w .  
     t h i s . s n o w C h a r a c t e r   =   ' I'' ;             / /   & b u l l ;   =   b u l l e t ,   & m i d d o t ;   i s   s q u a r e   o n   s o m e   s y s t e m s   e t c .  
     t h i s . s n o w S t i c k   =   t r u e ;                     / /   W h e t h e r   o r   n o t   s n o w   s h o u l d   " s t i c k "   a t   t h e   b o t t o m .   W h e n   o f f ,   w i l l   n e v e r   c o l l e c t .  
     t h i s . t a r g e t E l e m e n t   =   n u l l ;             / /   e l e m e n t   w h i c h   s n o w   w i l l   b e   a p p e n d e d   t o   ( n u l l   =   d o c u m e n t . b o d y )   -   c a n   b e   a n   e l e m e n t   I D   e g .   ' m y D i v ' ,   o r   a   D O M   n o d e   r e f e r e n c e  
     t h i s . u s e M e l t E f f e c t   =   t r u e ;             / /   W h e n   r e c y c l i n g   f a l l e n   s n o w   ( o r   r a r e l y ,   w h e n   f a l l i n g ) ,   h a v e   i t   " m e l t "   a n d   f a d e   o u t   i f   b r o w s e r   s u p p o r t s   i t  
     t h i s . u s e T w i n k l e E f f e c t   =   f a l s e ;     / /   A l l o w   s n o w   t o   r a n d o m l y   " f l i c k e r "   i n   a n d   o u t   o f   v i e w   w h i l e   f a l l i n g  
     t h i s . u s e P o s i t i o n F i x e d   =   f a l s e ;     / /   t r u e   =   s n o w   d o e s   n o t   s h i f t   v e r t i c a l l y   w h e n   s c r o l l i n g .   M a y   i n c r e a s e   C P U   l o a d ,   d i s a b l e d   b y   d e f a u l t   -   i f   e n a b l e d ,   u s e d   o n l y   w h e r e   s u p p o r t e d  
  
     / /   - - -   l e s s - u s e d   b i t s   - - -  
  
     t h i s . f r e e z e O n B l u r   =   t r u e ;               / /   O n l y   s n o w   w h e n   t h e   w i n d o w   i s   i n   f o c u s   ( f o r e g r o u n d . )   S a v e s   C P U .  
     t h i s . f l a k e L e f t O f f s e t   =   0 ;               / /   L e f t   m a r g i n / g u t t e r   s p a c e   o n   e d g e   o f   c o n t a i n e r   ( e g .   b r o w s e r   w i n d o w . )   B u m p   u p   t h e s e   v a l u e s   i f   s e e i n g   h o r i z o n t a l   s c r o l l b a r s .  
     t h i s . f l a k e R i g h t O f f s e t   =   0 ;             / /   R i g h t   m a r g i n / g u t t e r   s p a c e   o n   e d g e   o f   c o n t a i n e r  
     t h i s . f l a k e W i d t h   =   2 8 ;                         / /   M a x   p i x e l   w i d t h   r e s e r v e d   f o r   s n o w   e l e m e n t  
     t h i s . f l a k e H e i g h t   =   2 8 ;                       / /   M a x   p i x e l   h e i g h t   r e s e r v e d   f o r   s n o w   e l e m e n t  
     t h i s . v M a x X   =   5 ;                                   / /   M a x i m u m   X   v e l o c i t y   r a n g e   f o r   s n o w  
     t h i s . v M a x Y   =   4 ;                                   / /   M a x i m u m   Y   v e l o c i t y   r a n g e   f o r   s n o w  
     t h i s . z I n d e x   =   0 ;                                 / /   C S S   s t a c k i n g   o r d e r   a p p l i e d   t o   e a c h   s n o w f l a k e  
  
     / /   - - -   E n d   o f   u s e r   s e c t i o n   - - -  
  
     v a r   s   =   t h i s ,   s t o r m   =   t h i s ,   i ,  
     / /   U A   s n i f f i n g   a n d   b a c k C o m p a t   r e n d e r i n g   m o d e   c h e c k s   f o r   f i x e d   p o s i t i o n ,   e t c .  
     i s I E   =   n a v i g a t o r . u s e r A g e n t . m a t c h ( / m s i e / i ) ,  
     i s I E 6   =   n a v i g a t o r . u s e r A g e n t . m a t c h ( / m s i e   6 / i ) ,  
     i s W i n 9 8   =   n a v i g a t o r . a p p V e r s i o n . m a t c h ( / w i n d o w s   9 8 / i ) ,  
     i s M o b i l e   =   n a v i g a t o r . u s e r A g e n t . m a t c h ( / m o b i l e / i ) ,  
     i s B a c k C o m p a t I E   =   ( i s I E   & &   d o c u m e n t . c o m p a t M o d e   = = =   ' B a c k C o m p a t ' ) ,  
     n o F i x e d   =   ( i s M o b i l e   | |   i s B a c k C o m p a t I E   | |   i s I E 6 ) ,  
     s c r e e n X   =   n u l l ,   s c r e e n X 2   =   n u l l ,   s c r e e n Y   =   n u l l ,   s c r o l l Y   =   n u l l ,   v R n d X   =   n u l l ,   v R n d Y   =   n u l l ,  
     w i n d O f f s e t   =   1 ,  
     w i n d M u l t i p l i e r   =   2 ,  
     f l a k e T y p e s   =   6 ,  
     f i x e d F o r E v e r y t h i n g   =   f a l s e ,  
     o p a c i t y S u p p o r t e d   =   ( f u n c t i o n ( ) {  
         t r y   {  
             d o c u m e n t . c r e a t e E l e m e n t ( ' d i v ' ) . s t y l e . o p a c i t y   =   ' 0 . 5 ' ;  
         }   c a t c h ( e )   {  
             r e t u r n   f a l s e ;  
         }  
         r e t u r n   t r u e ;  
     } ( ) ) ,  
     d i d I n i t   =   f a l s e ,  
     d o c F r a g   =   d o c u m e n t . c r e a t e D o c u m e n t F r a g m e n t ( ) ;  
  
     t h i s . t i m e r s   =   [ ] ;  
     t h i s . f l a k e s   =   [ ] ;  
     t h i s . d i s a b l e d   =   f a l s e ;  
     t h i s . a c t i v e   =   f a l s e ;  
     t h i s . m e l t F r a m e C o u n t   =   2 0 ;  
     t h i s . m e l t F r a m e s   =   [ ] ;  
  
     t h i s . e v e n t s   =   ( f u n c t i o n ( )   {  
  
         v a r   o l d   =   ( w i n d o w . a t t a c h E v e n t ) ,   s l i c e   =   A r r a y . p r o t o t y p e . s l i c e ,  
         e v t   =   {  
             a d d :   ( o l d ? ' a t t a c h E v e n t ' : ' a d d E v e n t L i s t e n e r ' ) ,  
             r e m o v e :   ( o l d ? ' d e t a c h E v e n t ' : ' r e m o v e E v e n t L i s t e n e r ' )  
         } ;  
  
         f u n c t i o n   g e t A r g s ( o A r g s )   {  
             v a r   a r g s   =   s l i c e . c a l l ( o A r g s ) ,   l e n   =   a r g s . l e n g t h ;  
             i f   ( o l d )   {  
                 a r g s [ 1 ]   =   ' o n '   +   a r g s [ 1 ] ;   / /   p r e f i x  
                 i f   ( l e n   >   3 )   {  
                     a r g s . p o p ( ) ;   / /   n o   c a p t u r e  
                 }  
             }   e l s e   i f   ( l e n   = = =   3 )   {  
                 a r g s . p u s h ( f a l s e ) ;  
             }  
             r e t u r n   a r g s ;  
         }  
  
         f u n c t i o n   a p p l y ( a r g s ,   s T y p e )   {  
             v a r   o F u n c   =   a r g s . s h i f t ( ) [ e v t [ s T y p e ] ] ;  
             i f   ( o l d )   {  
                 o F u n c ( a r g s [ 0 ] ,   a r g s [ 1 ] ) ;  
             }   e l s e   {  
                 o F u n c . a p p l y ( t h i s ,   a r g s ) ;  
             }  
         }  
  
         f u n c t i o n   a d d E v e n t ( )   {  
             a p p l y ( g e t A r g s ( a r g u m e n t s ) ,   ' a d d ' ) ;  
         }  
  
         f u n c t i o n   r e m o v e E v e n t ( )   {  
             a p p l y ( g e t A r g s ( a r g u m e n t s ) ,   ' r e m o v e ' ) ;  
         }  
  
         r e t u r n   {  
             a d d :   a d d E v e n t ,  
             r e m o v e :   r e m o v e E v e n t  
         } ;  
  
     } ( ) ) ;  
  
     f u n c t i o n   r n d ( n , m i n )   {  
         i f   ( i s N a N ( m i n ) )   {  
             m i n   =   0 ;  
         }  
         r e t u r n   ( M a t h . r a n d o m ( ) * n ) + m i n ;  
     }  
  
     f u n c t i o n   p l u s M i n u s ( n )   {  
         r e t u r n   ( p a r s e I n t ( r n d ( 2 ) , 1 0 ) = = = 1 ? n * - 1 : n ) ;  
     }  
  
     t h i s . r a n d o m i z e W i n d   =   f u n c t i o n ( )   {  
         v R n d X   =   p l u s M i n u s ( r n d ( s . v M a x X , 0 . 2 ) ) ;  
         v R n d Y   =   r n d ( s . v M a x Y , 0 . 2 ) ;  
         i f   ( t h i s . f l a k e s )   {  
             f o r   ( v a r   i = 0 ;   i < t h i s . f l a k e s . l e n g t h ;   i + + )   {  
                 i f   ( t h i s . f l a k e s [ i ] . a c t i v e )   {  
                     t h i s . f l a k e s [ i ] . s e t V e l o c i t i e s ( ) ;  
                 }  
             }  
         }  
     } ;  
  
     t h i s . s c r o l l H a n d l e r   =   f u n c t i o n ( )   {  
         / /   " a t t a c h "   s n o w f l a k e s   t o   b o t t o m   o f   w i n d o w   i f   n o   a b s o l u t e   b o t t o m   v a l u e   w a s   g i v e n  
         s c r o l l Y   =   ( s . f l a k e B o t t o m ? 0 : p a r s e I n t ( w i n d o w . s c r o l l Y | | d o c u m e n t . d o c u m e n t E l e m e n t . s c r o l l T o p | | d o c u m e n t . b o d y . s c r o l l T o p , 1 0 ) ) ;  
         i f   ( i s N a N ( s c r o l l Y ) )   {  
             s c r o l l Y   =   0 ;   / /   N e t s c a p e   6   s c r o l l   f i x  
         }  
         i f   ( ! f i x e d F o r E v e r y t h i n g   & &   ! s . f l a k e B o t t o m   & &   s . f l a k e s )   {  
             f o r   ( v a r   i = s . f l a k e s . l e n g t h ;   i - - ; )   {  
                 i f   ( s . f l a k e s [ i ] . a c t i v e   = = =   0 )   {  
                     s . f l a k e s [ i ] . s t i c k ( ) ;  
                 }  
             }  
         }  
     } ;  
  
     t h i s . r e s i z e H a n d l e r   =   f u n c t i o n ( )   {  
         i f   ( w i n d o w . i n n e r W i d t h   | |   w i n d o w . i n n e r H e i g h t )   {  
             s c r e e n X   =   w i n d o w . i n n e r W i d t h - ( ! i s I E ? 1 6 : 2 ) - s . f l a k e R i g h t O f f s e t ;  
             s c r e e n Y   =   ( s . f l a k e B o t t o m ? s . f l a k e B o t t o m : w i n d o w . i n n e r H e i g h t ) ;  
         }   e l s e   {  
             s c r e e n X   =   ( d o c u m e n t . d o c u m e n t E l e m e n t . c l i e n t W i d t h | | d o c u m e n t . b o d y . c l i e n t W i d t h | | d o c u m e n t . b o d y . s c r o l l W i d t h ) - ( ! i s I E ? 8 : 0 ) - s . f l a k e R i g h t O f f s e t ;  
             s c r e e n Y   =   s . f l a k e B o t t o m ? s . f l a k e B o t t o m : ( d o c u m e n t . d o c u m e n t E l e m e n t . c l i e n t H e i g h t | | d o c u m e n t . b o d y . c l i e n t H e i g h t | | d o c u m e n t . b o d y . s c r o l l H e i g h t ) ;  
         }  
         s c r e e n X 2   =   p a r s e I n t ( s c r e e n X / 2 , 1 0 ) ;  
     } ;  
  
     t h i s . r e s i z e H a n d l e r A l t   =   f u n c t i o n ( )   {  
         s c r e e n X   =   s . t a r g e t E l e m e n t . o f f s e t L e f t + s . t a r g e t E l e m e n t . o f f s e t W i d t h - s . f l a k e R i g h t O f f s e t ;  
         s c r e e n Y   =   s . f l a k e B o t t o m ? s . f l a k e B o t t o m : s . t a r g e t E l e m e n t . o f f s e t T o p + s . t a r g e t E l e m e n t . o f f s e t H e i g h t ;  
         s c r e e n X 2   =   p a r s e I n t ( s c r e e n X / 2 , 1 0 ) ;  
     } ;  
  
     t h i s . f r e e z e   =   f u n c t i o n ( )   {  
         / /   p a u s e   a n i m a t i o n  
         i f   ( ! s . d i s a b l e d )   {  
             s . d i s a b l e d   =   1 ;  
         }   e l s e   {  
             r e t u r n   f a l s e ;  
         }  
         f o r   ( v a r   i = s . t i m e r s . l e n g t h ;   i - - ; )   {  
             c l e a r I n t e r v a l ( s . t i m e r s [ i ] ) ;  
         }  
     } ;  
  
     t h i s . r e s u m e   =   f u n c t i o n ( )   {  
         i f   ( s . d i s a b l e d )   {  
               s . d i s a b l e d   =   0 ;  
         }   e l s e   {  
             r e t u r n   f a l s e ;  
         }  
         s . t i m e r I n i t ( ) ;  
     } ;  
  
     t h i s . t o g g l e S n o w   =   f u n c t i o n ( )   {  
         i f   ( ! s . f l a k e s . l e n g t h )   {  
             / /   f i r s t   r u n  
             s . s t a r t ( ) ;  
         }   e l s e   {  
             s . a c t i v e   =   ! s . a c t i v e ;  
             i f   ( s . a c t i v e )   {  
                 s . s h o w ( ) ;  
                 s . r e s u m e ( ) ;  
             }   e l s e   {  
                 s . s t o p ( ) ;  
                 s . f r e e z e ( ) ;  
             }  
         }  
     } ;  
  
     t h i s . s t o p   =   f u n c t i o n ( )   {  
         t h i s . f r e e z e ( ) ;  
         f o r   ( v a r   i = t h i s . f l a k e s . l e n g t h ;   i - - ; )   {  
             t h i s . f l a k e s [ i ] . o . s t y l e . d i s p l a y   =   ' n o n e ' ;  
         }  
         s . e v e n t s . r e m o v e ( w i n d o w , ' s c r o l l ' , s . s c r o l l H a n d l e r ) ;  
         s . e v e n t s . r e m o v e ( w i n d o w , ' r e s i z e ' , s . r e s i z e H a n d l e r ) ;  
         i f   ( s . f r e e z e O n B l u r )   {  
             i f   ( i s I E )   {  
                 s . e v e n t s . r e m o v e ( d o c u m e n t , ' f o c u s o u t ' , s . f r e e z e ) ;  
                 s . e v e n t s . r e m o v e ( d o c u m e n t , ' f o c u s i n ' , s . r e s u m e ) ;  
             }   e l s e   {  
                 s . e v e n t s . r e m o v e ( w i n d o w , ' b l u r ' , s . f r e e z e ) ;  
                 s . e v e n t s . r e m o v e ( w i n d o w , ' f o c u s ' , s . r e s u m e ) ;  
             }  
         }  
     } ;  
  
     t h i s . s h o w   =   f u n c t i o n ( )   {  
         f o r   ( v a r   i = t h i s . f l a k e s . l e n g t h ;   i - - ; )   {  
             t h i s . f l a k e s [ i ] . o . s t y l e . d i s p l a y   =   ' b l o c k ' ;  
         }  
     } ;  
  
     t h i s . S n o w F l a k e   =   f u n c t i o n ( p a r e n t , t y p e , x , y )   {  
         v a r   s   =   t h i s ,   s t o r m   =   p a r e n t ;  
         t h i s . t y p e   =   t y p e ;  
         t h i s . x   =   x | | p a r s e I n t ( r n d ( s c r e e n X - 2 0 ) , 1 0 ) ;  
         t h i s . y   =   ( ! i s N a N ( y ) ? y : - r n d ( s c r e e n Y ) - 1 2 ) ;  
         t h i s . v X   =   n u l l ;  
         t h i s . v Y   =   n u l l ;  
         t h i s . v A m p T y p e s   =   [ 1 , 1 . 2 , 1 . 4 , 1 . 6 , 1 . 8 ] ;   / /   " a m p l i f i c a t i o n "   f o r   v X / v Y   ( b a s e d   o n   f l a k e   s i z e / t y p e )  
         t h i s . v A m p   =   t h i s . v A m p T y p e s [ t h i s . t y p e ] ;  
         t h i s . m e l t i n g   =   f a l s e ;  
         t h i s . m e l t F r a m e C o u n t   =   s t o r m . m e l t F r a m e C o u n t ;  
         t h i s . m e l t F r a m e s   =   s t o r m . m e l t F r a m e s ;  
         t h i s . m e l t F r a m e   =   0 ;  
         t h i s . t w i n k l e F r a m e   =   0 ;  
         t h i s . a c t i v e   =   1 ;  
         t h i s . f o n t S i z e   =   ( 1 0 + ( t h i s . t y p e / 5 ) * 1 0 ) ;  
         t h i s . o   =   d o c u m e n t . c r e a t e E l e m e n t ( ' d i v ' ) ;  
         t h i s . o . i n n e r H T M L   =   s t o r m . s n o w C h a r a c t e r ;  
         t h i s . o . s t y l e . c o l o r   =   s t o r m . s n o w C o l o r ;  
         t h i s . o . s t y l e . p o s i t i o n   =   ( f i x e d F o r E v e r y t h i n g ? ' f i x e d ' : ' a b s o l u t e ' ) ;  
         t h i s . o . s t y l e . w i d t h   =   s t o r m . f l a k e W i d t h + ' p x ' ;  
         t h i s . o . s t y l e . h e i g h t   =   s t o r m . f l a k e H e i g h t + ' p x ' ;  
         t h i s . o . s t y l e . f o n t F a m i l y   =   ' a r i a l , v e r d a n a ' ;  
         t h i s . o . s t y l e . o v e r f l o w   =   ' h i d d e n ' ;  
         t h i s . o . s t y l e . f o n t W e i g h t   =   ' n o r m a l ' ;  
         t h i s . o . s t y l e . z I n d e x   =   s t o r m . z I n d e x ;  
         d o c F r a g . a p p e n d C h i l d ( t h i s . o ) ;  
  
         t h i s . r e f r e s h   =   f u n c t i o n ( )   {  
             i f   ( i s N a N ( s . x )   | |   i s N a N ( s . y ) )   {  
                 / /   s a f e t y   c h e c k  
                 r e t u r n   f a l s e ;  
             }  
             s . o . s t y l e . l e f t   =   s . x + ' p x ' ;  
             s . o . s t y l e . t o p   =   s . y + ' p x ' ;  
         } ;  
  
         t h i s . s t i c k   =   f u n c t i o n ( )   {  
             i f   ( n o F i x e d   | |   ( s t o r m . t a r g e t E l e m e n t   ! = =   d o c u m e n t . d o c u m e n t E l e m e n t   & &   s t o r m . t a r g e t E l e m e n t   ! = =   d o c u m e n t . b o d y ) )   {  
                 s . o . s t y l e . t o p   =   ( s c r e e n Y + s c r o l l Y - s t o r m . f l a k e H e i g h t ) + ' p x ' ;  
             }   e l s e   i f   ( s t o r m . f l a k e B o t t o m )   {  
                 s . o . s t y l e . t o p   =   s t o r m . f l a k e B o t t o m + ' p x ' ;  
             }   e l s e   {  
                 s . o . s t y l e . d i s p l a y   =   ' n o n e ' ;  
                 s . o . s t y l e . t o p   =   ' a u t o ' ;  
                 s . o . s t y l e . b o t t o m   =   ' 0 p x ' ;  
                 s . o . s t y l e . p o s i t i o n   =   ' f i x e d ' ;  
                 s . o . s t y l e . d i s p l a y   =   ' b l o c k ' ;  
             }  
         } ;  
  
         t h i s . v C h e c k   =   f u n c t i o n ( )   {  
             i f   ( s . v X > = 0   & &   s . v X < 0 . 2 )   {  
                 s . v X   =   0 . 2 ;  
             }   e l s e   i f   ( s . v X < 0   & &   s . v X > - 0 . 2 )   {  
                 s . v X   =   - 0 . 2 ;  
             }  
             i f   ( s . v Y > = 0   & &   s . v Y < 0 . 2 )   {  
                 s . v Y   =   0 . 2 ;  
             }  
         } ;  
  
         t h i s . m o v e   =   f u n c t i o n ( )   {  
             v a r   v X   =   s . v X * w i n d O f f s e t ,   y D i f f ;  
             s . x   + =   v X ;  
             s . y   + =   ( s . v Y * s . v A m p ) ;  
             i f   ( s . x   > =   s c r e e n X   | |   s c r e e n X - s . x   <   s t o r m . f l a k e W i d t h )   {   / /   X - a x i s   s c r o l l   c h e c k  
                 s . x   =   0 ;  
             }   e l s e   i f   ( v X   <   0   & &   s . x - s t o r m . f l a k e L e f t O f f s e t   <   0 - s t o r m . f l a k e W i d t h )   {  
                 s . x   =   s c r e e n X - s t o r m . f l a k e W i d t h - 1 ;   / /   f l a k e W i d t h ;  
             }  
             s . r e f r e s h ( ) ;  
             y D i f f   =   s c r e e n Y + s c r o l l Y - s . y ;  
             i f   ( y D i f f < s t o r m . f l a k e H e i g h t )   {  
                 s . a c t i v e   =   0 ;  
                 i f   ( s t o r m . s n o w S t i c k )   {  
                     s . s t i c k ( ) ;  
                 }   e l s e   {  
                     s . r e c y c l e ( ) ;  
                 }  
             }   e l s e   {  
                 i f   ( s t o r m . u s e M e l t E f f e c t   & &   s . a c t i v e   & &   s . t y p e   <   3   & &   ! s . m e l t i n g   & &   M a t h . r a n d o m ( ) > 0 . 9 9 8 )   {  
                     / /   ~ 1 / 1 0 0 0   c h a n c e   o f   m e l t i n g   m i d - a i r ,   w i t h   e a c h   f r a m e  
                     s . m e l t i n g   =   t r u e ;  
                     s . m e l t ( ) ;  
                     / /   o n l y   i n c r e m e n t a l l y   m e l t   o n e   f r a m e  
                     / /   s . m e l t i n g   =   f a l s e ;  
                 }  
                 i f   ( s t o r m . u s e T w i n k l e E f f e c t )   {  
                     i f   ( ! s . t w i n k l e F r a m e )   {  
                         i f   ( M a t h . r a n d o m ( ) > 0 . 9 )   {  
                             s . t w i n k l e F r a m e   =   p a r s e I n t ( M a t h . r a n d o m ( ) * 2 0 , 1 0 ) ;  
                         }  
                     }   e l s e   {  
                         s . t w i n k l e F r a m e - - ;  
                         s . o . s t y l e . v i s i b i l i t y   =   ( s . t w i n k l e F r a m e   & &   s . t w i n k l e F r a m e % 2 = = = 0 ? ' h i d d e n ' : ' v i s i b l e ' ) ;  
                     }  
                 }  
             }  
         } ;  
  
         t h i s . a n i m a t e   =   f u n c t i o n ( )   {  
             / /   m a i n   a n i m a t i o n   l o o p  
             / /   m o v e ,   c h e c k   s t a t u s ,   d i e   e t c .  
             s . m o v e ( ) ;  
         } ;  
  
         t h i s . s e t V e l o c i t i e s   =   f u n c t i o n ( )   {  
             s . v X   =   v R n d X + r n d ( s t o r m . v M a x X * 0 . 1 2 , 0 . 1 ) ;  
             s . v Y   =   v R n d Y + r n d ( s t o r m . v M a x Y * 0 . 1 2 , 0 . 1 ) ;  
         } ;  
  
         t h i s . s e t O p a c i t y   =   f u n c t i o n ( o , o p a c i t y )   {  
             i f   ( ! o p a c i t y S u p p o r t e d )   {  
                 r e t u r n   f a l s e ;  
             }  
             o . s t y l e . o p a c i t y   =   o p a c i t y ;  
         } ;  
  
         t h i s . m e l t   =   f u n c t i o n ( )   {  
             i f   ( ! s t o r m . u s e M e l t E f f e c t   | |   ! s . m e l t i n g )   {  
                 s . r e c y c l e ( ) ;  
             }   e l s e   {  
                 i f   ( s . m e l t F r a m e   <   s . m e l t F r a m e C o u n t )   {  
                     s . m e l t F r a m e + + ;  
                     s . s e t O p a c i t y ( s . o , s . m e l t F r a m e s [ s . m e l t F r a m e ] ) ;  
                     s . o . s t y l e . f o n t S i z e   =   s . f o n t S i z e - ( s . f o n t S i z e * ( s . m e l t F r a m e / s . m e l t F r a m e C o u n t ) ) + ' p x ' ;  
                     s . o . s t y l e . l i n e H e i g h t   =   s t o r m . f l a k e H e i g h t + 2 + ( s t o r m . f l a k e H e i g h t * 0 . 7 5 * ( s . m e l t F r a m e / s . m e l t F r a m e C o u n t ) ) + ' p x ' ;  
                 }   e l s e   {  
                     s . r e c y c l e ( ) ;  
                 }  
             }  
         } ;  
  
         t h i s . r e c y c l e   =   f u n c t i o n ( )   {  
             s . o . s t y l e . d i s p l a y   =   ' n o n e ' ;  
             s . o . s t y l e . p o s i t i o n   =   ( f i x e d F o r E v e r y t h i n g ? ' f i x e d ' : ' a b s o l u t e ' ) ;  
             s . o . s t y l e . b o t t o m   =   ' a u t o ' ;  
             s . s e t V e l o c i t i e s ( ) ;  
             s . v C h e c k ( ) ;  
             s . m e l t F r a m e   =   0 ;  
             s . m e l t i n g   =   f a l s e ;  
             s . s e t O p a c i t y ( s . o , 1 ) ;  
             s . o . s t y l e . p a d d i n g   =   ' 0 p x ' ;  
             s . o . s t y l e . m a r g i n   =   ' 0 p x ' ;  
             s . o . s t y l e . f o n t S i z e   =   s . f o n t S i z e + ' p x ' ;  
             s . o . s t y l e . l i n e H e i g h t   =   ( s t o r m . f l a k e H e i g h t + 2 ) + ' p x ' ;  
             s . o . s t y l e . t e x t A l i g n   =   ' c e n t e r ' ;  
             s . o . s t y l e . v e r t i c a l A l i g n   =   ' b a s e l i n e ' ;  
             s . x   =   p a r s e I n t ( r n d ( s c r e e n X - s t o r m . f l a k e W i d t h - 2 0 ) , 1 0 ) ;  
             s . y   =   p a r s e I n t ( r n d ( s c r e e n Y ) * - 1 , 1 0 ) - s t o r m . f l a k e H e i g h t ;  
             s . r e f r e s h ( ) ;  
             s . o . s t y l e . d i s p l a y   =   ' b l o c k ' ;  
             s . a c t i v e   =   1 ;  
         } ;  
  
         t h i s . r e c y c l e ( ) ;   / /   s e t   u p   x / y   c o o r d s   e t c .  
         t h i s . r e f r e s h ( ) ;  
  
     } ;  
  
     t h i s . s n o w   =   f u n c t i o n ( )   {  
         v a r   a c t i v e   =   0 ,   u s e d   =   0 ,   w a i t i n g   =   0 ,   f l a k e   =   n u l l ,   i ;  
         f o r   ( i = s . f l a k e s . l e n g t h ;   i - - ; )   {  
             i f   ( s . f l a k e s [ i ] . a c t i v e   = = =   1 )   {  
                 s . f l a k e s [ i ] . m o v e ( ) ;  
                 a c t i v e + + ;  
             }   e l s e   i f   ( s . f l a k e s [ i ] . a c t i v e   = = =   0 )   {  
                 u s e d + + ;  
             }   e l s e   {  
                 w a i t i n g + + ;  
             }  
             i f   ( s . f l a k e s [ i ] . m e l t i n g )   {  
                 s . f l a k e s [ i ] . m e l t ( ) ;  
             }  
         }  
         i f   ( a c t i v e < s . f l a k e s M a x A c t i v e )   {  
             f l a k e   =   s . f l a k e s [ p a r s e I n t ( r n d ( s . f l a k e s . l e n g t h ) , 1 0 ) ] ;  
             i f   ( f l a k e . a c t i v e   = = =   0 )   {  
                 f l a k e . m e l t i n g   =   t r u e ;  
             }  
         }  
     } ;  
  
     t h i s . m o u s e M o v e   =   f u n c t i o n ( e )   {  
         i f   ( ! s . f o l l o w M o u s e )   {  
             r e t u r n   t r u e ;  
         }  
         v a r   x   =   p a r s e I n t ( e . c l i e n t X , 1 0 ) ;  
         i f   ( x < s c r e e n X 2 )   {  
             w i n d O f f s e t   =   - w i n d M u l t i p l i e r + ( x / s c r e e n X 2 * w i n d M u l t i p l i e r ) ;  
         }   e l s e   {  
             x   - =   s c r e e n X 2 ;  
             w i n d O f f s e t   =   ( x / s c r e e n X 2 ) * w i n d M u l t i p l i e r ;  
         }  
     } ;  
  
     t h i s . c r e a t e S n o w   =   f u n c t i o n ( l i m i t , a l l o w I n a c t i v e )   {  
         f o r   ( v a r   i = 0 ;   i < l i m i t ;   i + + )   {  
             s . f l a k e s [ s . f l a k e s . l e n g t h ]   =   n e w   s . S n o w F l a k e ( s , p a r s e I n t ( r n d ( f l a k e T y p e s ) , 1 0 ) ) ;  
             i f   ( a l l o w I n a c t i v e   | |   i > s . f l a k e s M a x A c t i v e )   {  
                 s . f l a k e s [ s . f l a k e s . l e n g t h - 1 ] . a c t i v e   =   - 1 ;  
             }  
         }  
         s t o r m . t a r g e t E l e m e n t . a p p e n d C h i l d ( d o c F r a g ) ;  
     } ;  
  
     t h i s . t i m e r I n i t   =   f u n c t i o n ( )   {  
         s . t i m e r s   =   ( ! i s W i n 9 8 ? [ s e t I n t e r v a l ( s . s n o w , s . a n i m a t i o n I n t e r v a l ) ] : [ s e t I n t e r v a l ( s . s n o w , s . a n i m a t i o n I n t e r v a l * 3 ) , s e t I n t e r v a l ( s . s n o w , s . a n i m a t i o n I n t e r v a l ) ] ) ;  
     } ;  
  
     t h i s . i n i t   =   f u n c t i o n ( )   {  
         f o r   ( v a r   i = 0 ;   i < s . m e l t F r a m e C o u n t ;   i + + )   {  
             s . m e l t F r a m e s . p u s h ( 1 - ( i / s . m e l t F r a m e C o u n t ) ) ;  
         }  
         s . r a n d o m i z e W i n d ( ) ;  
         s . c r e a t e S n o w ( s . f l a k e s M a x ) ;   / /   c r e a t e   i n i t i a l   b a t c h  
         s . e v e n t s . a d d ( w i n d o w , ' r e s i z e ' , s . r e s i z e H a n d l e r ) ;  
         s . e v e n t s . a d d ( w i n d o w , ' s c r o l l ' , s . s c r o l l H a n d l e r ) ;  
         i f   ( s . f r e e z e O n B l u r )   {  
             i f   ( i s I E )   {  
                 s . e v e n t s . a d d ( d o c u m e n t , ' f o c u s o u t ' , s . f r e e z e ) ;  
                 s . e v e n t s . a d d ( d o c u m e n t , ' f o c u s i n ' , s . r e s u m e ) ;  
             }   e l s e   {  
                 s . e v e n t s . a d d ( w i n d o w , ' b l u r ' , s . f r e e z e ) ;  
                 s . e v e n t s . a d d ( w i n d o w , ' f o c u s ' , s . r e s u m e ) ;  
             }  
         }  
         s . r e s i z e H a n d l e r ( ) ;  
         s . s c r o l l H a n d l e r ( ) ;  
         i f   ( s . f o l l o w M o u s e )   {  
             s . e v e n t s . a d d ( i s I E ? d o c u m e n t : w i n d o w , ' m o u s e m o v e ' , s . m o u s e M o v e ) ;  
         }  
         s . a n i m a t i o n I n t e r v a l   =   M a t h . m a x ( 2 0 , s . a n i m a t i o n I n t e r v a l ) ;  
         s . t i m e r I n i t ( ) ;  
     } ;  
  
     t h i s . s t a r t   =   f u n c t i o n ( b F r o m O n L o a d )   {  
         i f   ( ! d i d I n i t )   {  
             d i d I n i t   =   t r u e ;  
         }   e l s e   i f   ( b F r o m O n L o a d )   {  
             / /   a l r e a d y   l o a d e d   a n d   r u n n i n g  
             r e t u r n   t r u e ;  
         }  
         i f   ( t y p e o f   s . t a r g e t E l e m e n t   = = =   ' s t r i n g ' )   {  
             v a r   t a r g e t I D   =   s . t a r g e t E l e m e n t ;  
             s . t a r g e t E l e m e n t   =   d o c u m e n t . g e t E l e m e n t B y I d ( t a r g e t I D ) ;  
             i f   ( ! s . t a r g e t E l e m e n t )   {  
                 t h r o w   n e w   E r r o r ( ' S n o w s t o r m :   U n a b l e   t o   g e t   t a r g e t E l e m e n t   " ' + t a r g e t I D + ' " ' ) ;  
             }  
         }  
         i f   ( ! s . t a r g e t E l e m e n t )   {  
             s . t a r g e t E l e m e n t   =   ( ! i s I E ? ( d o c u m e n t . d o c u m e n t E l e m e n t ? d o c u m e n t . d o c u m e n t E l e m e n t : d o c u m e n t . b o d y ) : d o c u m e n t . b o d y ) ;  
         }  
         i f   ( s . t a r g e t E l e m e n t   ! = =   d o c u m e n t . d o c u m e n t E l e m e n t   & &   s . t a r g e t E l e m e n t   ! = =   d o c u m e n t . b o d y )   {  
             s . r e s i z e H a n d l e r   =   s . r e s i z e H a n d l e r A l t ;   / /   r e - m a p   h a n d l e r   t o   g e t   e l e m e n t   i n s t e a d   o f   s c r e e n   d i m e n s i o n s  
         }  
         s . r e s i z e H a n d l e r ( ) ;   / /   g e t   b o u n d i n g   b o x   e l e m e n t s  
         s . u s e P o s i t i o n F i x e d   =   ( s . u s e P o s i t i o n F i x e d   & &   ! n o F i x e d ) ;   / /   w h e t h e r   o r   n o t   p o s i t i o n : f i x e d   i s   s u p p o r t e d  
         f i x e d F o r E v e r y t h i n g   =   s . u s e P o s i t i o n F i x e d ;  
         i f   ( s c r e e n X   & &   s c r e e n Y   & &   ! s . d i s a b l e d )   {  
             s . i n i t ( ) ;  
             s . a c t i v e   =   t r u e ;  
         }  
     } ;  
  
     f u n c t i o n   d o S t a r t ( )   {  
         i f   ( ( t h i s . e x c l u d e M o b i l e   & &   ! i s M o b i l e )   | |   ! t h i s . e x c l u d e M o b i l e )   {  
             w i n d o w . s e t T i m e o u t ( f u n c t i o n ( )   {  
                 s . s t a r t ( t r u e ) ;  
             } ,   2 0 ) ;  
         }  
         / /   e v e n t   c l e a n u p  
         s . e v e n t s . r e m o v e ( w i n d o w ,   ' l o a d ' ,   d o S t a r t ) ;  
     }  
  
     / /   h o o k s   f o r   s t a r t i n g   t h e   s n o w  
     s . e v e n t s . a d d ( w i n d o w ,   ' l o a d ' ,   d o S t a r t ,   f a l s e ) ;  
  
     r e t u r n   t h i s ;  
  
 } ( w i n d o w ,   d o c u m e n t ) ) ; 
