function getUbiquity(){
  var mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                     .getInterface(Components.interfaces.nsIWebNavigation)
                     .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
                     .rootTreeItem
                     .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
                     .getInterface(Components.interfaces.nsIDOMWindow);
  
  return mainWindow.gUbiquity;  
}


CmdUtils.CreateCommand({
  name: "ms",
  takes: {"special": noun_arb_text}, // important that it is not called search or we get a recursive problem
  homepage: "http://larswolter.de/",
  author: { name: "Lars Wolter", email: "lars@larswolter.de"},
  license: "MPL",
  description: " UNDER DEVELOPMENT - Searches multiple sources at once and previews there results",
  help: "The command looks thru all your commands if it is a search command." +
        " It then uses all of them to present previews of all. ",


  preview: function( pblock, searchterm ) {
    var globals = CmdUtils;
    var msg = "Multisearch uses all availbale search commands to search for your word";
    var count = 0;
    if(!searchterm.text)
    {
        pblock.innerHTML = CmdUtils.renderTemplate( msg );
        return;
    }
    pblock.innerHTML = "";
    // a fullframe mode would be nice for that, but a bg height is enough
//    pblock.style.width = "1000px";
//    pblock.style.height = "500px";
    pblock.style.fontSize = "0.8em";
    pblock.style.overflow = "auto";

    // create a node that holds the preview of a single command
    // they are all floating so that they use the available space
    var ubiq = getUbiquity();
    var cmds = {
      "google": {},
      "image-search": {},
      "wikipedia": {in:"de"},
      "flickr": {},
      "yahoo-search":{},
    }
    for (cmdName in cmds )//ubiq.__cmdManager.__cmdSource.getAllCommands())
    {
      var cmd = ubiq.__cmdManager.__cmdSource.getCommand( cmdName );  
      if(!cmd || !cmd.preview)
        continue;
      var elem = CmdUtils.getDocument().createElement('div');
      elem.style.marginBottom= "5px";
      elem.style.maxHeight = "100px";
      elem.style.overflow = "hidden";
      /*
      var node = CmdUtils.getDocument().createElement('div');
     
      for (var i = 0; i < cmdName.length; i++)
        node.innerHTML += cmdName[i]+"<br />";
      node.style.position= "absolute";
      node.style.maxHeight = "100px";
      node.style.overflow = "hidden";
      elem.appendChild(node);*/
      var node = CmdUtils.getDocument().createElement('div');
      node.style.marginLeft= "10px";
      elem.appendChild(node);
     
      pblock.appendChild(elem);    
      cmd.preview({}, searchterm, cmds[cmdName], node );
    }

  },

  execute: function() {
    // nothing here.... how to choose the result that must be decided...
  }
})
