function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
var sectionNav = {
	config: {
		theClass : "section",
		theElem : "div",
		theNav : "tabNav",
		classActive : "active",
		mainSection : "packaging",
		container: "services"
	},
	showSection: function(id, theLink){
		var divs = document.getElementsByTagName(sectionNav.config.theElem);
		for (var i=0; i<divs.length; i++ ) {
			if (divs[i].className.indexOf(sectionNav.config.theClass) == -1) continue;
			divs[i].style.display = divs[i].getAttribute("id") != id ? "none" : "block";
		}
		var theContainer = document.getElementById(sectionNav.config.theNav);
		var theLinks = theContainer.getElementsByTagName("a");
		for (var j=0; j<theLinks.length; j++){
			theLinks[j].className = theLinks[j].getAttribute("href").split("#")[1] == id ? sectionNav.config.classActive : " ";
		}
	},
	prepareInternalNav : function(){
		if (!document.getElementById(sectionNav.config.theNav)) return false;
		var nav = document.getElementById(sectionNav.config.theNav);
		var links = nav.getElementsByTagName("a");
		for (var i=0; i<links.length; i++ ) {
			var sectionId = links[i].getAttribute("href").split("#")[1];
			var theLink = links[i];
			if (!document.getElementById(sectionId)) continue;
			if (sectionId != sectionNav.config.mainSection){
				document.getElementById(sectionId).style.display = "none";
			}
			else{
				links[i].className="active";
			}
			links[i].destination = sectionId;
			links[i].onclick = function() {
				sectionNav.showSection(this.destination, theLink);
				return false;
			}
		}
	},
	createNavigation : function(){
		var tabNav = document.createElement("ul");
		tabNav.setAttribute("id", sectionNav.config.theNav);
		var theSections = document.getElementsByTagName(sectionNav.config.theElem);
		for (var i=0; i<theSections.length; i++){
			sectionClass = theSections[i].className;
			relatedLink = theSections[i].getAttribute("id");
			if (sectionClass == sectionNav.config.theClass){
		  		var listItem = document.createElement("li");
		  		var theLink = document.createElement("a");
  				var theText = document.createTextNode(relatedLink);
  				theLink.setAttribute("href", "#" + relatedLink);
  				theLink.appendChild(theText);
  				listItem.appendChild(theLink);
  				tabNav.appendChild(listItem);
  			}
  		}
  		var container = document.getElementById(sectionNav.config.container);
  		container.appendChild(tabNav);
	}, 
	init : function(){
		if (!document.getElementsByTagName || !document.getElementById) return false;
		sectionNav.createNavigation();
		sectionNav.prepareInternalNav();
	}
}
addLoadEvent(sectionNav.init);