vcc.topnav = new Object();
vcc.topnav.timeouts = new Array();
vcc.topnav.arrSelects = new Array(); //All select lists
vcc.topnav.arrVisibleSelects = new Array(); //All visible select lists
vcc.topnav.arrPlugins = new Array(); //All object/plugin elements on the page
vcc.topnav.blnShowDropdowns = false; //Controls whether the dropdowns should be turned on or not
vcc.topnav.blnUseIframe = (vcc.ie && vcc.win && vcc.version > 5.2 && !vcc.opera) ? true : false;

//Dropdown init function. Called when the page loads
vcc.topnav.init = function() {
	if (!document.getElementById('dropdown1')) return false;
	//Position dropdowns
	var objDropdown, objDropdownButton, objDropdownLink;
	var iYOffset = (vcc.ie && vcc.mac) ? -8 : 0;
	var iXOffset = (vcc.ie && vcc.mac) ? -17 : 0;
	var iXPos, iYPos;
	for (i = 1; i < 5; i++) {
		objDropdown = vcc.getObj('dropdown' + i);
		//if (!objDropdown) break;
		objDropdownButton = vcc.getObj('dropdownbutton' + i);
		objDropdownLink = vcc.getObj('dropdownlink' + i);
		
		if (vcc.pageDirectionRtl != null && vcc.pageDirectionRtl) { //RTL
			if (!objDropdown) break;
			iXRtl = 233 + vcc.getX(objDropdownLink) - (vcc.getW(objDropdown) - vcc.getW(objDropdownLink));
			vcc.moveTo(objDropdown,iXRtl + iXOffset,vcc.getY(objDropdownLink) + vcc.getH(objDropdownButton) + iYOffset);
		} else {
			iXPos = vcc.getX(objDropdownLink) + iXOffset;
			iYPos = vcc.getY(objDropdownLink) + vcc.getH(objDropdownButton) + 8 + iYOffset;
			if (objDropdown)
				vcc.moveTo(objDropdown,iXPos,iYPos);
			vcc.moveTo("scopetext" + i, iXPos + 18,iYPos + 2);
			document.getElementById("scopetext" + i).style.width = vcc.getW(objDropdownLink);
			vcc.setDisplay("scopetext" + i, "block");
		}
	}
	/* Position and resize iframes */
	if (vcc.topnav.blnUseIframe) {
		vcc.topnav.blnShowDropdowns = true;
		var objIframe;
		for (i = 1; i < 5; i++) {
			objDropdown = vcc.getObj('dropdown' + i);
			if (!objDropdown) break;
			objIframe = vcc.getObj('dropdown' + i + 'iframe');
			vcc.moveTo(objIframe,vcc.getX(objDropdown) + vcc.getX('dropdowntable' + i),vcc.getY(objDropdown));
			objIframe.style.width = vcc.getW('dropdowntable' + i);
			objIframe.style.height = vcc.getH(objDropdown);
		}
	} else {
		vcc.topnav.arrPlugins = document.getElementsByTagName('object');
		vcc.topnav.arrSelects = document.getElementsByTagName('select');
		vcc.topnav.blnShowDropdowns = (vcc.topnav.arrPlugins.length > 0 && vcc.ie && vcc.win) ? vcc.topnav.checkForPlugins() : true;
		if (!vcc.topnav.blnShowDropdowns) return false;
	}
}

//Function returns false if a plugin object on the page has a left position under 486 px.
vcc.topnav.checkForPlugins = function() {
	var blnNoOverlap = true;
	for (i = 0; i < vcc.topnav.arrPlugins.length; i++) {
		var intLeft = vcc.getX(vcc.topnav.arrPlugins[i],true);
		if (intLeft < 486) {
			blnNoOverlap = false;
			break;
		}
	}
	return blnNoOverlap;
}

//Function displays a dropdown
vcc.topnav.showDropdown = function(intDrop) {
	vcc.getObj("dropdownlink" + intDrop).className = "active";
	if (!vcc.topnav.blnShowDropdowns) return;
	vcc.topnav.clearTimeoutForDrop();
	//Hide overlapping, and visible, select lists
	if (!vcc.topnav.blnUseIframe && document.all && vcc.win && !vcc.opera) {
		var objDrop = vcc.getObj('dropdown' + intDrop)
		for (i = 0; i < vcc.topnav.arrSelects.length; i++) {
			if (vcc.overlap(vcc.topnav.arrSelects[i],objDrop) && vcc.topnav.arrSelects[i].currentStyle.visibility != "hidden") {
				//Save this select in the arrVisibleSelects array
				vcc.topnav.arrVisibleSelects[vcc.topnav.arrVisibleSelects.length] = vcc.topnav.arrSelects[i];
				vcc.hide(vcc.topnav.arrSelects[i]);
			}
		}
	}
	vcc.topnav.hideDropdown();
	vcc.show('dropdown' + intDrop);
	if (vcc.topnav.blnUseIframe) vcc.show('dropdown' + intDrop + 'iframe');
}

//Function hides all dropdowns
vcc.topnav.hideDropdown = function() {
	vcc.hide('dropdown1','dropdown2','dropdown3','dropdown4','dropdown1iframe','dropdown2iframe','dropdown3iframe','dropdown4iframe');
}

//Function hides a dropdown
vcc.topnav.closeDropdown = function(intDrop,blnActive) {
	vcc.topnav.timeouts[intDrop] = setTimeout('vcc.topnav.hideDropdown();',100);
	strClass = (blnActive) ? "active" : "inactive";
	vcc.getObj("dropdownlink" + intDrop).className = strClass;
	if (!vcc.topnav.blnUseIframe) {
		//Show the overlapping select lists, stored in the arrVisibleSelects array
		for (i = 0; i < vcc.topnav.arrVisibleSelects.length; i++) {
			vcc.topnav.arrVisibleSelects[i].style.visibility = "inherit";
		}
		vcc.topnav.arrVisibleSelects.length = 0;
	}	
}

// Function clears all dropdown timeouts
vcc.topnav.clearTimeoutForDrop = function() {
	for (i = 0; i < vcc.topnav.timeouts.length; i ++) {
		if (vcc.topnav.timeouts[i]) {
			clearTimeout(vcc.topnav.timeouts[i]);
			vcc.topnav.timeouts[i] = null;
		}
	}	
}

vcc.addEvent(window, "load", "vcc.topnav.init");

// ZONAL

if (vcc.ie && document.styleSheets) {
	document.write("<style>#zonal ul.treeMenuChild {display:none;}</style>");
}

vcc.zonal = new Object();

vcc.zonal.init = function(){
	var uls = document.getElementsByTagName("ul");
	if (vcc.ie && document.styleSheets) {
		document.styleSheets[document.styleSheets.length-1].addRule("#zonal ul.treeMenuChild","display:block");
	}
	for(var i = 0; i<uls.length; i++){
		var elmUl = uls[i];
		var cn = " " + elmUl.className + " ";
		if(cn.indexOf(" treeMenu ")>-1){
			var subUls = elmUl.getElementsByTagName("ul")
			for(var j = 0; j<subUls.length; j++){				
				var s = subUls[j];
				s.parentNode.onclick = vcc.zonal.expandOrCollaps;
				var sCn = " " + s.className + " ";				
				vcc.zonal.checkChildClasses(s);				
				if (vcc.opera) {
					if (s.previousSibling.className != "expanded") s.style.display = "none";
				}  else if (sCn.indexOf(" expand ") == -1 && s.parentNode.className != "expanded" && !((vcc.w3c || vcc.mac) && s.previousSibling.className == "expanded")){
					s.style.display = "none";
				}				
			}
		}		
	}
}

//Called when the user clicks on a link, with subitems, in the zonal NavigationPlaceholderControl
vcc.zonal.expandOrCollaps = function(e){
	if(typeof(e) != "undefined"){ // Mozilla
		if (!vcc.safari) e.stopPropagation();
		var target = (e.target.nodeName == "A") ? e.target : e.target.parentNode;
		
	} else if(typeof(event) != "undefined"){ //IE
		event.cancelBubble = true
		var target = event.srcElement
	}
	vcc.zonal.switchChildDisplay(target);
	target.blur();
	if(target.parentNode.className == "expandable") target.parentNode.className = "expanded";
	else if(target.parentNode.className == "expanded") target.parentNode.className = "expandable";
}

//Called from the expandOrCollaps function. Displays or hides the subitem.
vcc.zonal.switchChildDisplay = function(elm){
	var elmChildUL;
	if (vcc.w3c || vcc.mac) {
		elmChildUL = elm.parentNode.nextSibling;
	} else {
		if (vcc.ie && !vcc.opera) {
			//IE: Loop through all nodes until we find the UL element.
			for (var currentNode = elm.parentNode.firstChild; currentNode != null; currentNode = currentNode.nextSibling) {
				if (currentNode.nodeName == "UL") {
					elmChildUL = currentNode;
					break;
				}
			}
		} else if (vcc.opera) {
			elmChildUL = elm.parentNode.nextSibling;
		} else {
			elmChildUL = null;
		}
	}
	if (elmChildUL && elmChildUL.style && elmChildUL.className.toLowerCase().indexOf("child") > -1) {
		if (elmChildUL.style.display == "none")
			elmChildUL.style.display = "block";
		else
			elmChildUL.style.display = "none";
	}
}

vcc.zonal.checkChildClasses = function(s){
	for(var k = 0; k < s.childNodes.length; k++){
		var sChild = s.childNodes[k];
		if(sChild.tagName && sChild.tagName.toLowerCase() == "li"){
			var cnChild = " " + sChild.className + " ";
			if(cnChild.indexOf(" active ")) return true;
		}
	}
}

vcc.addEvent(window, "load", "vcc.zonal.init");



if (!vcc.listLinks)
	vcc.listLinks = new Object();

//Fixes mouseover on all LI links
vcc.listLinks.init = function(strContainer) {
	var objContainer = (typeof strContainer == "string") ? vcc.getObj(strContainer) : vcc.getObj("maincontent");
	if (!objContainer) return;
	//Don't run this script on the sitemap page
	if (vcc.getObj("navSitemap")) return;
	//Get all LI items
	var arrListItems = objContainer.getElementsByTagName("li");
	for (i = 0; i < arrListItems.length; i++) {
		var strBgImage = (window.getComputedStyle) ? window.getComputedStyle(arrListItems[i],null).getPropertyValue("background-image") : arrListItems[i].currentStyle.backgroundImage;
		var strBulletImage = (window.getComputedStyle) ? window.getComputedStyle(arrListItems[i],null).getPropertyValue("list-style-image") : arrListItems[i].currentStyle.listStyleImage;
		if ((strBgImage.indexOf("listbullet.gif") > 0 || strBulletImage.indexOf("listbullet.gif") > 0) && arrListItems[i].getElementsByTagName("a").length > 0 && arrListItems[i].className != "active") {
			arrListItems[i].onmouseover = function() {
				this.className = "active";
			}
			arrListItems[i].onmouseout = function() {
				this.className = "";
			}
		}
	}
}

vcc.addEvent(window, "load", "vcc.listLinks.init");