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