    $(document).ready(function() {

      $('#jsddm > li').bind('mouseover', jsddm_open)
      $('#jsddm > li').bind('mouseout',  jsddm_timer)

      $("#hcsubmit").click(function() {
        $data = $("#hashes").val(); $rows = $data.split("\n");
        $count = $rows.length; $f = 0; $n = 0; $t = 0; $s_per = 0;
        $stime = new Date().getTime();

        $('#f_results').val(''); $('#n_results').val('');
        $('#f_count').text(''); $('#n_count').text('');
        $('#hashes').attr("readonly", true); $('#hashes').css("color","#aaa");
        $('#hcspan').text('Processing...');
        $('#hcsubmit').attr("disabled", true);
        $('#loading').attr("src","/img/loading.gif");

        $.each($rows, function(key, value) {

          $.ajax({
            async: true,
            url: 'http://www.tmto.org/api/latest/',
            data: {'hash': value, 'auth':'true' },
            dataType: 'xml',
            beforeSend:  function() { },

            success: function(xml) {
              $(xml).find("result").each(function() {
                $text = $.base64Decode($(this).attr("text"));
                $hash = $(this).attr("hash");
                if($text=="") {
                  $text = "NotFound";
                } else {
                  $text = $text.replace(/ /gi, "[space]");
                }

                if($text!="NotFound") {
                  $('#f_results').val($('#f_results').val() + $hash + ':' + $text + '\n');
                  $f++;
                  $('#f_count').text('(' + $f + ')');
                } else {
                  $('#n_results').val($('#n_results').val() + $hash + '\n');
                  $n++;
                  $('#n_count').text('(' + $n + ')');
                }
              });
            },

            complete: function() {
              $t++;
              if($t != $count ) {
                $s_per = ($f / $count) * 100;
                $('#processed').html('Processed ' + $t + ' of ' + $count + '<br /><br />Success Rate: ' + $s_per.toFixed(2) + '%');
                $('#title').text('Processed ' + $t + ' of ' + $count);
              } else {
                $etime = ((new Date().getTime() - $stime) / 1000);
                $atime = ($etime / $count);
                $('#processed').html('Processed ' + $count + ' hashes<br />in ' + $etime.toFixed(2) + ' secs.<br />Per Hash: ' + $atime.toFixed(2) + ' secs. <br /><br />Success Rate: ' + $s_per.toFixed(2) + '%');
                $('#title').text('Done. Processed ' + $count + ' hashes');
                $('#hashes').attr("readonly", false);
                $('#hashes').css("color","#000");
                $('#hcsubmit').attr("disabled", false);
                $('#hcspan').text('Decrypt');
                $('#loading').attr("src","/img/empty.gif");
              }
            }

          });

        });

      });

      $("#multihcsubmit").click(function() {
        $data = $("#hashes").val(); $rows = $data.split("\n");
        $count = $rows.length; $f = 0; $n = 0; $t = 0; $s_per = 0;
        $stime = new Date().getTime();

        $('#f_results').val(''); $('#n_results').val('');
        $('#f_count').text(''); $('#n_count').text('');
        $('#hashes').attr("readonly", true); $('#hashes').css("color","#aaa");
        $('#hcspan').text('Processing...');
        $('#hcsubmit').attr("disabled", true);
        $('#loading').attr("src","/img/loading.gif");

        $.each($rows, function(key, value) {

          $.ajax({
            async: true,
            url: 'http://www.tmto.org/api/v7.0/index.php',
            data: {'hash': value, 'auth':'true' },
            dataType: 'xml',
            beforeSend:  function() { },

            success: function(xml) {
              $(xml).find("result").each(function() {
                $text = $.base64Decode($(this).attr("text"));
                $type = $(this).attr("type");
                $hash = $(this).attr("hash");
                if($text=="") {
                  $text = "NotFound";
                } else {
                  $text = $text.replace(/ /gi, "[space]");
                }

                if($text!="NotFound") {
                  $('#f_results').val($('#f_results').val() + $type + ':' + $hash + ':' + $text + '\n');
                  $f++;
                  $('#f_count').text('(' + $f + ')');
                } else {
                  $('#n_results').val($('#n_results').val() + $type + $hash + '\n');
                  $n++;
                  $('#n_count').text('(' + $n + ')');
                }
              });
            },

            complete: function() {
              $t++;
              if($t != $count ) {
                $s_per = ($f / $count) * 100;
                $('#processed').html('Processed ' + $t + ' of ' + $count + '<br /><br />Success Rate: ' + $s_per.toFixed(2) + '%');
                $('#title').text('Processed ' + $t + ' of ' + $count);
              } else {
                $etime = ((new Date().getTime() - $stime) / 1000);
                $atime = ($etime / $count);
                $('#processed').html('Processed ' + $count + ' hashes<br />in ' + $etime.toFixed(2) + ' secs.<br />Per Hash: ' + $atime.toFixed(2) + ' secs. <br /><br />Success Rate: ' + $s_per.toFixed(2) + '%');
                $('#title').text('Done. Processed ' + $count + ' hashes');
                $('#hashes').attr("readonly", false);
                $('#hashes').css("color","#000");
                $('#hcsubmit').attr("disabled", false);
                $('#hcspan').text('Decrypt');
                $('#loading').attr("src","/img/empty.gif");
              }
            }

          });

        });

      });

    });

    document.onclick = jsddm_close;


