/**
 * Add a new function to be executed when the page loads.
 */
function addLoadEvent(func) {
  var oldOnload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  }
  else {
    window.onload = function() {
      oldOnload();
      func();
    }
  }
}

/** **/

/*****Extend the DOM. Capture classes*****/

function getElementsByClassName(name) {
 	var results = new Array;
 	var elems = document.getElementsByTagName("*");
 	for (var i = 0; i < elems.length; i++) {
 	if (elems[i].className.indexOf(name) != -1) {
 		results[results.length] = elems[i];
 	}
 }
 	return results;
}

/**********/

/*****Add spacer class to the main navigation*****/

function spacer() { /* The spacer class adds horizontal space within the main navigation to make room for the SmartStax logo. The space will be added to the right of the selected li. */
 //Gather page informations
	var mainNav = getElementsByClassName("main-nav");
		for (var i=0; i<mainNav.length; i++) {
//Get all the id's in main-nav
	var lis = mainNav[0].getElementsByTagName("li");
 //alert (lis.length);
 //Loop through the li's
		for (var j=0; j<lis.length; j++) {
	var targetspacer = lis[2];
//addClass("spacer");
		addClass(targetspacer,"spacer");
		}
	}
}

/**********/

/*****Add wide class to the main navigation*****/

function wide() { /* The wide function is to be used on any li link within the main navigation that is contained within one (1) line. There is a separate function for each one line navigation. A loop my be added if desired to used only one funtion. */
 //Gather page informations
	var mainNav = getElementsByClassName("main-nav");
		for (var i=0; i<mainNav.length; i++) {
//Get all the id's in main-nav
	var lis = mainNav[0].getElementsByTagName("li");
 //alert (lis.length);
 //Loop through the li's
		for (var j=0; j<lis.length; j++) {
		var targetwide = lis[1];
		
		addClass(targetwide,"wide");
		}
	}
}

function wideA() { /* The wide function is to be used on any li link within the main navigation that is contained within one (1) line. There is a separate function for each one line navigation. A loop my be added if desired to used only one funtion. */
 //Gather page informations
	var mainNav = getElementsByClassName("main-nav");
		for (var i=0; i<mainNav.length; i++) {
//Get all the id's in main-nav
	var lis = mainNav[0].getElementsByTagName("li");
 //alert (lis.length);
 //Loop through the li's
		for (var j=0; j<lis.length; j++) {
		var targetwide = lis[3];
		
		addClass(targetwide,"wide");
		}
	}
}






/**********/

//On Page Load Events

//window.onload = spacer;
addLoadEvent(spacer); 
addLoadEvent(wide);
addLoadEvent(wideA);
