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