// JavaScript Document for pcMD

var menuItem = null; // The pull-down menu (subMenu)
var mainMenuItem; // The menu item on the main navigation that the subMenu is attached to
var subMenuList; // A list of the items in the subMenu
var listSource; // The subMenu is created from the list of services that appears on the left side of the webpage
var nodeLevel; // The index of the array for the individual menu items in the subMenu list
var listItem; // The individual menu options in the subMenu list

//start creating list of submenu
// Create the unordered list tag with the id subMenu4
function makeSubMenu() {
	mainMenuItem = document.getElementById("menu4");
	subMenuList = document.createElement("ul");
	subMenuList.setAttribute("id", "subMenu4");
	mainMenuItem.appendChild(subMenuList);
	
	listSource = document.getElementById("small");
	createSubMenuList(subMenuList);
}

// Create the list of subMenu items and display subMenu
function createSubMenuList(list) {
	for (var n=listSource.firstChild; n!=null; n=n.nextSibling) {
		nodeLevel = levelNumber(n);
		if (nodeLevel != -1) {
			listItem = document.createElement("li");
			listItem.innerHTML = n.innerHTML;
			
			list.appendChild(listItem);
		}
	}
}

// Creates the array for the list (see function createSubMenuList) and returns the index of the array to the createSubMenuList function
var sections = Array("li");
function levelNumber(node) {
	for (var i=0; i<sections.length; i++) {
		if (node.nodeName == sections[i].toUpperCase()) return i;
	}
	return -1;
}
//end creating list of submenus


//Hide the SubMenu on the Main Navigation Bar when the mouse is not hovered over the associated Menu Item
function hideSubMenu(id) {
	menuItem = document.getElementById(id);
	menuItem.style.visibility='hidden';
}
//Show the SubMenu on the Main Navigation Bar when the mouse is hovered over the associated Menu Item
function showSubMenu(id) {
	menuItem = document.getElementById(id);
	menuItem.style.visibility='visible';
}


//Start rotating computer tips on the sidebar
var currentIndex = 0; // Determines the index of the current tip to display
var previousIndex = 0; // Determines the index of the previous tip to hide it
var numberTips = new Array(); // Array for the list of tips
var tipRotation; // The interval of time before the next computer tip is displayed

// gets all the html tags based on whether the browser uses the IE DOM or the W3C DOM
// Create an array from the html tags that includes only those with the specified class attribute
function getElementsByClass(classname) {
	var counter=0; //creates an index number for the list of tips
	var allTags = document.all? document.all : document.getElementsByTagName("*"); 
		for ( var i=0; i<allTags.length; i++) {
		if (allTags[i].className == classname)
			numberTips[counter++] = allTags[i];
	}
}

// rotates the display of the tips
function rotateTips() {
	currentIndex=(currentIndex < numberTips.length-1) ? currentIndex+1 : 0;
	previousIndex=(currentIndex==0) ? numberTips.length-1 : currentIndex-1;
	numberTips[previousIndex].style.display="none";  // hides the old tip
	numberTips[currentIndex].style.display="block";  // displays the new tip
}

// pauses the rotation of the tips when the mouse pointer is hovered over the tip
function pauseTips() {
	clearInterval(tipRotation);
}

// restarts the rotation of the tips when the mouse pointer moves away from the tip
function restartTips() {
	tipRotation = setInterval("rotateTips()", 7000);
}

// starts multiple functions when the website loads
window.onload=function() {
	if (document.all || document.getElementById) {
		makeSubMenu();
		getElementsByClass("tips");
		tipRotation = setInterval("rotateTips()", 7000);
	}
}

