ÿþ/ *  
 S c r i p t :   i m a g e M e n u . j s  
  
 A u t h o r s :  
 	 S a m   B i r c h  
  
 L i c e n s e :  
 	 M I T - s t y l e   l i c e n s e .  
  
 * /  
 v a r   I m a g e M e n u   =   n e w   C l a s s ( {  
 	  
 	 i n i t i a l i z e :   f u n c t i o n ( m y E l e m e n t s , o p t i o n s ) {  
 	 	 o p t i o n s   =   O b j e c t . e x t e n d ( {  
 	 	 	 o n C l i c k :   C l a s s . e m p t y ,  
 	 	 	 s t a r t :   - 1 ,  
 	 	 	 o p e n W i d t h :   0 ,  
 	 	 	 s m a l l W i d t h :   0 ,  
 	 	 	 i t e m W i d t h :   0 ,  
 	 	 	 s e l e c t e d :   - 1 ,  
 	 	 	 o p e n :   - 1 ,  
 	 	 	 t r a n s i t i o n :   F x . T r a n s i t i o n s . q u a d O u t  
 	 	 } ,   o p t i o n s   | |   { } ) ;  
 	 	  
 	 	 t h i s . m y E l e m e n t s   =   m y E l e m e n t s ;  
 	 	 t h i s . o p t i o n s   =   o p t i o n s ;  
 	 	  
 	 	 o p t i o n s . i t e m W i d t h   =   m y E l e m e n t s [ 0 ] . g e t S t y l e ( ' w i d t h ' ) . t o I n t ( ) ;  
 	 	 o p t i o n s . s m a l l W i d t h   =   M a t h . r o u n d ( ( ( o p t i o n s . i t e m W i d t h * m y E l e m e n t s . l e n g t h ) - o p t i o n s . o p e n W i d t h ) / ( m y E l e m e n t s . l e n g t h - 1 ) ) ;  
 	 	  
 	 	 v a r   f x   =   n e w   F x . E l e m e n t s ( m y E l e m e n t s ,   { w a i t :   f a l s e ,   d u r a t i o n :   4 0 0 ,   t r a n s i t i o n :   o p t i o n s . t r a n s i t i o n } ) ;  
 	 	  
 	 	 m y E l e m e n t s . e a c h ( f u n c t i o n ( e l ,   i ) {  
 	 	 	 e l . a d d E v e n t ( ' m o u s e o v e r ' ,   f u n c t i o n ( e ) {  
 	 	 	 	 e   =   n e w   E v e n t ( e ) . s t o p ( ) ;  
 	 	 	 	 e l . s h o w ( ) ;  
 	 	 	 } ) ;  
 	 	 	  
 	 	 	 e l . a d d E v e n t ( ' c l i c k ' ,   f u n c t i o n ( e ) {  
 	 	 	 	 e l . s e l e c t ( ) ;  
 	 	 	 } ) ;  
 	 	 	  
 	 	 	 e l . a d d E v e n t ( ' m o u s e o u t ' ,   f u n c t i o n ( e ) {  
 	 	 	 	 e   =   n e w   E v e n t ( e ) . s t o p ( ) ;  
 	 	 	 	 e l . h i d e ( ) ;  
 	 	 	 } ) ;  
 	 	 	  
 	 	 	 e l . s h o w   =   f u n c t i o n ( ) {  
 	 	 	 	 v a r   o b j   =   { } ;  
 	 	 	 	 o b j [ i ]   =   { ' w i d t h ' :   [ e l . g e t S t y l e ( ' w i d t h ' ) . t o I n t ( ) ,   o p t i o n s . o p e n W i d t h ] } ;  
 	 	 	 	 m y E l e m e n t s . e a c h ( f u n c t i o n ( o t h e r ,   j ) {  
 	 	 	 	 	 i f   ( o t h e r   ! =   e l ) {  
 	 	 	 	 	 	 v a r   w   =   o t h e r . g e t S t y l e ( ' w i d t h ' ) . t o I n t ( ) ;  
 	 	 	 	 	 	 i f   ( w   ! =   o p t i o n s . s m a l l W i d t h )   o b j [ j ]   =   { ' w i d t h ' :   [ w ,   o p t i o n s . s m a l l W i d t h ] } ;  
 	 	 	 	 	 }  
 	 	 	 	 } ) ;  
 	 	 	 	 f x . s t a r t ( o b j ) ;  
 	 	 	 } ;  
 	 	 	  
 	 	 	 e l . h i d e   =   f u n c t i o n ( ) {  
 	 	 	 	 v a r   o b j   =   { } ;  
 	 	 	 	 i f ( o p t i o n s . s e l e c t e d   = =   - 1 ) {  
 	 	 	 	 	 m y E l e m e n t s . e a c h ( f u n c t i o n ( e l , i ) {  
 	 	 	 	 	 	 o b j [ i ]   =   { ' w i d t h ' :   [ e l . g e t S t y l e ( ' w i d t h ' ) . t o I n t ( ) ,   o p t i o n s . i t e m W i d t h ] } ; 	  
 	 	 	 	 	 } ) ;  
 	 	 	 	 } e l s e {  
 	 	 	 	 	 m y E l e m e n t s . e a c h ( f u n c t i o n ( e l , i ) {  
 	 	 	 	 	 	 i f ( i   ! =   o p t i o n s . s e l e c t e d ) {  
 	 	 	 	 	 	 	 v a r   w   =   e l . g e t S t y l e ( ' w i d t h ' ) . t o I n t ( ) ;  
 	 	 	 	 	 	 	 i f ( w   ! =   o p t i o n s . s m a l l W i d t h ) { o b j [ i ]   =   { ' w i d t h ' :   [ w ,   o p t i o n s . s m a l l W i d t h ] } } ;  
 	 	 	 	 	 	 } e l s e {  
 	 	 	 	 	 	 	 o b j [ i ]   =   { ' w i d t h ' :   [ e l . g e t S t y l e ( ' w i d t h ' ) . t o I n t ( ) ,   o p t i o n s . o p e n W i d t h ] } ;  
 	 	 	 	 	 	 }  
 	 	 	 	 	 } ) ;  
 	 	 	 	 }  
 	 	 	 	 f x . s t a r t ( o b j ) ;  
 	 	 	 } ;  
 	 	 	  
 	 	 	 e l . s e l e c t   =   f u n c t i o n ( ) {  
 	 	 	 	 i f ( o p t i o n s . s e l e c t e d   = =   i ) { o p t i o n s . s e l e c t e d   =   - 1 } e l s e { o p t i o n s . s e l e c t e d   =   i }  
 	 	 	 	 o p t i o n s . o n C l i c k ( o p t i o n s . s e l e c t e d , o p t i o n s . o p e n ) ;  
 	 	 	 	 o p t i o n s . o p e n   =   o p t i o n s . s e l e c t e d ;  
 	 	 	 } ;  
 	 	 } ) ;  
 	 	  
 	 	 i f ( o p t i o n s . s t a r t   ! =   - 1 ) {  
 	 	 	 m y E l e m e n t s [ o p t i o n s . s t a r t ] . s h o w ( ) ;  
 	 	 	 m y E l e m e n t s [ o p t i o n s . s t a r t ] . s e l e c t ( ) ;  
 	 	 }  
 	 } ,  
 	  
 	 r e s e t :   f u n c t i o n ( ) {  
 	 	 t h i s . o p t i o n s . s e l e c t e d   =   - 1 ;  
 	 	 t h i s . o p t i o n s . o p e n   =   - 1 ;  
 	 	 t h i s . m y E l e m e n t s . e a c h ( f u n c t i o n ( e l ,   i ) {  
 	 	 	 e l . h i d e ( ) ;  
 	 	 } ) ;  
 	 }  
 	  
 } ) ;  
 
