finished arachnid rocketgum
[ephemerata.git] / ArachnidRocketgum / web / static / js / rocket.js
blob290e5ea5aaaba612adedcff4f5f7b2e88fb608b8
1 var initial = 15000;
2 var pause = 10000;
3 var delta = 100;
5 function faster() {
6 if (delta > 1)
7 delta >>= 1;
10 function slower() {
11 if (delta < 10000000)
12 delta <<= 1;
15 function longer() {
16 if (pause < 1000000)
17 pause <<= 1;
20 function shorter() {
21 if (pause > 1)
22 pause >>= 1;
25 function MWJ_findObj( oName, oFrame, oDoc ) {
26 /* MWJ_findObj function got from
27 * http://www.howtocreate.co.uk/tutorials/javascript/elementcontents
29 * if not working on a layer, document should be set to the
30 * document of the working frame
31 * if the working frame is not set, use the window object
32 * of the current document
33 * WARNING: - cross frame scripting will cause errors if
34 * your page is in a frameset from a different domain */
35 if( !oDoc ) { if( oFrame ) { oDoc = oFrame.document; } else { oDoc = window.document; } }
37 //check for images, forms, layers
38 if( oDoc[oName] ) { return oDoc[oName]; }
40 //check for pDOM layers
41 if( oDoc.all && oDoc.all[oName] ) { return oDoc.all[oName]; }
43 //check for DOM layers
44 if( oDoc.getElementById && oDoc.getElementById(oName) ) {
45 return oDoc.getElementById(oName); }
47 //check for form elements
48 for( var x = 0; x < oDoc.forms.length; x++ ) {
49 if( oDoc.forms[x][oName] ) { return oDoc.forms[x][oName]; } }
51 //check for anchor elements
52 //NOTE: only anchor properties will be available,
53 //NOT link properties (in layers browsers)
54 for( var x = 0; x < oDoc.anchors.length; x++ ) {
55 if( oDoc.anchors[x].name == oName ) {
56 return oDoc.anchors[x]; } }
58 //check for any of the above within a layer in layers browsers
59 for( var x = 0; document.layers && x < oDoc.layers.length; x++ ) {
60 var theOb = MWJ_findObj( oName, null, oDoc.layers[x].document );
61 if( theOb ) { return theOb; } }
63 //check for frames, variables or functions
64 if( !oFrame && window[oName] ) { return window[oName]; }
65 if( oFrame && oFrame[oName] ) { return oFrame[oName]; }
67 //if checking through frames, check for any of the above within
68 //each child frame
69 for( var x = 0; oFrame && oFrame.frames && x < oFrame.frames.length; x++ ) {
70 var theOb = MWJ_findObj( oName, oFrame.frames[x], oFrame.frames[x].document ); if( theOb ) { return theOb; } }
72 return null;
75 var itersLeft = 0;
76 var set = 0;
78 function go() {
79 var theOb = MWJ_findObj( 'your_mom' );
80 for (i = 0; i < setSize; i++) {
81 var newdiv = document.createElement('span');
82 newdiv.setAttribute('id', 'thing_' + i);
83 newdiv.setAttribute('class', margins[i]);
84 newdiv.innerHTML = contents[0][i][0];
85 theOb.appendChild(newdiv);
86 wordsLeft[i] = contents[0][i].length - 1;
87 itersLeft += wordsLeft[i];
89 setTimeout(iterate, initial);
92 function iterate() {
93 if (itersLeft == 0) {
94 set = (set + 1) % sets;
95 for (i = 0; i < setSize; i++) {
96 wordsLeft[i] = contents[set][i].length - 1;
97 itersLeft += wordsLeft[i];
99 setTimeout(iterate, pause);
100 return;
103 var ind = Math.floor(Math.random() * itersLeft);
104 var i = findIndex(ind);
105 var newdiv = MWJ_findObj('thing_' + i);
107 var index = contents[set][i].length - wordsLeft[i];
108 if (index <= 0) {
109 alert("too small @" + i);
111 if (index >= contents[set][i].length) {
112 alert("too big @" + i);
114 newdiv.innerHTML = contents[set][i][index];
116 wordsLeft[i]--;
117 itersLeft--;
118 setTimeout(iterate, delta);
121 function findIndex(ind) {
122 var count = wordsLeft[0];
123 var i = 0;
124 while (count <= ind) {
125 i++;
126 count += wordsLeft[i];
128 return i;