// ==UserScript==
// @author        mungushume
// @version       1.1
// @name          Two Column Google (row-wise)
// @namespace     mungushume_@_hotmail_._com
// @description   Places Google search results into two columns row-wise. Based on the original idea by Jeffrey Sharkey
// @include       http://www.google.*/search*
// @include       http://google.*/search*
// @scriptsource   http://userscripts.org/scripts/show/8477
// ==/UserScript==

// New in v1.1 numbering of the results

var table = document.createElement("table");
table.setAttribute("cellspacing", "0");
table.setAttribute("cellpadding", "0");

var cols=2;

var links = [], link, row;

//links = document.evaluate("//div[@class='g']", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
//var parent=links.snapshotItem(0).parentNode;

var elms = document.getElementsByTagName('div');
for(var i = 0; i < elms.length; i++) {
  if(elms[i].className == 'g'){
	links.push(elms[i]);
  }
}
var parent = links[0].parentNode;

for(var i = 0; i < links.length; i++) {
  link = links[i];
  link.innerHTML="<strong>"+(i+1)+" </strong>"+link.innerHTML;

  if(i%cols==0){
  	row = table.insertRow(Math.floor(i/cols));
  }
  
  var cell = row.insertCell(i%cols);

  cell.setAttribute("valign", "top");

  cell.appendChild(link);
}

parent.appendChild(table);

