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