if (typeof vcc != "object")	vcc = new Object();
vcc.nav = new Object();
vcc.nav.iDelay = 200;
vcc.nav.arTimeout1 = [];
vcc.nav.arTimeout2 = [];
vcc.nav.iActiveDrop;
vcc.nav.arItems = [];
vcc.nav.objPageDiv;
vcc.nav.objIframe;
vcc.nav.objIframeSub;
vcc.nav.arTopImages = [];
vcc.nav.iBreakPoint = 450;
vcc.nav.blnJustify;
vcc.nav.blnHorizontalNavFixed;
vcc.nav.safariTimeout = null;
vcc.nav.curSafariOpacity = .99;
vcc.nav.elmTopDrops = null;
vcc.nav.iDropWidth = (vcc.ie && vcc.version < 7) ? 176 : 174;

vcc.nav.init = function() {
	if (!vcc.nav.blnHorizontalNavFixed) vcc.nav.horizontalBar();
	vcc.nav.createDropdowns();	
}

vcc.addEvent(window, "load", "vcc.nav.init");

/* Horizontal navigation bar */

vcc.nav.horizontalBar = function() {
	if (!(objNavBar = document.getElementById("nav-bar"))) return;
	var objNavBarTable = objNavBar.getElementsByTagName("table")[0];
	if (vcc.getW(objNavBarTable) > vcc.nav.iBreakPoint || vcc.nav.blnJustify) {
		objNavBarTable.style.width = 882 + "px";
	} else {
		var arNavBarCells = objNavBarTable.getElementsByTagName("td");
		if (arNavBarCells.length == 0) return;
		var objLastCell = arNavBarCells[arNavBarCells.length - 1];
		if (objLastCell.className == "last") objLastCell.className = null;
	}
	var arLinks = objNavBar.getElementsByTagName("a");
	for (var i = 0; i < arLinks.length; i++) {
		var objLink = arLinks[i];
		var iHeight = vcc.getH(objLink);
		var iTopPadding = parseInt((33 - iHeight)/2 - 1);
		objLink.style.paddingTop = iTopPadding + "px";
		objLink.style.paddingBottom = parseInt((33 - iHeight - iTopPadding - 1)) + "px";					
	}
	vcc.nav.blnHorizontalNavFixed = true;
}

/* Dropdowns */

vcc.nav.createDropdowns = function() {
	if (!(vcc.nav.objPageDiv = vcc.getObj("page"))) return;	
	var objContainer = vcc.nav.objPageDiv.appendChild(document.createElement("div"));
	objContainer.id = "topdrops";
	if (vcc.safari) {
		objContainer.style.position = "absolute";
		vcc.moveTo(objContainer, 0, 0);
	}	
	for (var i = 0; i < vcc.nav.arItems.length; i++) {
		var objDropButtonContainer = vcc.getObj("topbutton-" + (i + 1));
		//Preload button images
		var objTopButtonImages = vcc.nav.arTopImages[i];
		with (objTopButtonImages) {
			imgDefault = new Image();
			imgDefault.src = objTopButtonImages.d;
			imgDefaultHover = new Image();
			imgDefaultHover.src = objTopButtonImages.dh;
			imgSelected = new Image();
			imgSelected.src = objTopButtonImages.s;
			imgSelectedHover = new Image();
			imgSelectedHover.src = objTopButtonImages.sh;
		}			
		var arItems = vcc.nav.arItems[i].arItems;
		//Check if section has any children. If yes, create dropdown
		if (arItems.length > 0) {
			var iDropId = i + 1;
			var iX = (vcc.bIsRtl) ? vcc.getX(objDropButtonContainer,false) + (vcc.getW(objDropButtonContainer) - vcc.nav.iDropWidth) + 9 : vcc.getX(objDropButtonContainer,false);		
			vcc.moveTo(objContainer.appendChild(vcc.nav.createDropDown(arItems,iDropId)),iX,vcc.getY(objDropButtonContainer,false));
			var objButtonLink = objDropButtonContainer.getElementsByTagName("a")[0];
			objButtonLink.setAttribute("dropid",iDropId);
			if (vcc.nav.arItems[i].active) objDropButtonContainer.setAttribute("active","true");
			objButtonLink.onmouseover = function() {
				vcc.nav.activateSafariFix(true);
				var iDropId = this.getAttribute("dropid");
				var blnIsActive = (this.className == "active");
				var arImages = this.getElementsByTagName("img");
				var objImage = (arImages.length > 0) ? arImages[0] : null;
				var objImages = vcc.nav.arTopImages[iDropId - 1];
				if (vcc.nav.iActiveDrop != iDropId) vcc.nav.hideDrop(vcc.nav.iActiveDrop);
				if (objImage != null)					
					objImage.src = (blnIsActive) ? objImages.sh : objImages.dh;
				if (vcc.nav.arTimeout1[iDropId]) clearTimeout(vcc.nav.arTimeout1[iDropId]);
				vcc.nav.arTimeout1[iDropId] = setTimeout("vcc.nav.showDrop(" + iDropId + ");",vcc.nav.iDelay);
			}
			objButtonLink.onmouseout = function() {
				vcc.nav.activateSafariFix(false);
				var iDropId = this.getAttribute("dropid");
				vcc.nav.arTimeout1[iDropId] = setTimeout("vcc.nav.hideDrop(" + iDropId + ");",vcc.nav.iDelay);
			}
			objButtonLink.onfocus = function() { this.blur(); }			
		}
	}
	//Fix the IE Zonal guillotine bug
	if (vcc.getObj("zonal") != null && vcc.ie) {
		var objFixDiv = vcc.nav.objPageDiv.appendChild(document.createElement("div"));
		objFixDiv.className = "flickerfix";
	}
	
}

vcc.nav.Item = function(sTitle, sUrl, bActive, strPopupProperties) {
	this.title = sTitle;
	this.url = sUrl.replace(/&amp;/g,"&");
	this.active = bActive;
	this.arItems = [];
	this.popupProps = strPopupProperties;
}

vcc.nav.createDropDown = function(arItems,iDropId) {
	var oDiv = document.createElement("div");
	oDiv.id = "drop-" + iDropId;
	oDiv.className = "drop";
	oDiv.setAttribute("dropid",iDropId);
	oDiv.onmouseover = function() {
		vcc.nav.activateSafariFix(true);
		if (vcc.nav.arTimeout1[this.getAttribute("dropid")]) clearTimeout(vcc.nav.arTimeout1[this.getAttribute("dropid")]);
		vcc.nav.arTimeout1[this.getAttribute("dropid")] = setTimeout("vcc.nav.showDrop(" + this.getAttribute("dropid") + ");",vcc.nav.iDelay);
	}
	oDiv.onmouseout = function() {
		vcc.nav.activateSafariFix(false);
		vcc.nav.arTimeout1[this.getAttribute("dropid")] = setTimeout("vcc.nav.hideDrop(" + this.getAttribute("dropid") + ");",vcc.nav.iDelay);
	}			
	var objUl = oDiv.appendChild(document.createElement("ul"));
	for (var i = 0; i < arItems.length; i++) {
		var objItem = arItems[i];
		var objLi = objUl.appendChild(document.createElement("li"));
		var objLink = objLi.appendChild(document.createElement("a"));
		objLink.href = objItem.url;
		objLink.innerHTML = objItem.title;
		if (objItem.popupProps != "") {
			objLink.setAttribute("props",objItem.popupProps);
			objLink.onclick = function() {
				vcc.openWindow(this.href,'_blank',this.getAttribute("props"));
				return false;
			}
		}
		if (objItem.active) {
			objLink.className = "active";
			objLink.setAttribute("active",true);
		}
		if (objItem.arItems.length > 0) {
			objLi.className = "parent";
			var iSubDropId = i + 1;
			objLink.setAttribute("dropid",iDropId);
			objLink.setAttribute("subdropid",iSubDropId);
			objLink.id = "droplink-" + iDropId + "-" + iSubDropId;
			objLink.onmouseover = function() {
				if (vcc.nav.arTimeout2[this.getAttribute("subdropid")]) clearTimeout(vcc.nav.arTimeout2[this.getAttribute("subdropid")]);
				vcc.nav.arTimeout2[this.getAttribute("subdropid")] = setTimeout("vcc.nav.showSubDrop(" + this.getAttribute("dropid") + "," + this.getAttribute("subdropid") + ");",vcc.nav.iDelay);
			}
			objLink.onmouseout = function() {
				vcc.nav.arTimeout2[this.getAttribute("subdropid")] = setTimeout("vcc.nav.hideSubDrop(" + this.getAttribute("dropid") + "," + this.getAttribute("subdropid") + ");",vcc.nav.iDelay);
			}
			vcc.getObj("topdrops").appendChild(vcc.nav.createSubDropDown(objItem.arItems,iDropId,iSubDropId));
		}
	}
	if (vcc.bIsRtl && vcc.opera)
		oDiv.style.padding = "0 4px 3px 0";
	return oDiv;
}

vcc.nav.createSubDropDown = function(arItems,iDrop,iSubDrop) {
	var oDiv = document.createElement("div");
	with (oDiv) {
		id = "drop-" + iDrop + "-" + iSubDrop;
		className = "drop subdrop";
		setAttribute("dropid",iDrop);
		setAttribute("subdropid",iSubDrop);
		style.zIndex = 100;
	}
	oDiv.onmouseover = function() {
		vcc.nav.activateSafariFix(true);
		if (vcc.nav.arTimeout1[this.getAttribute("dropid")]) clearTimeout(vcc.nav.arTimeout1[this.getAttribute("dropid")]);
		if (vcc.nav.arTimeout2[this.getAttribute("subdropid")]) clearTimeout(vcc.nav.arTimeout2[this.getAttribute("subdropid")]);
		vcc.getObj("droplink-" + this.getAttribute("dropid") + "-" + this.getAttribute("subdropid")).className = "active";
	}
	oDiv.onmouseout = function() {
		vcc.nav.activateSafariFix(false);
		vcc.nav.arTimeout1[this.getAttribute("dropid")] = setTimeout("vcc.nav.hideDrop(" + this.getAttribute("dropid") + ");",vcc.nav.iDelay);
		vcc.nav.arTimeout2[this.getAttribute("subdropid")] = setTimeout("vcc.nav.hideSubDrop(" + this.getAttribute("dropid") + "," + this.getAttribute("subdropid") + ");",vcc.nav.iDelay);
	}			
	var objUl = oDiv.appendChild(document.createElement("ul"));
	for (var i = 0; i < arItems.length; i++) {
		var oItem = arItems[i];
		var strItem = "<li><a href=\"" + oItem.url + "\"";
		if (oItem.active) strItem += " class=\"active\"";
		if (oItem.popupProps != "") strItem += " onclick=\"vcc.openWindow(this.href,'_blank','" + oItem.popupProps + "');return false;\"";
		strItem += ">" + oItem.title + "</a></li>";
		objUl.innerHTML += strItem;
	}
	if (vcc.bIsRtl && vcc.opera)
		oDiv.style.padding = "0 4px 3px 0";
	return oDiv;
}

vcc.nav.showDrop = function(iDrop) {
	var oDrop = vcc.getObj("drop-" + iDrop);
	vcc.getObj("topbutton-" + iDrop).className = "active";
	oDrop.style.zIndex = 1000;
	vcc.setDisplay(oDrop,"block");
	vcc.nav.iActiveDrop = iDrop;
	if (vcc.opera || vcc.mac) return;
	vcc.nav.createIframe(oDrop, false);
}

vcc.nav.hideDrop = function(iDropId) {
	if (vcc.nav.iActiveDrop == null) return;
	var objImages = vcc.nav.arTopImages[iDropId - 1];
	var oContainer = vcc.getObj("topbutton-" + iDropId);
	vcc.setDisplay(vcc.getObj("iframedrop"),"none");
	vcc.setDisplay("drop-" + iDropId,"none");
	oContainer.className = "";
	var arImages =  oContainer.getElementsByTagName("img");
	if (arImages.length > 0)
		arImages[0].src = (oContainer.getElementsByTagName("a")[0].className == "active") ? objImages.s : objImages.d;
}

vcc.nav.showSubDrop = function(iDrop,iSubDrop) {
	var oDrop = vcc.getObj("drop-" + iDrop + "-" + iSubDrop);
	var iTop = vcc.getY("droplink-" + iDrop + "-" + iSubDrop,false) - 3;
	var iLeft = vcc.bIsRtl ? vcc.getX("drop-" + iDrop,false) - (vcc.nav.iDropWidth * 2) + 177 : vcc.getX("drop-" + iDrop,false) + ((vcc.ie && vcc.version < 7) ? 175 : 171);
	vcc.moveTo(oDrop,iLeft,iTop);
	oDrop.style.zIndex = vcc.getObj("drop-" + iDrop).style.zIndex + 1;
	vcc.setDisplay(oDrop,"block");
	//Create and show sub iframe
	if (vcc.opera || vcc.mac) return;
	vcc.nav.createIframe(oDrop, true);
}

vcc.nav.createIframe = function(oDrop, bSub) {
	var oIframe = bSub ? vcc.getObj("iframedropsub") : vcc.getObj("iframedrop");
	if (oIframe == null) {
		oIframe = document.createElement("iframe");
		//oIframe.src = "empty.html";
		//oIframe.id = bSub ? "iframedropsub" : "iframedrop";
		//oIframe.frameborder = 0;
		//vcc.nav.objPageDiv.appendChild(oIframe);
	}
	with (oIframe.style) {
		width = (vcc.ie7) ? vcc.getW(oDrop) - 4 + "px" : vcc.getW(oDrop) + "px";
		height = (vcc.ie7) ? vcc.getH(oDrop) - 4 + "px" : vcc.getH(oDrop) + "px";
		left = oDrop.style.left;
		top = oDrop.style.top;
	}
	if (vcc.bIsRtl && (vcc.ie7 || !vcc.ie))
		oIframe.style.left = parseInt(oDrop.style.left) + 4 + "px";
	vcc.setDisplay(oIframe,"block");
}

vcc.nav.hideSubDrop = function(iDrop,iSubDrop) {
	var oDrop = vcc.getObj("drop-" + iDrop + "-" + iSubDrop);
	vcc.setDisplay(vcc.getObj("iframedropsub"),"none");
	vcc.setDisplay(oDrop,"none");
	if (vcc.getObj("droplink-" + iDrop + "-" + iSubDrop).getAttribute("active") + "" != "true")
		vcc.getObj("droplink-" + iDrop + "-" + iSubDrop).className = "";
}

vcc.nav.fixSafari = function() {
	vcc.nav.curSafariOpacity = (vcc.nav.curSafariOpacity == .99) ? .98 : .99;
	if (vcc.nav.elmTopDrops) {
		vcc.nav.elmTopDrops.style.opacity = vcc.nav.curSafariOpacity;
	}
}

vcc.nav.activateSafariFix = function(bOn) {
	// Sets an interval that changes opacity on the navigation every 20 ms. A stupid way to fix a stupid rendering bug in safari, making the navigation visible on top of flash all the time.
	if (vcc.safari) {
		clearInterval(vcc.nav.safariTimeout);
		vcc.nav.elmTopDrops = vcc.getObj("topdrops");
		if (bOn)
			vcc.nav.safariTimeout = setInterval(vcc.nav.fixSafari, 20);
	}
}

vcc.nav.searchDealer = function(strSearchFieldId,strHiddenFieldId) {
	var objHidden = vcc.getObj(strHiddenFieldId);
	if (objHidden == null) return;
	arConfigData = objHidden.value.split("|");
	var strUrl = arConfigData[0];
	var strSearchType = arConfigData[1]
	var strKeyword = vcc.getObj(strSearchFieldId).value;
	var strGoToUrl = strUrl + ((strUrl.indexOf("?") > -1) ? "&" : "?");
	var objDate = new Date();
	iMilSec = objDate.getTime();
	document.location.href = strGoToUrl + strSearchType + "=" + strKeyword + "&id=" + iMilSec;
}

vcc.nav.searchDealerSubmit = function(event,strSearchFieldId,strHiddenFieldId) {
	var e = (window.event) ? window.event : event;
	if (e.keyCode == 13 || e.keyCode == 3) {
		vcc.nav.searchDealer(strSearchFieldId,strHiddenFieldId);
		return false;
	}
	return true;
}

vcc.nav.rightContent = function() {
	var objRightContent = document.getElementById("rightcontent");
	var objLeftContent = document.getElementById("leftcontent");
	if (!objRightContent || !objLeftContent) return;
	var arRightContentDivs = objRightContent.getElementsByTagName("div");
	if (arRightContentDivs.length == 0) {
		objRightContent.style.display = "none";
		objLeftContent.className += " wide";
	}
}

