/* Control Tab Open
 *   nanto_vi (TOYAMA Nao), 2006-12-30
 *
 * Swaps the functions of the Ctrl key and the Alt key 
 * on the URL bar and the search bar.
 */

(function ControlTabOpen() {

var newCodes = ["data:application/javascript,"];

changeModifier("BrowserLoadURL");
changeModifier("canonizeUrl");
changeModifier("document.getElementById('searchbar').handleSearchCommand");

Cc["@mozilla.org/moz/jssubscript-loader;1"]
  .createInstance(Ci.mozIJSSubScriptLoader)
  .loadSubScript(encodeURI(newCodes.join("")));

function changeModifier(target) {
  var keyMap = { altKey: "ctrlKey", ctrlKey: "altKey" };
  newCodes.push(target, "=",
                eval(target).toSource().replace(/\b(?:alt|ctrl)Key\b/g,
                  function (oldKey) { return keyMap[oldKey]; }),
                ";");
}

})();
