ddLoaded = false; try { if (dd != undefined) ddLoaded = true; } catch (err) { // do nothing } if (ddLoaded) { SET_DHTML("8ball"+CURSOR_HAND); // store a reference to this object answerBox = document.getElementById('answer_box'); answerTxt = document.getElementById('answer_text'); eball = dd.elements['8ball']; // output the necessary HTML document.write('
\n'); eball.swapImage('/oracle/before-poppet.gif'); eball.setCursor(CURSOR_HAND); // keep track of shacking max_x = 0; max_y = 0; dragged = 0; function my_PickFunc() { answerBox.style.display = 'none'; // reset max_x = 0; max_y = 0; dragged = 0; fade_level = 1.0; fade_direction = -0.1; } function my_DragFunc() { // when they drag, swap the image with the during state if (dragged == 0) { eball.swapImage('/oracle/during-poppet.gif'); dragged = 1; } if ( Math.abs(eball.x - eball.defx) > max_x) max_x = Math.abs(eball.x - eball.defx); if ( Math.abs(eball.y - eball.defy) > max_y) max_y = Math.abs(eball.y - eball.defy); } fade_level = 1.0; fade_direction = -0.1; function fade() { fade_level += fade_direction; if (fade_level <= 0.1 || fade_level >= 1.0) { fade_direction *= -1; } eball.setOpacity(fade_level); } function my_DropFunc() { // only do something if they actually shook it if ( max_x > 5 && max_y > 5) { // swap the image with the after state eball.swapImage('/oracle/after-poppet.gif'); // move it back to where it was eball.moveTo(eball.defx, eball.defy); eball.setZ(1); // get a sentence var url = "/oracle/get_answer.php?sid=" + Math.random(); if (xmlhttp) { document.body.style.cursor = 'wait'; eball.setCursor(CURSOR_WAIT); thisFade = setInterval("fade()", 40); xmlhttp.open("GET", url, true); xmlhttp.onreadystatechange = function () { if (xmlhttp.readyState == 4) { // get result string and turn it into key and answer answer = xmlhttp.responseText; if ( answer.indexOf("Fatal error") != -1 ) { answer = "Ask again later." } // update the DOM! answerTxt.innerHTML = answer; answerBox.style.display = 'block'; // put cursors back document.body.style.cursor = 'auto'; eball.setCursor(CURSOR_HAND); // turn off throbbing clearInterval(thisFade); eball.setOpacity(1.0); } }; xmlhttp.send(null); } } else { eball.moveTo(eball.defx, eball.defy); eball.setZ(1); answerTxt.innerHTML = "YOU HAVE TO ACTUALLY SHAKE IT."; answerBox.style.display = 'block'; } } }