      var input = null;
      var looker = null;
      var d = document;
      
      var ie = false;

      function init() {
        input = d.getElementById('search');
        looker = d.getElementById('looker');

        // This helps spread out the advertisments a bit so the aren't all
        // ugly and clumbed together.
        var advertCell = d.getElementById('advertCell');
        var advertTable = d.getElementById('advertTable');
        if (advertTable) {  // If there is no query, we don't show the advert table
          advertTable.style.height = (advertCell.offsetHeight - 30) + 'px';
        }
        
        if (navigator.appVersion.indexOf('MSIE') != -1) { ie = true; }

        // We have to turn off border-collapse
        if (ie) { // Aiya...
          nav = d.getElementById('navTable');
          nav.className = 'blank';
        }
        
        Update();
      }

      // Get all the cells out of the way
      function ClearAll() {
        Hide("romajiRow", "romajiCell");
        Hide("hiraRow", "hiraCell");
        Hide("kanaRow", "kanaCell");
        
        ClearKanji();
      }
      
      // Get all the kanji cells out of the way
      function ClearKanji() {
        Hide('kanjiRow0', 'kanjiCell0');
        Hide('kanjiRow1', 'kanjiCell1');
        Hide('kanjiRow2', 'kanjiCell2');
        
        Hide('glossRow0_0', 'glossCell0_0');
        Hide('glossRow0_1', 'glossCell0_1');
        Hide('glossRow0_2', 'glossCell0_2');

        Hide('glossRow1_0', 'glossCell1_0');
        Hide('glossRow1_1', 'glossCell1_1');
        Hide('glossRow1_2', 'glossCell1_2');

        Hide('glossRow2_0', 'glossCell2_0');
        Hide('glossRow2_1', 'glossCell2_1');
        Hide('glossRow2_2', 'glossCell2_2');

        Hide("moreRow", "moreCell");
      }


      // Updates the quick links if the text box has changed
      var oldText = "";
      function Update() {
        var curText;
        if (!input || oldText == (curText = input.value)) { 
          setTimeout('Update()', 1000);
          return;
        }
        
        if (curText == "" || curText == "type here...") {
          ClearAll();
        } else {
          
          var dc = (looker.contentDocument) ? (looker.contentDocument): ((looker.contentWindow)?(looker.contentWindow.document):(self.frames['looker'].document))
          dc.getElementById('query').setAttribute('value', curText);
          dc.getElementById('ajax').submit();
        }
        
        oldText = curText;
        setTimeout('Update()', 1000);
      }
      
      var AnimRows = new Array();    // maps rows' ids to { c: cellObject, t: (0 for contract, 1 for expand) }
      var AnimSize = new Array();    // maps rows' ids to current hight in em's
      
      // 0: Animaitons are complete, 1: Animations pending
      var animate = 0;
      
      // Hide a cell
      function Hide(row, cell) {
        if (!AnimSize[row]) { AnimSize[row] = 0.5; }
        AnimRows[row] = { c: d.getElementById(cell), t: 0 };
        if (!animate) { Animate(); }
      }

      // Show a cell
      function Show(row, cell, value, link) {
        if (!value) { value = ""; }
        cell = d.getElementById(cell);
        
        SetCellValue(cell, value, link);
        if (!AnimSize[row]) { AnimSize[row] = 0.3; }
        AnimRows[row] = { c: cell, t: 1 };
        
        tr = d.getElementById(row);
        if (ie) {  // Sigh...
          tr.style.display = 'block';        
        } else {
          tr.style.display = 'table-row';
        }

        
        morecell = d.getElementById('moreCell');
        if (!AnimSize['moreRow']) { AnimSize['moreRow'] = 0.3; }
        AnimRows['moreRow'] = { c: morecell, t: 1 };
        
        tr = d.getElementById('moreRow');
        if (ie) {  // Sigh...
          tr.style.display = 'block';        
        } else {
          tr.style.display = 'table-row';
        }

        if (!animate) { Animate(); }
      }
      
      // The animation's tick method for expanding/contracting cells
      function Animate() {
        animate = 1;
        done = 1;
        for (row in AnimRows) {
          var tr = d.getElementById(row);
          var attrs = AnimRows[row];
          target = attrs.t;
          cell = attrs.c;
          if (target == 0) {
            if (AnimSize[row] / 1.5 <= 0.3) {
              AnimSize[row] = 0.3;
              cell.style.fontSize = '0.3em';
              tr.style.display = 'none';
              delete AnimRows[row];
            } else {
              AnimSize[row] /= 1.5;
              done = 0;
              cell.style.fontSize = AnimSize[row] + "em";
            }
          } else {
            if (AnimSize[row] * 1.5 >= 1 ) {
              AnimSize[row] = 1;
              cell.style.fontSize = '1em';
              delete AnimRows[row];
            } else {
              AnimSize[row] *= 1.5;
              done = 0;
              cell.style.fontSize = AnimSize[row] + "em";
            }
          }
        }
        if (!done) {          
          setTimeout('Animate()', 40);      
        } else {
          animate = 0;
        }
      }

      // Highlight a cell      
      function H(cell) {
        cell.style.backgroundImage = "url(/images/tallyellow.jpg)";
        cell.style.backgroundColor = "#F4FBDC";
        if (cell.className != 'sideinfo') {
          var imgs = cell.getElementsByTagName('img');
          for (var idx = 0; idx < imgs.length; idx++) {
            imgs[idx].src = imgs[idx].src.replace("Blue", "Yellow");
          }
        }
      }

      // Unhighlight a cell
      function U(cell) {
        if (cell.className == 'sideinfo') {
          cell.style.backgroundImage = "url(/images/shortcyan.jpg)";
          cell.style.backgroundColor = "#D1E2FF";
        } else {
          cell.style.backgroundImage = "url(/images/shortblue.jpg)";
          cell.style.backgroundColor = "#77A7FB";
          var imgs = cell.getElementsByTagName('img');
          for (var idx = 0; idx < imgs.length; idx++) {
            imgs[idx].src = imgs[idx].src.replace("Yellow", "Blue");
          }
        }
      }
      
      // Get a cell's value (taking nested elements into account)
      function GetCellValue(cell) {
        if (cell.link) { return cell.link; }
        if (cell.className == 'sideinfo') {
          return cell.firstChild.firstChild.innerHTML;        
        } else {
          return cell.innerHTML;
        }      
      }

      // Set a cell's value (taking nested elements into account)
      function SetCellValue(cell, value, link) {
        if (!value) { value = ""; }
        cell.link = link;
        if (cell.className == 'sideinfo') {
          cell.firstChild.firstChild.innerHTML = value;
        } else {
          cell.innerHTML = value;
        }      
      }
      
      // Load a clicked cell into the form and submit it
      function L(cell) {
        var url = "search.tofu?kanji=" + escape("&#28450;&#23383;") + "&query=" + escape(GetCellValue(cell));
        var format = d.getElementById('format');
        if (format) { url += "&format=" + format.value; }        
        var locale = d.getElementById('locale');
        if (locale) { url += "&locale=" + locale.value; }        
        document.location.href = url;
      }
