ÿþ/ / A n i m a t e d   C o l l a p s i b l e   D I V -   A u t h o r :   D y n a m i c   D r i v e   ( h t t p : / / w w w . d y n a m i c d r i v e . c o m )  
 / / L a s t   u p d a t e d   A u g   1 s t ,   0 7 ' .   F i x e d   b u g   w i t h   " b l o c k "   p a r a m e t e r   n o t   w o r k i n g   w h e n   p e r s i s t   i s   e n a b l e d  
 / / U p d a t e d   J u n e   2 7 t h ,   0 7 ' .   A d d e d   a b i l i t y   f o r   a   D I V   t o   b e   i n i t i a l l y   e x p a n d e d .  
  
 v a r   u n i q u e p a g e i d = w i n d o w . l o c a t i o n . h r e f . r e p l a c e ( " h t t p : / / " + w i n d o w . l o c a t i o n . h o s t n a m e ,   " " ) . r e p l a c e ( / ^ \ / / ,   " " )   / / g e t   c u r r e n t   p a g e   p a t h   a n d   n a m e ,   u s e d   t o   u n i q u e l y   i d e n t i f y   t h i s   p a g e   f o r   p e r s i s t e n c e   f e a t u r e  
  
 f u n c t i o n   a n i m a t e d c o l l a p s e ( d i v I d ,   a n i m a t e t i m e ,   p e r s i s t e x p a n d ,   i n i t s t a t e ) {  
 	 t h i s . d i v I d = d i v I d  
 	 t h i s . d i v O b j = d o c u m e n t . g e t E l e m e n t B y I d ( d i v I d )  
 	 t h i s . d i v O b j . s t y l e . o v e r f l o w = " h i d d e n "  
 	 t h i s . t i m e l e n g t h = a n i m a t e t i m e  
 	 t h i s . i n i t s t a t e = ( t y p e o f   i n i t s t a t e ! = " u n d e f i n e d "   & &   i n i t s t a t e = = " b l o c k " ) ?   " b l o c k "   :   " c o n t r a c t "  
 	 t h i s . i s E x p a n d e d = a n i m a t e d c o l l a p s e . g e t C o o k i e ( u n i q u e p a g e i d + " - " + d i v I d )   / / " y e s "   o r   " n o " ,   b a s e d   o n   c o o k i e   v a l u e  
 	 t h i s . c o n t e n t h e i g h t = p a r s e I n t ( t h i s . d i v O b j . s t y l e . h e i g h t )  
 	 v a r   t h i s o b j = t h i s  
 	 i f   ( i s N a N ( t h i s . c o n t e n t h e i g h t ) ) {   / / i f   n o   C S S   " h e i g h t "   a t t r i b u t e   e x p l i c i t l y   d e f i n e d ,   g e t   D I V ' s   h e i g h t   o n   w i n d o w . l o a d  
 	 	 a n i m a t e d c o l l a p s e . d o t a s k ( w i n d o w ,   f u n c t i o n ( ) { t h i s o b j . _ g e t h e i g h t ( p e r s i s t e x p a n d ) } ,   " l o a d " )  
 	 	 i f   ( ! p e r s i s t e x p a n d   & &   t h i s . i n i t s t a t e = = " c o n t r a c t "   | |   p e r s i s t e x p a n d   & &   t h i s . i s E x p a n d e d ! = " y e s "   & &   t h i s . i s E x p a n d e d ! = " " )   / / H i d e   D I V   ( u n l e s s   d i v   s h o u l d   b e   e x p a n d e d   b y   d e f a u l t ,   O R   p e r s i s t e n c e   i s   e n a b l e d   a n d   t h i s   D I V   s h o u l d   b e   e x p a n d e d )  
 	 	 	 t h i s . d i v O b j . s t y l e . v i s i b i l i t y = " h i d d e n "   / / h i d e   c o n t e n t   ( v e r s u s   c o l l a p s e )   u n t i l   w e   c a n   g e t   i t s   h e i g h t  
 	 }  
 	 e l s e   i f   ( ! p e r s i s t e x p a n d   & &   t h i s . i n i t s t a t e = = " c o n t r a c t "   | |   p e r s i s t e x p a n d   & &   t h i s . i s E x p a n d e d ! = " y e s "   & &   t h i s . i s E x p a n d e d ! = " " )   / / H i d e   D I V   ( u n l e s s   d i v   s h o u l d   b e   e x p a n d e d   b y   d e f a u l t ,   O R   p e r s i s t e n c e   i s   e n a b l e d   a n d   t h i s   D I V   s h o u l d   b e   e x p a n d e d )  
 	 	 t h i s . d i v O b j . s t y l e . h e i g h t = 0   / / j u s t   c o l l a p s e   c o n t e n t   i f   C S S   " h e i g h t "   a t t r i b u t e   a v a i l a b l e  
 	 i f   ( p e r s i s t e x p a n d )  
 	 	 a n i m a t e d c o l l a p s e . d o t a s k ( w i n d o w ,   f u n c t i o n ( ) { a n i m a t e d c o l l a p s e . s e t C o o k i e ( u n i q u e p a g e i d + " - " + t h i s o b j . d i v I d ,   t h i s o b j . i s E x p a n d e d ) } ,   " u n l o a d " )  
 }  
  
 a n i m a t e d c o l l a p s e . p r o t o t y p e . _ g e t h e i g h t = f u n c t i o n ( p e r s i s t e x p a n d ) {  
 	 t h i s . c o n t e n t h e i g h t = t h i s . d i v O b j . o f f s e t H e i g h t  
 	 i f   ( ! p e r s i s t e x p a n d   & &   t h i s . i n i t s t a t e = = " c o n t r a c t "   | |   p e r s i s t e x p a n d   & &   t h i s . i s E x p a n d e d ! = " y e s " ) {   / / H i d e   D I V   ( u n l e s s   d i v   s h o u l d   b e   e x p a n d e d   b y   d e f a u l t ,   O R   p e r s i s t e n c e   i s   e n a b l e d   a n d   t h i s   D I V   s h o u l d   b e   e x p a n d e d )  
 	 	 t h i s . d i v O b j . s t y l e . h e i g h t = 0   / / c o l l a p s e   c o n t e n t  
 	 	 t h i s . d i v O b j . s t y l e . v i s i b i l i t y = " v i s i b l e "  
 	 }  
 	 e l s e   / / e l s e   i f   p e r s i s t e n c e   i s   e n a b l e d   A N D   t h i s   c o n t e n t   s h o u l d   b e   e x p a n d e d ,   d e f i n e   i t s   C S S   h e i g h t   v a l u e   s o   s l i d e u p ( )   h a s   s o m e t h i n g   t o   w o r k   w i t h  
 	 	 t h i s . d i v O b j . s t y l e . h e i g h t = t h i s . c o n t e n t h e i g h t + " p x "  
 }  
  
  
 a n i m a t e d c o l l a p s e . p r o t o t y p e . _ s l i d e e n g i n e = f u n c t i o n ( d i r e c t i o n ) {  
 	 v a r   e l a p s e d = n e w   D a t e ( ) . g e t T i m e ( ) - t h i s . s t a r t T i m e   / / g e t   t i m e   a n i m a t i o n   h a s   r u n  
 	 v a r   t h i s o b j = t h i s  
 	 i f   ( e l a p s e d < t h i s . t i m e l e n g t h ) {   / / i f   t i m e   r u n   i s   l e s s   t h a n   s p e c i f i e d   l e n g t h  
 	 	 v a r   d i s t a n c e p e r c e n t = ( d i r e c t i o n = = " d o w n " ) ?   a n i m a t e d c o l l a p s e . c u r v e i n c r e m e n t ( e l a p s e d / t h i s . t i m e l e n g t h )   :   1 - a n i m a t e d c o l l a p s e . c u r v e i n c r e m e n t ( e l a p s e d / t h i s . t i m e l e n g t h )  
 	 t h i s . d i v O b j . s t y l e . h e i g h t = d i s t a n c e p e r c e n t   *   t h i s . c o n t e n t h e i g h t   + " p x "  
 	 t h i s . r u n t i m e r = s e t T i m e o u t ( f u n c t i o n ( ) { t h i s o b j . _ s l i d e e n g i n e ( d i r e c t i o n ) } ,   1 0 )  
 	 }  
 	 e l s e {   / / i f   a n i m a t i o n   f i n i s h e d  
 	 	 t h i s . d i v O b j . s t y l e . h e i g h t = ( d i r e c t i o n = = " d o w n " ) ?   t h i s . c o n t e n t h e i g h t + " p x "   :   0  
 	 	 t h i s . i s E x p a n d e d = ( d i r e c t i o n = = " d o w n " ) ?   " y e s "   :   " n o "   / / r e m e m b e r   w h e t h e r   c o n t e n t   i s   e x p a n d e d   o r   n o t  
 	 	 t h i s . r u n t i m e r = n u l l  
 	 }  
 }  
  
  
 a n i m a t e d c o l l a p s e . p r o t o t y p e . s l i d e d o w n = f u n c t i o n ( ) {  
 	 i f   ( t y p e o f   t h i s . r u n t i m e r = = " u n d e f i n e d "   | |   t h i s . r u n t i m e r = = n u l l ) {   / / i f   a n i m a t i o n   i s n ' t   a l r e a d y   r u n n i n g   o r   h a s   s t o p p e d   r u n n i n g  
 	 	 i f   ( i s N a N ( t h i s . c o n t e n t h e i g h t ) )   / / i f   c o n t e n t   h e i g h t   n o t   a v a i l a b l e   y e t   ( u n t i l   w i n d o w . o n l o a d )  
 	 	 	 a l e r t ( " P l e a s e   w a i t   u n t i l   d o c u m e n t   h a s   f u l l y   l o a d e d   t h e n   c l i c k   a g a i n " )  
 	 	 e l s e   i f   ( p a r s e I n t ( t h i s . d i v O b j . s t y l e . h e i g h t ) = = 0 ) {   / / i f   c o n t e n t   i s   c o l l a p s e d  
 	 	 	 t h i s . s t a r t T i m e = n e w   D a t e ( ) . g e t T i m e ( )   / / S e t   a n i m a t i o n   s t a r t   t i m e  
 	 	 	 t h i s . _ s l i d e e n g i n e ( " d o w n " )  
 	 	 }  
 	 }  
 }  
  
 a n i m a t e d c o l l a p s e . p r o t o t y p e . s l i d e u p = f u n c t i o n ( ) {  
 	 i f   ( t y p e o f   t h i s . r u n t i m e r = = " u n d e f i n e d "   | |   t h i s . r u n t i m e r = = n u l l ) {   / / i f   a n i m a t i o n   i s n ' t   a l r e a d y   r u n n i n g   o r   h a s   s t o p p e d   r u n n i n g  
 	 	 i f   ( i s N a N ( t h i s . c o n t e n t h e i g h t ) )   / / i f   c o n t e n t   h e i g h t   n o t   a v a i l a b l e   y e t   ( u n t i l   w i n d o w . o n l o a d )  
 	 	 	 a l e r t ( " P l e a s e   w a i t   u n t i l   d o c u m e n t   h a s   f u l l y   l o a d e d   t h e n   c l i c k   a g a i n " )  
 	 	 e l s e   i f   ( p a r s e I n t ( t h i s . d i v O b j . s t y l e . h e i g h t ) = = t h i s . c o n t e n t h e i g h t ) {   / / i f   c o n t e n t   i s   e x p a n d e d  
 	 	 	 t h i s . s t a r t T i m e = n e w   D a t e ( ) . g e t T i m e ( )  
 	 	 	 t h i s . _ s l i d e e n g i n e ( " u p " )  
 	 	 }  
 	 }  
 }  
  
 a n i m a t e d c o l l a p s e . p r o t o t y p e . s l i d e i t = f u n c t i o n ( ) {  
 	 i f   ( i s N a N ( t h i s . c o n t e n t h e i g h t ) )   / / i f   c o n t e n t   h e i g h t   n o t   a v a i l a b l e   y e t   ( u n t i l   w i n d o w . o n l o a d )  
 	 	 a l e r t ( " P l e a s e   w a i t   u n t i l   d o c u m e n t   h a s   f u l l y   l o a d e d   t h e n   c l i c k   a g a i n " )  
 	 e l s e   i f   ( p a r s e I n t ( t h i s . d i v O b j . s t y l e . h e i g h t ) = = 0 )  
 	 	 t h i s . s l i d e d o w n ( )  
 	 e l s e   i f   ( p a r s e I n t ( t h i s . d i v O b j . s t y l e . h e i g h t ) = = t h i s . c o n t e n t h e i g h t )  
 	 	 t h i s . s l i d e u p ( )  
 }  
  
 / /   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
 / /   A   f e w   u t i l i t y   f u n c t i o n s   b e l o w :  
 / /   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -  
  
 a n i m a t e d c o l l a p s e . c u r v e i n c r e m e n t = f u n c t i o n ( p e r c e n t ) {  
 	 r e t u r n   ( 1 - M a t h . c o s ( p e r c e n t * M a t h . P I ) )   /   2   / / r e t u r n   c o s   c u r v e   b a s e d   v a l u e   f r o m   a   p e r c e n t a g e   i n p u t  
 }  
  
  
 a n i m a t e d c o l l a p s e . d o t a s k = f u n c t i o n ( t a r g e t ,   f u n c t i o n r e f ,   t a s k t y p e ) {   / / a s s i g n   a   f u n c t i o n   t o   e x e c u t e   t o   a n   e v e n t   h a n d l e r   ( i e :   o n u n l o a d )  
 	 v a r   t a s k t y p e = ( w i n d o w . a d d E v e n t L i s t e n e r ) ?   t a s k t y p e   :   " o n " + t a s k t y p e  
 	 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 ( t a s k t y p e ,   f u n c t i o n r e f ,   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 ( t a s k t y p e ,   f u n c t i o n r e f )  
 }  
  
 a n i m a t e d c o l l a p s e . g e t C o o k i e = f u n c t i o n ( N a m e ) {    
 	 v a r   r e = n e w   R e g E x p ( N a m e + " = [ ^ ; ] + " ,   " i " ) ;   / / c o n s t r u c t   R E   t o   s e a r c h   f o r   t a r g e t   n a m e / v a l u e   p a i r  
 	 i f   ( d o c u m e n t . c o o k i e . m a t c h ( r e ) )   / / i f   c o o k i e   f o u n d  
 	 	 r e t u r n   d o c u m e n t . c o o k i e . m a t c h ( r e ) [ 0 ] . s p l i t ( " = " ) [ 1 ]   / / r e t u r n   i t s   v a l u e  
 	 r e t u r n   " "  
 }  
  
 a n i m a t e d c o l l a p s e . s e t C o o k i e = f u n c t i o n ( n a m e ,   v a l u e ) {  
 	 	 d o c u m e n t . c o o k i e   =   n a m e + " = " + v a l u e  
 } 
