var shownDropDown = null;
var hideDropDownTimeout = 0;
hideActiveMenu =0;

function showDropDown(dropDownId, triggerLink) {
  cancelHideDropDown();
  doHideDropDown();
  cancelhideActiveMenu();
  shownDropDown = document.getElementById(dropDownId);
  shownDropDown.style.display = 'block';  
  shownDropDown.onmouseout = triggerLink.onmouseout = hideDropDown;
  shownDropDown.onmouseover = cancelHideDropDown;
}

function hideDropDown() {
  hideDropDownTimeout = setTimeout(doHideDropDown, 200);
}

function cancelHideDropDown() {
  clearTimeout(hideDropDownTimeout);
}

function doHideDropDown() {
  if (shownDropDown) {
    shownDropDown.style.display = 'none';
  }
}

function doShowMenu(dropDownId, triggerLink, activeLink){
	if(dropDownId && triggerLink){
		if(activeLink=='celebrateSub'){				
			document.getElementById('eventsSub').style.display = 'none';
			document.getElementById('foodSub').style.display = 'none';
			document.getElementById('marketplaceSub').style.display = 'none';
			document.getElementById('directionsSub').style.display = 'none';
			document.getElementById('sponsorsSub').style.display = 'none';
		}else if(activeLink=='marketplaceSub'){
			document.getElementById('celebrateSub').style.display = 'none';
			document.getElementById('foodSub').style.display = 'none';
			document.getElementById('eventsSub').style.display = 'none';
			document.getElementById('directionsSub').style.display = 'none';
			document.getElementById('sponsorsSub').style.display = 'none';
		}else if(activeLink=='eventsSub'){
			document.getElementById('celebrateSub').style.display = 'none';
			document.getElementById('foodSub').style.display = 'none';
			document.getElementById('marketplaceSub').style.display = 'none';
			document.getElementById('directionsSub').style.display = 'none';
			document.getElementById('sponsorsSub').style.display = 'none';
		}else if(activeLink=='foodSub'){
			document.getElementById('celebrateSub').style.display = 'none';
			document.getElementById('eventsSub').style.display = 'none';
			document.getElementById('marketplaceSub').style.display = 'none';
			document.getElementById('directionsSub').style.display = 'none';
			document.getElementById('sponsorsSub').style.display = 'none';
		}else if(activeLink=='directionsSub'){
			document.getElementById('celebrateSub').style.display = 'none';
			document.getElementById('eventsSub').style.display = 'none';
			document.getElementById('marketplaceSub').style.display = 'none';
			document.getElementById('foodSub').style.display = 'none';
			document.getElementById('sponsorsSub').style.display = 'none';
		}else if(activeLink=='sponsorsSub'){
			document.getElementById('celebrateSub').style.display = 'none';
			document.getElementById('foodSub').style.display = 'none';
			document.getElementById('marketplaceSub').style.display = 'none';
			document.getElementById('directionsSub').style.display = 'none';
			document.getElementById('eventsSub').style.display = 'none';
		}
		hideActiveMenu = setTimeout(function(){lastMenu(dropDownId, triggerLink, activeLink)},300);			
	}
}

function cancelhideActiveMenu() {
	clearTimeout(hideActiveMenu);
}

function hidePrinMenu(dropDownId){
	//document.getElementById(dropDownId).style.display = 'none';
}

function lastMenu(dropDownId, triggerLink, activeLink) {
	if(document.getElementById(dropDownId).style.display == 'block'){
		 cancelhideActiveMenu();
	}else{
		if(activeLink=='celebrateSub'){				
			document.getElementById('eventsSub').style.display = 'none';
			document.getElementById('foodSub').style.display = 'none';
			document.getElementById('marketplaceSub').style.display = 'none';
			document.getElementById('directionsSub').style.display = 'none';
			document.getElementById('sponsorsSub').style.display = 'none';
		}else if(activeLink=='marketplaceSub'){
			document.getElementById('celebrateSub').style.display = 'none';
			document.getElementById('foodSub').style.display = 'none';
			document.getElementById('eventsSub').style.display = 'none';
			document.getElementById('directionsSub').style.display = 'none';
			document.getElementById('sponsorsSub').style.display = 'none';
		}else if(activeLink=='eventsSub'){
			document.getElementById('celebrateSub').style.display = 'none';
			document.getElementById('foodSub').style.display = 'none';
			document.getElementById('marketplaceSub').style.display = 'none';
			document.getElementById('directionsSub').style.display = 'none';
			document.getElementById('sponsorsSub').style.display = 'none';
		}else if(activeLink=='foodSub'){
			document.getElementById('celebrateSub').style.display = 'none';
			document.getElementById('eventsSub').style.display = 'none';
			document.getElementById('marketplaceSub').style.display = 'none';
			document.getElementById('directionsSub').style.display = 'none';
			document.getElementById('sponsorsSub').style.display = 'none';
		}else if(activeLink=='directionsSub'){
			document.getElementById('celebrateSub').style.display = 'none';
			document.getElementById('eventsSub').style.display = 'none';
			document.getElementById('marketplaceSub').style.display = 'none';
			document.getElementById('foodSub').style.display = 'none';
			document.getElementById('sponsorsSub').style.display = 'none';
		}else if(activeLink=='sponsorsSub'){
			document.getElementById('celebrateSub').style.display = 'none';
			document.getElementById('foodSub').style.display = 'none';
			document.getElementById('marketplaceSub').style.display = 'none';
			document.getElementById('directionsSub').style.display = 'none';
			document.getElementById('eventsSub').style.display = 'none';
		}
		shownDropDown = document.getElementById(dropDownId);
		shownDropDown.style.display = 'block';
	}
}

function showDropDownStay(dropDownId, triggerLink) {
	if(document.getElementById(dropDownId).style.display != 'block'){
		cancelHideDropDown();
		doHideDropDown();
		shownDropDown = document.getElementById(dropDownId);
		shownDropDown.style.display = 'block';
		//shownDropDown.onmouseout = triggerLink.onmouseout = hideDropDown;
		//shownDropDown.onmouseover = cancelHideDropDown;
	}else{
		document.getElementById(dropDownId).style.display = 'none'
	}
}
