// Ids of the divs that contains sub menu items.
var menuIds = new Array('menu-ideas', 'menu-news', 'menu-tooltips', 'menu-research', 'menu-careers', 'menu-myProfile');

// Ids of the links that make sub menus appear.
var menuLinkIds = new Array('linkHome', 'linkIdeas', 'linkNews', 'linkTooltips', 'linkResearch', 'linkCareers');

// Ids of the links for the sub-menus.
var subMenuLinksIds = new Array(
								//Ideas
								'submenu-hottopics', 'submenu-expertopinions', 'submenu-destinations', 'submenu-premiumsincentives',

								//News
								'submenu-whatsnew', 'submenu-industrycalendar', 'submenu-newspeople',

								//Tools & Tips
								'submenu-checklists', 'submenu-layoutcharts', 'submenu-strategy', 'submenu-eventmanagement',

								//Research
								'submenu-statisticstrends', 'submenu-technology', 'submenu-eventprofiles', 'submenu-topcanadian', 'submenu-topus',

								//Careers
								'submenu-professionaldevelopment', 'submenu-eventplannerscoordinators',

								//My meetings
								'myrfps', 'myfavorites', 'myprofile'
);

// Id of the div that contains every sub menus.
var subNavId = 'header-secondnav-container';

/** Change the class of the elements which ids are in the ids array to the mouseOut class. */
function mouseOutAllLinks(linkId) {

	// Change the class for regular links
	for (var i = 0; i < menuLinkIds.length; i++){
		var link = document.getElementById(menuLinkIds[i]);
		if(link) {
			link.className = 'mouseOut';
		}
	}

	// Change the class for the special MyProfile link (because it's not the same color).
	var myProfileLink = document.getElementById('linkMyProfile');
	if(myProfileLink) {
		myProfileLink.className = 'mouseOutMyProfile';
	}

	// Set the class of the current link to mouseOver
	if(linkId && document.getElementById(linkId) != undefined) {
		if(linkId == 'linkMyProfile') {
			document.getElementById(linkId).className = 'mouseOverMyProfile';
		} else {
			document.getElementById(linkId).className = 'mouseOver';
		}
	}

}

/** Loop through the array and hide each element by id */
function hideallids(currentSectionId) {

	for (var i=0;i < menuIds.length;i++){
		hidediv(menuIds[i]);
	}

	document.getElementById(subNavId).style.display = 'none';
}

var active = 0;
/** Redisplay the current sub menu after a certain amout of time in milliseconds */
function redisplayCurrentSubMenu(subDivToShow, linkToHighlight, subLinkToHighlight) {
	if(active == 0) {
		active=1;
		window.setTimeout("displaySubMenu('" + subDivToShow + "', '" + linkToHighlight + "', '" + subLinkToHighlight + "');active=0;", 5000);
	}
}

/** Display the specified sub div and highlight the specified link. */
function displaySubMenu(subDivToShow, linkToHighlight, subLinkToHighlight) {
	//alert(subLinkToHighlight);
	hideallids();
	showdiv(subDivToShow);
	mouseOutAllLinks(linkToHighlight);
	highlightSubMenu(subLinkToHighlight);
}

/** Safe function to hide an element with a specified id. Source: http://www.webmasterworld.com/forum91/441.htm */
function hidediv(id) {
	if (document.getElementById) { // DOM3 = IE5, NS6
		document.getElementById(id).style.display = 'none';
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'none';
		}
		else { // IE 4
			document.all.id.style.display = 'none';
		}
	}
}

/** Safe function to show an element with a specified id. Source: http://www.webmasterworld.com/forum91/441.htm */
function showdiv(id) {

	if(!contains(menuIds, id)) {
		return;
	}

	// Show the sub navigation
	document.getElementById(subNavId).style.display = 'block';

	if (document.getElementById) { // DOM3 = IE5, NS6
		var element = document.getElementById(id);
		if(element) {
			element.style.display = 'block';
		}
	}
	else {
		if (document.layers) { // Netscape 4
			document.id.display = 'block';
		}
		else { // IE 4
			document.all.id.style.display = 'block';
		}
	}
}

/** Checks if an element is in the specified array. */
function contains(array, element) {
	for (var i = 0; i < array.length; i++){
		if(array[i] == element) {
			return true;
		}
	}
	return false;
}

/** Highlight the selected submenu link. */
function highlightSubMenu(subLinkToHighlight) {
	if(subLinkToHighlight != "" && document.getElementById(subLinkToHighlight) != undefined) {
		document.getElementById(subLinkToHighlight).className = "mouseOver";
	}
}
