var open_items = new Array();
var open_items_time = new Array();

function clearTime()
{
	

		var rem = open_items_time.pop();
		//alert(open_items.length);
		clearTimeout(rem);
	for (var i = 0; i < open_items.length -1; i++)
	{
		
		var _id = open_items.pop();
		if (_id != this.id && _id.length != 6)
		{
		//alert(_id.length);
		document.getElementById(_id).lastChild.style.display="none";
		}
	}
}

function timeout(_id)
{
	
	if(_id.length == 6)
	{
		document.getElementById(_id).lastChild.style.display="none";
	}
	else{
		document.getElementById(_id).lastChild.style.display="block";
	}
	document.getElementById(_id).lastChild.style.display="none";
	
	eval("var t = setTimeout(\"document.getElementById('"+_id+"').lastChild.style.display='none'\",1000)");
	open_items.push(_id);
	open_items_time.push(t);
	
				   
}


var time;
var todo;



//get browser version
var bName = navigator.appName;
var bVer = parseInt(navigator.appVersion);

//adjust the height of the nav for ie
if(bName == "Microsoft Internet Explorer"){
	document.getElementById("trans").style.height="500";
}
else{
	document.getElementById("trans").style.height="26";
}

activateMenu = function(nav)  {
	
	
    /* currentStyle restricts the Javascript to IE only */
	//if (document.all && document.getElementById(nav).currentStyle) {  
       var navroot = document.getElementById(nav);
        
		/* Get all the list items within the menu */
		var lis=navroot.getElementsByTagName("LI");  
        for (i=0; i<lis.length; i++) {
        
           /* If the LI has another menu level */
            if(lis[i].lastChild.tagName=="UL"){

                /* assign the function to the LI */
             	lis[i].onmouseover=function() {	
					hideSelectBoxes();
					clearTime();
				   this.lastChild.style.display="block";
				   this.className+="_over";
				   //alert("test");
				   
				   
				   if(this.id.charAt(3) != "")
				   {
				   	document.getElementById("imgnav"+this.id.charAt(3)).src =  navArrayTop[this.id.charAt(3)][1]
				   	//alert("imgnav"+this.id.charAt(3));
				   }
				   
				   
				   if(this.hasChildNodes()){
				   		var length = this.childNodes.length;
						for (x=0; x<this.childNodes.length; x++) {
						node = this.childNodes[x];
						
						if (node.nodeName=="UL") {
							for(y=0; y<node.childNodes.length; y++)
							{
								node2 = node.childNodes[y];
								var _posa = parseInt(node2.id.charAt(5));
								
								if(node2 != null && node2.nodeName=="UL"){
									//node2.className+="_over";
									
								}
								
								if(node2 != null && node2.nodeName=="LI"){
									if(node2.className.indexOf('_over')==-1){
										if(node2.id.indexOf('lev')==-1)
										{
											//alert("test");
										}
										else{
											//node.style.top=-((_posa)*30)+"px";
										
											var _pos = parseInt(node2.id.charAt(5));
											node.onmouseover=function(){
												hideSelectBoxes();
												this.style.backgroundColor="#4D4D4D";
											}
											node.style.height=(_pos+1)*30+"px";
											//alert(node2.className);
											node2.className+="_over";
										}
									}
								}
								
								
							}
						}
					else{}
					
					}
					
					}
				  
                }				
				lis[i].onmouseout=function() {   
				showSelectBoxes();
			  	timeout(this.id);
			  
				 /* this.lastChild.style.display="none";
				   this.className=this.className.replace("_over", "");
				   if(this.id.charAt(3) != "")
				   {
				   		if(this.id.charAt(3) == strLev1.charAt(3))
						{
							document.getElementById("imgnav"+this.id.charAt(3)).src =  navArrayTop[this.id.charAt(3)][2]
						}
						else
						{
							document.getElementById("imgnav"+this.id.charAt(3)).src =  navArrayTop[this.id.charAt(3)][0]
						}

				   }*/
                }
            }
  }
	
	
}


function bc_out(obj)
{
	//change the top image to the rollover state
	document.getElementById("imgnav"+obj.substring(3,4)).src = navArrayTop[obj.substring(3,4)][0]
	
	var n=document.getElementById(obj);
	if(n)
	{
		if(n.className.indexOf('_over')==-1){

		}
		else{
			n.className=n.className.replace("_over", "");
		}
	
	}
	
}


function bc(obj)
{
	//change the top image to the rollover state
	document.getElementById("imgnav"+obj.substring(3,4)).src = navArrayTop[obj.substring(3,4)][1]
	
	
	var n=document.getElementById(obj);

	var len = obj.length;
	var _pos = obj.charAt(len-1);
			
	if(n != null && n.hasChildNodes()){
	
	
	for (x=0; x<n.childNodes.length; x++) {

		node = n.childNodes[x];

		if (node.nodeName=="UL") {
			
			for(y=0; y<node.childNodes.length; y++)
			{
				node2 = node.childNodes[y];
				if(node2.nodeName=="LI"){
					if(node2.className.indexOf('_over')==-1){
						node2.className+="_over";		
					}
				}
			}
		}
	}
		
		
	}

		
	if(n)
	{
		if(n.className.indexOf('_over')==-1){
			n.className+="_over";
		}
	}
}

 var nameOfArray = eval("navArray_prod");

 function productMouseOver(id) {
				clearTime();
				document.getElementById(id).className="prodDrop_over";
				var img_loc = id.substring(5,7);
				if(nameOfArray[img_loc])
				{
					document.getElementById("prod_img").src = nameOfArray[img_loc][2];
				}
			}
			
 function productMouseOut(id) {
				document.getElementById(id).className="prodDrop";
				document.getElementById("prod_img").src = baseURLimages+"/images/consumer/nav/brands/cag_crop_logo.gif";
				
			}



function change_img_src(obj,what){
//alert(what);
	if(what == "over"){
	
		//hide the brand dropdown when using products dropdown
		if(obj.id=="imgnav1") {
				if(document.getElementById("Brands") != null)
					{
						document.getElementById("Brands").style.visibility = 'hidden';
					}
			}
			
		obj.src = navArrayTop[obj.id.substring(6,7)][1];
	}
	if(what == "out"){
		//alert(obj);
		//alert(navArrayTop[document.getElementById(obj).id.substring(6,7)][0]);
		
		//hide the brand dropdown when using products dropdown
		if(obj.id=="imgnav1") {
				if(document.getElementById("Brands") != null)
					{
						document.getElementById("Brands").style.visibility = '';
					}
			}
			
		if(obj.id=="imgnav6") {
			//do nothing
		} else {			
			obj.src = navArrayTop[obj.id.substring(6,7)][0];
		}
	}
	if(what == "on"){
		obj.src = navArrayTop[obj.id.substring(6,7)][2];
	}

}

///hide the select boxes that would show under the dropdowns for ie
function hideSelectBoxes()
{
	if(bName == "Microsoft Internet Explorer"){

			var ele = document.getElementById("Brands")
			if(ele != null)
			{
			document.all.Brands.style.visibility="hidden";
			}
			
			var ele2 = document.getElementById("fms_8");
			if(ele2 != null)
			{
			document.all.fms_8.style.visibility="hidden";
			}
	}
	
}

function showSelectBoxes()
{
	if(bName == "Microsoft Internet Explorer"){
			var ele = document.getElementById("Brands")
			if(ele != null)
			{
			document.all.Brands.style.visibility="";
			}
			
			var ele2 = document.getElementById("fms_8");
			if(ele2 != null)
			{
			document.all.fms_8.style.visibility="";
			}

	}

}