Special Ops 2.50
[specialops2.git] / js / global.js
blobed98f89acb48bfeb2c7923773c7c0bed2e05282c
1 // Container for timed events
2 var timers = {
3     rate: 4 * 1000,      // default loop delay in ms
4     loop: 0,             // Count how many times it's looped
5     things: Array(),     // functions to be called go into this array
6     update: function() { // calls all of the array functions
7         for ( var i = 0, j = timers.things.length; i < j; i++ ) {
8             timers.things[i]();
9         }
10         if ( timers.things.length ) { // Don't bother if there's nothing to run
11             setTimeout(timers.update, timers.rate);
12         }
13         timers.loop++;
14     }
17 // Start the event timer
18 function startTimer() {
19     setTimeout(timers.update, timers.rate);
21 window.addEventListener('load', startTimer, false);