// ==UserScript==
// @namespace     http://www.yogurtearl.com/
// @name          Consumerist Nested Comments
// @description   Nests reply comments inside the parent in the consumerist
// @description   Copyright 2008 YogurtEarl yogurtearl+consumerist@gmail.com
// @version       0.10
// @include       http://consumerist.com/*
// @include       http://www.consumerist.com/*
// @include       http://lifehacker.com/software/*
// @include       http://www.lifehacker.com/software/*
// ==/UserScript==

window.addEventListener("load", function(e) {

if (typeof unsafeWindow !== "undefined"){
$$ = unsafeWindow.$$;
$ = unsafeWindow.$;
}
if($$){
var comments  = $$('.comment[id]');
var commentIDs = [];
for ( var i in comments ){
  if (comments[i].id) {
    commentIDs.push(comments[i].id);
  }
}

var url = $$("div.post h1 a")[0].href;
for ( var i in commentIDs ){
    var comment = $(commentIDs[i]);
    if (comment && comment.id == commentIDs[i]) {
      
     var replys =  $$('a[href="'+url+'#'+comment.id +'"]');
     var replyIDs = {};
      for ( var j =1; j< replys.length; j++ ){
       if(replys[j].parentNode) {
            var reply = replys[j].parentNode.parentNode.parentNode;
	    
	    if (reply.hasClassName("comment") && !replyIDs[ reply.id ]) {
		    var replyClone =  reply.cloneNode(true);
		    replyClone.setStyle( { "marginLeft": "1.5em",
					   "borderLeft": "solid 1px", 
					   "borderBottom":"solid 0px", 
					   "padding": "5px" } );
		    comment.appendChild( replyClone );
		    if (reply.parentNode) reply.remove();
		    replyIDs[ reply.id ] = true;
	    }
        }    
    }
        
  }
}

}


}, false);//.user.js
