// ==UserScript==
// @name          Customize Digg
// @namespace     http://loucypher.wordpress.com/
// @include       http://digg.com/*
// @include       http://www.digg.com/*
// @description	  custom
// ==/UserScript==

var topics = document.evaluate('//div[@class="news-summary" or @class="news-short-summary"]',
  document, null, 6, null);

if(!topics) return;

var contentDiv = document.evaluate('//div[@id="contents" or @id="contents-user"]',
  document, null, 0, null).iterateNext();

if(!contentDiv) return;

var newDiv = document.createElement('div');
newDiv.setAttribute('style', 'max-height: 400px; overflow: auto;');

contentDiv.insertBefore(newDiv, contentDiv.firstChild);

for(var i = 0; i < topics.snapshotLength; i++) {
  var topic = topics.snapshotItem(i);
  newDiv.appendChild(topic.nextSibling);
  newDiv.appendChild(topic);
}

var tnavs = document.evaluate('//div[@id="sidebar"]//ul[@class="tab-nav"]',
  document, null, 6, null);

var tcontents = document.evaluate('//div[@id="sidebar"]//div[@class="tab-contents"]',
  document, null, 6, null);

for(var j = 0; j < tnavs.snapshotLength; j++) {
  var tnav = tnavs.snapshotItem(j);
  var tctn = tcontents.snapshotItem(j);
  tctn.style.display = 'none';
  tnav.addEventListener('click', function(e) {
    var tctn = this.parentNode.getElementsByTagName('div')[0];
    tctn.style.display = (tctn.style.display == 'none')?'':'none';
  }, false);
  tnav.style.cursor = 'pointer';
}

