//SuckerTree Horizontal Menu (Sept 14th, 06)
//By Dynamic Drive: http://www.dynamicdrive.com/style/

var menuids=["treemenu1"] //Enter id(s) of SuckerTree UL menus, separated by commas

function buildsubmenus_horizontal(){
	var agt = navigator.userAgent.toLowerCase();
//	alert(agt);
	var isIE = agt.indexOf("msie") != -1;
	var isFF = agt.indexOf("firefox") != -1;
	
	for (var i=0; i<menuids.length; i++){
		var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
		
			var ul_minus_a = ultags[2].offsetWidth - ultags[2].getElementsByTagName("li")[1].offsetWidth;
			//alert(ul_minus_a);
			
			for (var t=0; t<ultags.length; t++){
				// widen width to allow texts with bold fonts to fit in submenu (also for the > character)
				ultags[t].style.width = (ultags[t].offsetWidth * 1.0) + "px";		// factor 1.0 is found by trial and error. Please adjust when css changes.
													
				//if (t == 0)
				{
					var atags=ultags[t].getElementsByTagName("a");
					for (var n=0; n<atags.length; n++){
						
						//alert(ul_minus_a);
						// Only widen a tags that are direct children of the ul current tag
						if (atags[n].parentNode.parentNode == ultags[t])
						{
							atags[n].style.width = (ultags[t].offsetWidth - 23) + "px"; // 23 pixels is found by trial and error. Please adjust when css changes.
						}							
					}

					// Reset width of ul tag in IE. Width grows because of the a tag widths are growing
					if (isIE)
					{
						if (atags.length > 0)
						{
							ultags[t].style.width = atags[0].style.width;
						}
					}
				}


				// position menus				
				if (ultags[t].parentNode.parentNode.id==menuids[i]){ //if this is a first level submenu
					ultags[t].style.top=ultags[t].parentNode.offsetHeight+"px" //dynamically position first level submenus to be height of main menu item
					//ultags[t].parentNode.getElementsByTagName("a")[0].className="mainfoldericon"
					if (ultags[t].className=="alignRight")
					{
						// (parentNode is li)
						if (ultags[t].parentNode.getElementsByTagName("a").length > 0)
						{
							ultags[t].style.left=(ultags[t].parentNode.getElementsByTagName("a")[0].offsetWidth - ultags[t].offsetWidth + 1) + "px";
						}
					}			
				}
				else{ //else if this is a sub level menu (ul)
					ultags[t].style.top= -1;
					
					if (ultags[t-1].getElementsByTagName("a").length > 0)
					{
						if (ultags[t].className=="alignRight")
						{
							//Position menu to the left of menu item that activated it. Exact position depends on browser type
							if (!isFF)
							{
								ultags[t].style.left=(ultags[t-1].getElementsByTagName("a")[0].offsetLeft - ultags[t].offsetWidth) + "px"
							}
							else
							{
								ultags[t].style.left=(ultags[t-1].getElementsByTagName("a")[0].offsetLeft - ultags[t].offsetWidth + 0) + "px"
							}
						}
						else
						{
							//Position menu to the right of menu item that activated it. Exact position depends on browser type
							if (isIE)
							{
								ultags[t].style.left=ultags[t-1].getElementsByTagName("a")[0].offsetWidth +"px" 
							}
							else
							{
								ultags[t].style.left=(ultags[t-1].getElementsByTagName("a")[0].offsetWidth + 1) +"px"
							}
						}
						
    					//ultags[t].parentNode.getElementsByTagName("a")[0].className="subfoldericon"
    				}
				}							

				ultags[t].parentNode.onmouseover=function(){
				this.getElementsByTagName("ul")[0].style.visibility="visible"
			}
			ultags[t].parentNode.onmouseout=function(){
			this.getElementsByTagName("ul")[0].style.visibility="hidden"
			}
		}
	}
}

if (window.addEventListener)
window.addEventListener("load", buildsubmenus_horizontal, false)
else if (window.attachEvent)
window.attachEvent("onload", buildsubmenus_horizontal)


