ÿþj Q u e r y . f n . r o t a t e   =   f u n c t i o n ( a n g l e , w h e n c e )   {  
 	 v a r   p   =   t h i s . g e t ( 0 ) ;  
  
 	 / /   w e   s t o r e   t h e   a n g l e   i n s i d e   t h e   i m a g e   t a g   f o r   p e r s i s t e n c e  
 	 i f   ( ! w h e n c e )   {  
 	 	 p . a n g l e   =   ( ( p . a n g l e = = u n d e f i n e d ? 0 : p . a n g l e )   +   a n g l e )   %   3 6 0 ;  
 	 }   e l s e   {  
 	 	 p . a n g l e   =   a n g l e ;  
 	 }  
  
 	 i f   ( p . a n g l e   > =   0 )   {  
 	 	 v a r   r o t a t i o n   =   M a t h . P I   *   p . a n g l e   /   1 8 0 ;  
 	 }   e l s e   {  
 	 	 v a r   r o t a t i o n   =   M a t h . P I   *   ( 3 6 0 + p . a n g l e )   /   1 8 0 ;  
 	 }  
 	 v a r   c o s t h e t a   =   M a t h . c o s ( r o t a t i o n ) ;  
 	 v a r   s i n t h e t a   =   M a t h . s i n ( r o t a t i o n ) ;  
  
 	 i f   ( d o c u m e n t . a l l   & &   ! w i n d o w . o p e r a )   {  
 	 	 v a r   c a n v a s   =   d o c u m e n t . c r e a t e E l e m e n t ( ' i m g ' ) ;  
  
 	 	 c a n v a s . s r c   =   p . s r c ;  
 	 	 c a n v a s . h e i g h t   =   p . h e i g h t ;  
 	 	 c a n v a s . w i d t h   =   5 0 ;  
  
 	 	 c a n v a s . s t y l e . f i l t e r   =   " p r o g i d : D X I m a g e T r a n s f o r m . M i c r o s o f t . M a t r i x ( M 1 1 = " + c o s t h e t a + " , M 1 2 = " + ( - s i n t h e t a ) + " , M 2 1 = " + s i n t h e t a + " , M 2 2 = " + c o s t h e t a + " , S i z i n g M e t h o d = ' a u t o   e x p a n d ' ) " ;  
 	 }   e l s e   {  
 	 	 v a r   c a n v a s   =   d o c u m e n t . c r e a t e E l e m e n t ( ' c a n v a s ' ) ;  
 	 	 i f   ( ! p . o I m a g e )   {  
 	 	 	 c a n v a s . o I m a g e   =   n e w   I m a g e ( ) ;  
 	 	 	 c a n v a s . o I m a g e . s r c   =   p . s r c ;  
 	 	 }   e l s e   {  
 	 	 	 c a n v a s . o I m a g e   =   p . o I m a g e ;  
 	 	 }  
  
 	 	 c a n v a s . s t y l e . w i d t h   =   c a n v a s . w i d t h   =   M a t h . a b s ( c o s t h e t a * c a n v a s . o I m a g e . w i d t h )   +   M a t h . a b s ( s i n t h e t a * c a n v a s . o I m a g e . h e i g h t ) ;  
 	 	 c a n v a s . s t y l e . h e i g h t   =   c a n v a s . h e i g h t   =   M a t h . a b s ( c o s t h e t a * c a n v a s . o I m a g e . h e i g h t )   +   M a t h . a b s ( s i n t h e t a * c a n v a s . o I m a g e . w i d t h ) ;  
  
 	 	 v a r   c o n t e x t   =   c a n v a s . g e t C o n t e x t ( ' 2 d ' ) ;  
 	 	 c o n t e x t . s a v e ( ) ;  
 	 	 i f   ( r o t a t i o n   < =   M a t h . P I / 2 )   {  
 	 	 	 c o n t e x t . t r a n s l a t e ( s i n t h e t a * c a n v a s . o I m a g e . h e i g h t , 0 ) ;  
 	 	 }   e l s e   i f   ( r o t a t i o n   < =   M a t h . P I )   {  
 	 	 	 c o n t e x t . t r a n s l a t e ( c a n v a s . w i d t h , - c o s t h e t a * c a n v a s . o I m a g e . h e i g h t ) ;  
 	 	 }   e l s e   i f   ( r o t a t i o n   < =   1 . 5 * M a t h . P I )   {  
 	 	 	 c o n t e x t . t r a n s l a t e ( - c o s t h e t a * c a n v a s . o I m a g e . w i d t h , c a n v a s . h e i g h t ) ;  
 	 	 }   e l s e   {  
 	 	 	 c o n t e x t . t r a n s l a t e ( 0 , - s i n t h e t a * c a n v a s . o I m a g e . w i d t h ) ;  
 	 	 }  
 	 	 c o n t e x t . r o t a t e ( r o t a t i o n ) ;  
 	 	 c o n t e x t . d r a w I m a g e ( c a n v a s . o I m a g e ,   0 ,   0 ,   c a n v a s . o I m a g e . w i d t h ,   c a n v a s . o I m a g e . h e i g h t ) ;  
 	 	 c o n t e x t . r e s t o r e ( ) ;  
 	 }  
 	 c a n v a s . i d   =   p . i d ;  
 	 c a n v a s . a n g l e   =   p . a n g l e ;  
 	 p . p a r e n t N o d e . r e p l a c e C h i l d ( c a n v a s ,   p ) ;  
 }  
  
 / * *  
 *       X o a y   £n h   c ó   t h ê m   c á c   t h a m   s Ñ  Ù  r Ùn g   ,   Ù  d à i   c ça   £n h  
 * /  
 j Q u e r y . f n . r o t a t e W i t h C u s   =   f u n c t i o n ( a n g l e , s c a l e w i d t h ,   s c a l e h e i g h t )   {  
 	 v a r   p   =   t h i s . g e t ( 0 ) ;  
  
 	 / /   w e   s t o r e   t h e   a n g l e   i n s i d e   t h e   i m a g e   t a g   f o r   p e r s i s t e n c e  
 	 p . a n g l e   =   ( ( p . a n g l e = = u n d e f i n e d ? 0 : p . a n g l e )   +   a n g l e )   %   3 6 0 ;  
  
         / /   r o t a t i o n   l à   g ó c   t í n h   t h e o   r a d i a n  
 	 i f   ( p . a n g l e   > =   0 )   {  
 	 	 v a r   r o t a t i o n   =   M a t h . P I   *   p . a n g l e   /   1 8 0 ;  
 	 }   e l s e   {  
 	 	 v a r   r o t a t i o n   =   M a t h . P I   *   ( 3 6 0 + p . a n g l e )   /   1 8 0 ;  
 	 }  
 	 v a r   c o s t h e t a   =   M a t h . c o s ( r o t a t i o n ) ;  
 	 v a r   s i n t h e t a   =   M a t h . s i n ( r o t a t i o n ) ;  
  
 	 i f   ( d o c u m e n t . a l l   & &   ! w i n d o w . o p e r a )   {  
 	 / /   - - - -   t r ì n h   d u y Çt   I E  
 	 	 v a r   c a n v a s   =   d o c u m e n t . c r e a t e E l e m e n t ( ' i m g ' ) ;  
  
 	 	 c a n v a s . s r c   =   p . s r c ;  
 	 	 c a n v a s . h e i g h t   =   s c a l e h e i g h t ;  
 	 	 c a n v a s . w i d t h   =   s c a l e w i d t h ;  
 	 	  
 	 	 / /   c h Én h   v Ë  t r í   c h o   £n h   s i n h   r a   -   m ·c   Ën h   k o   c ó  
 	 	 c a n v a s . s t y l e . m a r g i n   =   " 2 p x   0   0   0 " ;  
 	 	  
 	 	 c a n v a s . s t y l e . f i l t e r   =   " p r o g i d : D X I m a g e T r a n s f o r m . M i c r o s o f t . M a t r i x ( M 1 1 = " + c o s t h e t a + " , M 1 2 = " + ( - s i n t h e t a ) + " , M 2 1 = " + s i n t h e t a + " , M 2 2 = " + c o s t h e t a + " , S i z i n g M e t h o d = ' a u t o   e x p a n d ' ) " ;  
 	 }   e l s e   {  
 	 / /   - - - -   t r ì n h   d u y Çt   f i r e   f o x  
 	 	 v a r   c a n v a s   =   d o c u m e n t . c r e a t e E l e m e n t ( ' c a n v a s ' ) ;  
 	 	 i f   ( ! p . o I m a g e )   {  
 	 	 	 c a n v a s . o I m a g e   =   n e w   I m a g e ( ) ;  
 	 	 	 c a n v a s . o I m a g e . s r c   =   p . s r c ;  
 	 	 }   e l s e   {  
 	 	 	 c a n v a s . o I m a g e   =   p . o I m a g e ;  
 	 	 }  
  
 	 	 c a n v a s . s t y l e . w i d t h   =   c a n v a s . w i d t h   =   M a t h . a b s ( c o s t h e t a * c a n v a s . o I m a g e . w i d t h )   +   M a t h . a b s ( s i n t h e t a * c a n v a s . o I m a g e . h e i g h t ) ;  
 	 	 c a n v a s . s t y l e . h e i g h t   =   c a n v a s . h e i g h t   =   M a t h . a b s ( c o s t h e t a * c a n v a s . o I m a g e . h e i g h t )   +   M a t h . a b s ( s i n t h e t a * c a n v a s . o I m a g e . w i d t h ) ;  
 	 	  
 	 	 v a r   c o n t e x t   =   c a n v a s . g e t C o n t e x t ( ' 2 d ' ) ;  
 	 	 c o n t e x t . s a v e ( ) ;  
 	 	 i f   ( r o t a t i o n   < =   M a t h . P I / 2 )   {  
 	 	         / /   n ¿u   0   <   g ó c   < =   9 0 o  
 	 	 	 c o n t e x t . t r a n s l a t e ( s i n t h e t a * c a n v a s . o I m a g e . h e i g h t , 0 ) ;  
 	 	 }   e l s e   i f   ( r o t a t i o n   < =   M a t h . P I )   {  
 	 	         / /   n ¿u   9 0 o   <   g ó c   < =   1 8 0 o  
 	 	 	 c o n t e x t . t r a n s l a t e ( c a n v a s . w i d t h , - c o s t h e t a * c a n v a s . o I m a g e . h e i g h t ) ;  
 	 	 }   e l s e   i f   ( r o t a t i o n   < =   1 . 5 * M a t h . P I )   {  
 	 	         / /   n ¿u   1 8 0 o   <   g ó c   < =   2 7 0 o  
 	 	 	 c o n t e x t . t r a n s l a t e ( - c o s t h e t a * c a n v a s . o I m a g e . w i d t h , c a n v a s . h e i g h t ) ;  
 	 	 }   e l s e   {  
 	 	         / /   n ¿u   2 7 0 o   <   g ó c   < =   3 6 0 o  
 	 	 	 c o n t e x t . t r a n s l a t e ( 2 , - s i n t h e t a * c a n v a s . o I m a g e . w i d t h - 7 ) ;  
 	 	 }  
 	 	 c o n t e x t . r o t a t e ( r o t a t i o n ) ;  
 	 	 / / c o n t e x t . d r a w I m a g e ( c a n v a s . o I m a g e ,   0 ,   0 ,   c a n v a s . o I m a g e . w i d t h ,   c a n v a s . o I m a g e . h e i g h t ) ;  
 	 	 c o n t e x t . d r a w I m a g e ( c a n v a s . o I m a g e ,   0 ,   0 ,   s c a l e w i d t h ,   s c a l e h e i g h t ) ;  
 	 	 c o n t e x t . r e s t o r e ( ) ;  
 	 }  
 	 c a n v a s . i d   =   p . i d ;  
 	 c a n v a s . a n g l e   =   p . a n g l e ;  
 	 p . p a r e n t N o d e . r e p l a c e C h i l d ( c a n v a s ,   p ) ;  
 }  
  
 j Q u e r y . f n . r o t a t e R i g h t   =   f u n c t i o n ( a n g l e )   {  
 	 t h i s . r o t a t e ( a n g l e = = u n d e f i n e d ? 9 0 : a n g l e ) ;  
 }  
  
 j Q u e r y . f n . r o t a t e L e f t   =   f u n c t i o n ( a n g l e )   {  
 	 t h i s . r o t a t e ( a n g l e = = u n d e f i n e d ? - 9 0 : - a n g l e ) ;  
 } 
