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