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