function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function showSection(id, self_id) {
  var divs = document.getElementsByTagName("div");
  clicked_link = document.getElementById(self_id);
  clicked_link.parentNode.className = "current";
  for (var i=0; i<divs.length; i++ ) {
    if (divs[i].className.indexOf("section") == -1) continue;
	if (divs[i].getAttribute("id") == id) {
      divs[i].className = "section current";
    }
  }
}

function hideSection(links) {
  var container_div = document.getElementById("nav_sections");
  divs = container_div.getElementsByTagName("div");
  for (var i=0; i<divs.length; i++ ) {
    if (divs[i].className.indexOf("section") == -1) continue;
      divs[i].className = "section";
  }
  for(var i=0; i<links.length; i++)
  {
	  links[i].parentNode.className = "";
  }
}

function prepareInternalnav() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("nav_tabs")) return false;
  var nav = document.getElementById("nav_tabs");
  var links = nav.getElementsByTagName("a");
  for (var i=0; i<links.length; i++ ) {
    var sectionId = links[i].getAttribute("href").split("#")[1];
    if (!document.getElementById(sectionId)) continue;
    //document.getElementById(sectionId).style.display = "none";
    //document.getElementById("tab-d").style.display = "block";

    links[i].destination = sectionId;
	links[i].id = "nav_for_" + String(sectionId);
    links[i].onclick = function() {
	  hideSection(links);
      showSection(this.destination, this.id);
      return false;
    }
  }
}

addLoadEvent(prepareInternalnav);
