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