/* 
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


xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
*/

//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() {
	
	//Find all LIs
	var allListTags = new Array();
	var allListTags = document.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';
    						if (listItem.className == "liNormalDD") {
        						listItem.className = "liHoverDD";
							listItem.firstChild.style.backgroundImage = "url('assets/images/nav_caps_overL.gif')";
							listItem.firstChild.style.backgroundPosition = "right top";
							listItem.firstChild.style.backgroundRepeat = "no-repeat";
    							} else {
        						listItem.className = "liNormalDD";
							listItem.firstChild.style.backgroundImage = "url('assets/images/nav_capsL.gif')";
							listItem.firstChild.style.backgroundPosition = "left top";
							listItem.firstChild.style.backgroundRepeat = "no-repeat";
    							}
					};
				listItem.onmouseout = function(){
					subList.style.visibility = 'hidden';
    						if (listItem.className == "liNormalDD") {
        						listItem.className = "liHoverDD";
							listItem.firstChild.style.backgroundImage = "url('assets/images/nav_caps_overL.gif')";
							listItem.firstChild.style.backgroundPosition = "right top";
							listItem.firstChild.style.backgroundRepeat = "no-repeat";
    							} else {
        						listItem.className = "liNormalDD";
							listItem.firstChild.style.backgroundImage = "url('assets/images/nav_capsL.gif')";
							listItem.firstChild.style.backgroundPosition = "left top";
							listItem.firstChild.style.backgroundRepeat = "no-repeat";
    							}
					};
				}
			}
		}
	}












