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