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