/*
 * public class JSVM
 * Author: Matthew Copeland
 * Versions:
 *  v1.0 (280102)
 * Language: Javascript 1.0
 */

JSVM = new Object ( ) ; // class object for JSVM
JSVM . updatables = [ ] ; // static array of updatable objects
JSVM . timeout_ID = null ; // static field for timeout_ID returned by 'window . setTimeout ( )'
JSVM . timeout_milliseconds = 0 ; // static field for millisecond pause argument in 'window . setTimeout ( )'
JSVM . add_Updatable = JSVM_add_Updatable ; // public method for registering an 'Updatable' object with the JSVM
JSVM . start = JSVM_start ; // public method to invoke the JSVM
JSVM . update = JSVM_update ; // public method to run the JSVM
JSVM . stop = JSVM_stop ; // public method to stop the JSVM

function JSVM_add_Updatable ( updatable )
{ JSVM . updatables [ JSVM . updatables . length ] = updatable ;
}
function JSVM_start ( )
{ if ( JSVM . timeout_ID == null )
  { JSVM . update ( ) ;
  }
}
function JSVM_update ( )
{ var x = 0 ;
  while ( x < JSVM . updatables . length )
  { JSVM . updatables [ x ++ ] . update ( ) ;
  }
  JSVM . timeout_ID = window . setTimeout ( 'JSVM.update()' , JSVM . timeout_milliseconds ) ;
}
function JSVM_stop ( )
{ if ( JSVM . timeout_ID == null )
  { return ;
  }
  window . clearTimeout ( JSVM . timeout_ID ) ;
  JSVM . timeout_ID = null ;
}

window . onload = JSVM . start ;
window . onunload = JSVM . stop ;

/*
 *
 * public interface Updatable
 * { public void update ( ) ;
 * }
 *
 */