/* 
Navigation Dropdown v1.2
Román D. Pacheco
-------------------------------------------
Changes/Revisions
2008.12.23 - Added code to trigger on load, eliminating the need to hardcode it into the <body> tag
2008.12.23 - Added support for OLs as well as ULs
2009.05.12 - Now requires that you supply your dropdown lists with a class


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
*/
//Default Variables
var targetClass = "dropdown"; //List's Class Name

//Start dropDown() on load
if (window.attachEvent) {
	window.attachEvent('onload', dropDown);
	} else if (window.addEventListener) {
		window.addEventListener('load', dropDown, false);
	} else {
		document.addEventListener('load', dropDown, false);
	}

//The good stuff starts here
function dropDown() {
	//Locate target lists
	var allDropDowns = getElementsByClassName(targetClass);
	
	// Go through each list
	for (var x = 0; x < allDropDowns.length; x++) {
		var currDropDown = allDropDowns[x];
		
		//Find all LIs within the lists
		var allListTags = new Array();
		var allListTags = currDropDown.getElementsByTagName("li");
		
		//Go through all LIs...
		for (i=0; i<allListTags.length; i++) {
			
			//See if this LI has a list in it
			var subListTags = new Array();
			subListTags = allListTags[i].getElementsByTagName("ul");
			var olListTags = new Array();
			olListTags = allListTags[i].getElementsByTagName("ol");
			
			//If its an OL, use that array instead of the default UL array
			if (olListTags.length > 0) {
				subListTags = olListTags;
			}
			
			//If this LI DOES have a list in it...
			if (subListTags.length > 0) {
				n=0;
				
				//Generate unique ID
				listItemId = "li" + i;
				
				//Assign current LI the ID
				allListTags[i].setAttribute("id",listItemId);
				listItem = document.getElementById(listItemId);
				
				//Generate unique ID for sub list
				subListId =  "li" + i + "ul" + n;
				
				//Assign sub list the ID
				subListTags[n].setAttribute("id",subListId);
				subList = document.getElementById(subListId);
				
				//Hide the sub list from view
				subList.style.visibility = 'hidden';
				
				//Make sure the loop knows 'subList' changes (DO NOT REMOVE)
				with ({ "subList": subList }) {
					
					//Add onmouseover and onmouseout actions
					listItem.onmouseover = function(){subList.style.visibility = 'visible';};
					listItem.onmouseout = function(){subList.style.visibility = 'hidden';};
					}// end with
				}// end if
			}// end for
		}// end for
	}// end function
	
function getElementsByClassName(className){
	var elements = new Array();
	var allTags = document.getElementsByTagName("*");
	
	for (var x = 0; x < allTags.length; x++) {
		if (allTags[x].className == className) {
			elements.push(allTags[x]);
			}
		}
	return elements;
	}