ÿþ/ /   a n i m a t i o n   o b j e c t   h o l d s   n u m e r o u s   p r o p e r t i e s   r e l a t e d   t o   m o t i o n  
  
 v a r   a n i m e ;  
  
 / / i n i t i a l i z e   d e f a u l t   a n i m e   o b j e c t  
 f u n c t i o n   i n i t A n i m e ( )   {  
         a n i m e   =   { e l e m I D : " " ,  
                 x C u r r : 0 ,  
                 y C u r r :   0 ,  
                 x C u r r t e m p :   0 ,  
                 y C u r r t e m p :   0 ,  
                 x T a r g : 0 ,  
                 y T a r g : 0 ,  
                 x S t e p : 0 ,  
                 y S t e p : 0 ,  
                 x D e l t a : 0 ,  
                 y D e l t a : 0 ,  
                 x T r a v e l : 0 ,  
                 y T r a v e l : 0 ,  
                 v e l : 1 ,  
                 p a t h L e n : 1 ,  
                 i n t e r v a l : n u l l  
         } ;  
 }  
  
 / / s t u f f   a n i m a t i o n   o b j e c t   w i t h   n e c e s s a r y   e x p l i c i t   a n d   c a l c u l a t e d   v a l u e s  
 f u n c t i o n   i n i t S L A n i m e ( e l e m I D ,   s t a r t X ,   s t a r t Y ,   e n d X ,   e n d Y ,   s p e e d )   {  
         i n i t A n i m e ( ) ;  
         a n i m e . e l e m I D   =   e l e m I D ;  
         a n i m e . x C u r r   =   s t a r t X ;  
         a n i m e . y C u r r   =   s t a r t Y ;  
         a n i m e . x T a r g   =   e n d X ;  
         a n i m e . y T a r g   =   e n d Y ;  
         a n i m e . x D e l t a   =   M a t h . a b s ( e n d X   -   s t a r t X ) ;  
         a n i m e . y D e l t a   =   M a t h . a b s ( e n d Y   -   s t a r t Y ) ;  
         a n i m e . v e l   =   ( s p e e d )   ?   s p e e d   :   1 ;  
         / / g e t   w i d t h   o f   e l e m e n t  
 / /         v a r   e l e m w i d t h   =   M a t h . a b s ( p a r s e I n t ( d o c u m e n t . g e t E l e m e n t B y I d ( e l e m I D ) . s t y l e . r i g h t )   -   p a r s e I n t ( d o c u m e n t . g e t E l e m e n t B y I d ( e l e m I D ) . s t y l e . l e f t ) ) ;  
         / /   s e t   e l e m e n t ' s   s t a r t   p o s i t i o n  
         d o c u m e n t . g e t E l e m e n t B y I d ( e l e m I D ) . s t y l e . l e f t   =   s t a r t X   +   " p x " ;  
         d o c u m e n t . g e t E l e m e n t B y I d ( e l e m I D ) . s t y l e . t o p   =   s t a r t Y   +   " p x " ;  
         / /   t h e   l e n g t h   o f   t h e   l i n e   b e t w e e n   t h e   s t a r t   a n d   e n d   p o i n t s  
         a n i m e . p a t h L e n   =   M a t h . s q r t ( ( M a t h . p o w ( ( s t a r t X   -   e n d X ) ,   2 ) )   +   ( M a t h . p o w ( ( s t a r t Y   -   e n d Y ) ,   2 ) ) ) ;  
         / / h o w   b i g   t h e   p i x e l   s t e p s   a r e   a l o n g   t h e   w a y  
         a n i m e . x S t e p   =   p a r s e I n t ( ( ( a n i m e . x T a r g   -   a n i m e . x C u r r )   /   a n i m e . p a t h L e n )   *   a n i m e . v e l ) ;  
         a n i m e . y S t e p   =   p a r s e I n t ( ( ( a n i m e . y T a r g   -   a n i m e . y C u r r )   /   a n i m e . p a t h L e n )   *   a n i m e . v e l ) ;  
         / / s t a r t   t h e   r e p e a t e d   i n v o c a t i o n   o f   t h e   a n i m a t i o n  
         a n i m e . i n t e r v a l   =   s e t I n t e r v a l ( " d o S L A n i m a t i o n ( ) " ,   1 0 ) ;  
 }  
  
 / / c a l c u l a t e   n e x t   s t e p s   a n d   a s s i g n   t o   s t y l e   p r o p e r t i e s  
 f u n c t i o n   d o S L A n i m a t i o n ( )   {  
         i f   ( ( a n i m e . x T r a v e l   +   a n i m e . x S t e p )   < =   a n i m e . x D e l t a   & &  
                 ( a n i m e . y T r a v e l   +   a n i m e . y S t e p )   < =   a n i m e . y D e l t a )   {  
                 v a r   x   =   a n i m e . x C u r r   +   a n i m e . x S t e p ;  
                 v a r   y   =   a n i m e . y C u r r   +   a n i m e . y S t e p ;  
                 d o c u m e n t . g e t E l e m e n t B y I d ( a n i m e . e l e m I D ) . s t y l e . l e f t   =   x   +   " p x " ;  
                 d o c u m e n t . g e t E l e m e n t B y I d ( a n i m e . e l e m I D ) . s t y l e . t o p   =   y   +   " p x " ;  
                 a n i m e . x T r a v e l   + =   M a t h . a b s ( a n i m e . x S t e p ) ;  
                 a n i m e . y T r a v e l   + =   M a t h . a b s ( a n i m e . y S t e p ) ;  
                 a n i m e . x C u r r   =   x ;  
                 a n i m e . y C u r r   =   y ;  
         }   e l s e   {  
                 d o c u m e n t . g e t E l e m e n t B y I d ( a n i m e . e l e m I D ) . s t y l e . l e f t   =   a n i m e . x T a r g   +   " p x " ;  
                 d o c u m e n t . g e t E l e m e n t B y I d ( a n i m e . e l e m I D ) . s t y l e . t o p   =   a n i m e . y T a r g   +   " p x " ;  
                 c l e a r I n t e r v a l ( a n i m e . i n t e r v a l ) ;  
         }  
 }  
 a d d O n L o a d E v e n t ( i n i t A n i m e ) ; 
