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