/* better event handling */
if (document.all && window.attachEvent) { // IE-Win
    window.attachEvent("onload", showAuthor);
    window.attachEvent("onload", showComment);
} else if (window.addEventListener) { // Gecko, Safari, KDE
    window.addEventListener("load", showAuthor, true);
    window.addEventListener("load", showComment, true);
} else { // old others, like ie5-mac
}

function showComment() {
  var a;
  if (a = document.getElementById(document.location.hash.substr(2))) {
    var b = document.location.hash.substr(2);
    var roothash = document.location.hash.substr(1,1);
	if (roothash == 'c') {
    	showLaterComments(b);
	}
    showThisComment(b);
    a.childNodes[1].style.border = '2px dotted #ff7b00';
  }
}
function showParent(commid) {
  var b  = document.getElementsByTagName('div');
  for (var i=0;i<b.length;i++) { 
    if (b[i].className=='xar-accent-outline') { 
	  if ( b[i].id.match('d[0-9]+d'+commid+'$') ) {
	    var commids = b[i].id.split(/d[0-9]+d/);
		if (commids.length>2) { 
		  showThisComment(commids[commids.length-2]);
		  document.location.hash = '#c'+commids[commids.length-2];
        } else {
		  document.location.hash = '#commenti';
        }
      } 
	}
  }
}
function showThisComment(commid) {
  var a;
  if (a = document.getElementById(commid)) {
    a.style.display = 'block';
	var img =document.getElementById('i'+commid)
	img.src = '/themes/noise/images/close.png';
	img.onclick = function(){hideComment(commid);};
  }
}
function hideComment(commid) {
  var a;
  if (a = document.getElementById(commid)) {
    a.style.display = 'none';
	var img =document.getElementById('i'+commid)
	img.src = '/themes/noise/images/exp1.gif';
	img.onclick = function(){showThisComment(commid);};
  }
}
function hideThread(commid) {
  var b  = document.getElementsByTagName('div');
  for (var i=0;i<b.length;i++) { 
    if (b[i].className=='xar-accent-outline') { 
	  if ( b[i].id.match(commid+'d') ) {
	    hideComment(b[i].parentNode.id);
      } 
	}
  };
  hideComment(commid);
}
function showThread(commid) {
  showThisComment(commid);
  var b  = document.getElementsByTagName('div');
  for (var i=0;i<b.length;i++) { 
    if (b[i].className=='xar-accent-outline') { 
	  if (b[i].id.match(commid)  ) {
	    showThisComment(b[i].parentNode.id);
      } 
	}
  };
}
function showLaterComments(idnumber) {
  var b  = document.getElementsByTagName('div');
  for (var i=0;i<b.length;i++) { 
    if (b[i].className=='xar-tr-collapsed') { 
	  if (b[i].id-idnumber>0) {
		showThisComment(b[i].id);
      } 
	}
  };
}
function showAuthor() {
  var ah =document.getElementsByTagName('a');
  var authorstring = '';
  for (var i=0;i<7;i++) {
    if (aut = document.getElementById('authorid'+i)) {
	  authorstring += aut.innerHTML+'-';
	} else {
	  break;
	}
  }
 
  for (var i=0;i<ah.length;i++) { 
    if ( authorstring.match(ah[i].innerHTML) 
	     && ah[i].parentNode.className=='xar-tr-author' )  { 
	    ah[i].className= 'auth-outline' ;
	};
  }
}
