ÿþ/ * *  
   *   j Q u e r y . t i m e r s   -   T i m e r   a b s t r a c t i o n s   f o r   j Q u e r y  
   *   W r i t t e n   b y   B l a i r   M i t c h e l m o r e   ( b l a i r   D O T   m i t c h e l m o r e   A T   g m a i l   D O T   c o m )  
   *   L i c e n s e d   u n d e r   t h e   W T F P L   ( h t t p : / / s a m . z o y . o r g / w t f p l / ) .  
   *   D a t e :   2 0 0 9 / 0 2 / 0 8  
   *  
   *   @ a u t h o r   B l a i r   M i t c h e l m o r e  
   *   @ v e r s i o n   1 . 1 . 2  
   *  
   * * /  
  
 j Q u e r y . f n . e x t e n d ( {  
 	 e v e r y T i m e :   f u n c t i o n ( i n t e r v a l ,   l a b e l ,   f n ,   t i m e s ,   b e l a y )   {  
 	 	 r e t u r n   t h i s . e a c h ( f u n c t i o n ( )   {  
 	 	 	 j Q u e r y . t i m e r . a d d ( t h i s ,   i n t e r v a l ,   l a b e l ,   f n ,   t i m e s ,   b e l a y ) ;  
 	 	 } ) ;  
 	 } ,  
 	 o n e T i m e :   f u n c t i o n ( i n t e r v a l ,   l a b e l ,   f n )   {  
 	 	 r e t u r n   t h i s . e a c h ( f u n c t i o n ( )   {  
 	 	 	 j Q u e r y . t i m e r . a d d ( t h i s ,   i n t e r v a l ,   l a b e l ,   f n ,   1 ) ;  
 	 	 } ) ;  
 	 } ,  
 	 s t o p T i m e :   f u n c t i o n ( l a b e l ,   f n )   {  
 	 	 r e t u r n   t h i s . e a c h ( f u n c t i o n ( )   {  
 	 	 	 j Q u e r y . t i m e r . r e m o v e ( t h i s ,   l a b e l ,   f n ) ;  
 	 	 } ) ;  
 	 }  
 } ) ;  
  
 j Q u e r y . e v e n t . s p e c i a l  
  
 j Q u e r y . e x t e n d ( {  
 	 t i m e r :   {  
 	 	 g l o b a l :   [ ] ,  
 	 	 g u i d :   1 ,  
 	 	 d a t a K e y :   " j Q u e r y . t i m e r " ,  
 	 	 r e g e x :   / ^ ( [ 0 - 9 ] + ( ? : \ . [ 0 - 9 ] * ) ? ) \ s * ( . * s ) ? $ / ,  
 	 	 p o w e r s :   {  
 	 	 	 / /   Y e a h   t h i s   i s   m a j o r   o v e r k i l l . . .  
 	 	 	 ' m s ' :   1 ,  
 	 	 	 ' c s ' :   1 0 ,  
 	 	 	 ' d s ' :   1 0 0 ,  
 	 	 	 ' s ' :   1 0 0 0 ,  
 	 	 	 ' d a s ' :   1 0 0 0 0 ,  
 	 	 	 ' h s ' :   1 0 0 0 0 0 ,  
 	 	 	 ' k s ' :   1 0 0 0 0 0 0  
 	 	 } ,  
 	 	 t i m e P a r s e :   f u n c t i o n ( v a l u e )   {  
 	 	 	 i f   ( v a l u e   = =   u n d e f i n e d   | |   v a l u e   = =   n u l l )  
 	 	 	 	 r e t u r n   n u l l ;  
 	 	 	 v a r   r e s u l t   =   t h i s . r e g e x . e x e c ( j Q u e r y . t r i m ( v a l u e . t o S t r i n g ( ) ) ) ;  
 	 	 	 i f   ( r e s u l t [ 2 ] )   {  
 	 	 	 	 v a r   n u m   =   p a r s e F l o a t ( r e s u l t [ 1 ] ) ;  
 	 	 	 	 v a r   m u l t   =   t h i s . p o w e r s [ r e s u l t [ 2 ] ]   | |   1 ;  
 	 	 	 	 r e t u r n   n u m   *   m u l t ;  
 	 	 	 }   e l s e   {  
 	 	 	 	 r e t u r n   v a l u e ;  
 	 	 	 }  
 	 	 } ,  
 	 	 a d d :   f u n c t i o n ( e l e m e n t ,   i n t e r v a l ,   l a b e l ,   f n ,   t i m e s ,   b e l a y )   {  
 	 	 	 v a r   c o u n t e r   =   0 ;  
 	 	 	  
 	 	 	 i f   ( j Q u e r y . i s F u n c t i o n ( l a b e l ) )   {  
 	 	 	 	 i f   ( ! t i m e s )    
 	 	 	 	 	 t i m e s   =   f n ;  
 	 	 	 	 f n   =   l a b e l ;  
 	 	 	 	 l a b e l   =   i n t e r v a l ;  
 	 	 	 }  
 	 	 	  
 	 	 	 i n t e r v a l   =   j Q u e r y . t i m e r . t i m e P a r s e ( i n t e r v a l ) ;  
  
 	 	 	 i f   ( t y p e o f   i n t e r v a l   ! =   ' n u m b e r '   | |   i s N a N ( i n t e r v a l )   | |   i n t e r v a l   < =   0 )  
 	 	 	 	 r e t u r n ;  
  
 	 	 	 i f   ( t i m e s   & &   t i m e s . c o n s t r u c t o r   ! =   N u m b e r )   {  
 	 	 	 	 b e l a y   =   ! ! t i m e s ;  
 	 	 	 	 t i m e s   =   0 ;  
 	 	 	 }  
 	 	 	  
 	 	 	 t i m e s   =   t i m e s   | |   0 ;  
 	 	 	 b e l a y   =   b e l a y   | |   f a l s e ;  
 	 	 	  
 	 	 	 v a r   t i m e r s   =   j Q u e r y . d a t a ( e l e m e n t ,   t h i s . d a t a K e y )   | |   j Q u e r y . d a t a ( e l e m e n t ,   t h i s . d a t a K e y ,   { } ) ;  
 	 	 	  
 	 	 	 i f   ( ! t i m e r s [ l a b e l ] )  
 	 	 	 	 t i m e r s [ l a b e l ]   =   { } ;  
 	 	 	  
 	 	 	 f n . t i m e r I D   =   f n . t i m e r I D   | |   t h i s . g u i d + + ;  
 	 	 	  
 	 	 	 v a r   h a n d l e r   =   f u n c t i o n ( )   {  
 	 	 	 	 i f   ( b e l a y   & &   t h i s . i n P r o g r e s s )    
 	 	 	 	 	 r e t u r n ;  
 	 	 	 	 t h i s . i n P r o g r e s s   =   t r u e ;  
 	 	 	 	 i f   ( ( + + c o u n t e r   >   t i m e s   & &   t i m e s   ! = =   0 )   | |   f n . c a l l ( e l e m e n t ,   c o u n t e r )   = = =   f a l s e )  
 	 	 	 	 	 j Q u e r y . t i m e r . r e m o v e ( e l e m e n t ,   l a b e l ,   f n ) ;  
 	 	 	 	 t h i s . i n P r o g r e s s   =   f a l s e ;  
 	 	 	 } ;  
 	 	 	  
 	 	 	 h a n d l e r . t i m e r I D   =   f n . t i m e r I D ;  
 	 	 	  
 	 	 	 i f   ( ! t i m e r s [ l a b e l ] [ f n . t i m e r I D ] )  
 	 	 	 	 t i m e r s [ l a b e l ] [ f n . t i m e r I D ]   =   w i n d o w . s e t I n t e r v a l ( h a n d l e r , i n t e r v a l ) ;  
 	 	 	  
 	 	 	 t h i s . g l o b a l . p u s h (   e l e m e n t   ) ;  
 	 	 	  
 	 	 } ,  
 	 	 r e m o v e :   f u n c t i o n ( e l e m e n t ,   l a b e l ,   f n )   {  
 	 	 	 v a r   t i m e r s   =   j Q u e r y . d a t a ( e l e m e n t ,   t h i s . d a t a K e y ) ,   r e t ;  
 	 	 	  
 	 	 	 i f   (   t i m e r s   )   {  
 	 	 	 	  
 	 	 	 	 i f   ( ! l a b e l )   {  
 	 	 	 	 	 f o r   (   l a b e l   i n   t i m e r s   )  
 	 	 	 	 	 	 t h i s . r e m o v e ( e l e m e n t ,   l a b e l ,   f n ) ;  
 	 	 	 	 }   e l s e   i f   (   t i m e r s [ l a b e l ]   )   {  
 	 	 	 	 	 i f   (   f n   )   {  
 	 	 	 	 	 	 i f   (   f n . t i m e r I D   )   {  
 	 	 	 	 	 	 	 w i n d o w . c l e a r I n t e r v a l ( t i m e r s [ l a b e l ] [ f n . t i m e r I D ] ) ;  
 	 	 	 	 	 	 	 d e l e t e   t i m e r s [ l a b e l ] [ f n . t i m e r I D ] ;  
 	 	 	 	 	 	 }  
 	 	 	 	 	 }   e l s e   {  
 	 	 	 	 	 	 f o r   (   v a r   f n   i n   t i m e r s [ l a b e l ]   )   {  
 	 	 	 	 	 	 	 w i n d o w . c l e a r I n t e r v a l ( t i m e r s [ l a b e l ] [ f n ] ) ;  
 	 	 	 	 	 	 	 d e l e t e   t i m e r s [ l a b e l ] [ f n ] ;  
 	 	 	 	 	 	 }  
 	 	 	 	 	 }  
 	 	 	 	 	  
 	 	 	 	 	 f o r   (   r e t   i n   t i m e r s [ l a b e l ]   )   b r e a k ;  
 	 	 	 	 	 i f   (   ! r e t   )   {  
 	 	 	 	 	 	 r e t   =   n u l l ;  
 	 	 	 	 	 	 d e l e t e   t i m e r s [ l a b e l ] ;  
 	 	 	 	 	 }  
 	 	 	 	 }  
 	 	 	 	  
 	 	 	 	 f o r   (   r e t   i n   t i m e r s   )   b r e a k ;  
 	 	 	 	 i f   (   ! r e t   )    
 	 	 	 	 	 j Q u e r y . r e m o v e D a t a ( e l e m e n t ,   t h i s . d a t a K e y ) ;  
 	 	 	 }  
 	 	 }  
 	 }  
 } ) ;  
  
 j Q u e r y ( w i n d o w ) . b i n d ( " u n l o a d " ,   f u n c t i o n ( )   {  
 	 j Q u e r y . e a c h ( j Q u e r y . t i m e r . g l o b a l ,   f u n c t i o n ( i n d e x ,   i t e m )   {  
 	 	 j Q u e r y . t i m e r . r e m o v e ( i t e m ) ;  
 	 } ) ;  
 } ) ; 
