// DEFERABLE routines called by index page only

function OnFramesetPageLoad() {
	setTimeout("FadeInEtmLogo()", 2500);
	// OLD: UpdateCopyrightYear(); 
	InitNewsTicker(); 
	InitMenu();
}

// NOT cross-browser yet (e.g., event object)
function InitMenu() {
	if(Ptr("tblMenu")) {
		tblMenu.menuLinks = [];		// collection of all menu links
		var links = tblMenu.getElementsByTagName("A");

		for(var i=0; i<links.length; i++) {
			tblMenu.menuLinks.push(links[i]);
			AttachEvent(links[i], "mouseover", function() { SetActiveMenuLabel(this); if(window.event) event.cancelBubble = true; } );
			// bug: cancelBubble doesn't work for 'click' events
			AttachEvent(links[i], "click", MenuLabelClickHandler(i) );
			links[i].labelNum = i;
		}
		// DISABLED: DbgMsg("tblMenu.menuLinks array ("+ tblMenu.menuLinks.length +"):<br>"+tblMenu.menuLinks.join("<br>"));
		
		AttachEvent(tblMenu, "mouseout", StartMenuSpringTimer);
		AttachEvent(tblMenu, "mouseover", CancelMenuSpringTimer);
	}
}

// returns click handler that only activates i
function MenuLabelClickHandler(iLabelNum) {
	fncClickHandler.iTargetLabelNum = iLabelNum;
	function fncClickHandler() { if(this.labelNum == fncClickHandler.iTargetLabelNum) SetActiveMenuLabel(this); this.blur(); if(window.event) event.cancelBubble = true; }
	return fncClickHandler;
}
			


// spring back to active menu node 3 seconds after user mouseouts from menu (reset if user mouseovers a menu item)
function StartMenuSpringTimer() { window.menuTimer = setTimeout('SetActiveMenuLabel(tblMenu.activeLink)', 3000); }
// cancel active menu spring-back timer
function CancelMenuSpringTimer() { clearTimeout(window.menuTimer); }


function SetActiveMenuLabel(aActiveMenuLabel) {
	if(window.tblMenu && tblMenu.menuLinks && aActiveMenuLabel && (aActiveMenuLabel.tagName=="A")) {
		CancelMenuSpringTimer();		
		if(HasCssClass(aActiveMenuLabel, "activeMenuLabel"))
			// if already an active menu label, don't re-activate (fixes links that are proxies for a child link)
			DbgMsg("menu label \""+ aActiveMenuLabel.innerText +"\" already active; aborting SetActiveMenuLabel()", 5);
		else {
			DbgMsg("setting \""+ aActiveMenuLabel.innerText +"\" menu label active", 4);
	
			// clear activeMenuLabel CSS class from all labels
			for(var i=0; i<tblMenu.menuLinks.length; i++)
				RemCssClass(tblMenu.menuLinks[i], "activeMenuLabel");
	
			// assign CSS class activeMenuLabel to specified menu label and its parent labels
			oLabel = aActiveMenuLabel;
			do {
				AddCssClass(oLabel, "activeMenuLabel");
				oLabel = oLabel.parentNode;
			}
			while(oLabel != tblMenu);
		}
	}
}


function FadeInEtmLogo() {
	if(window.divEtmLogo && window.etmLogo) {
		if(divEtmLogo.filters && divEtmLogo.filters[0]) divEtmLogo.filters[0].Apply();
		etmLogo.style.visibility = "visible"; 
		if(divEtmLogo.filters && divEtmLogo.filters[0]) divEtmLogo.filters[0].Play();
	}
}


function UpdateCopyrightYear() {
	if(window.copyrightYear) copyrightYear.innerHTML = (new Date()).getFullYear();
}

function UpdateNav(sContentId) {
	try {
		if(!is.NBStr(sContentId)) return;

		// reset current activeLink
		if(tblMenu.activeLink) {
			RemCssClass(tblMenu.activeLink, "activeLink");
			tblMenu.activeLink = null;
		}
		var x, oLinks = tblMenu.getElementsByTagName("A");
		var rePageIdUrl = new RegExp("cid="+ sContentId);
		//alert("matching \""+sContentId+"\" ("+ rePageIdUrl +")");
		for(x in oLinks) {
			if( rePageIdUrl.test( oLinks[x].href ) ) {
				DbgMsg("Menu item \""+ oLinks[x].innerText +"\" marked as new activeLink", 3);
				AddCssClass(oLinks[x], "activeLink");
				DbgMsg("active item CSS class = "+ oLinks[x].className, 5);
				tblMenu.activeLink = oLinks[x];
				break;
			}
		}
		if(!tblMenu.activeLink) WarnMsg("tblMenu.activeLink undefined");
	}
	catch(oErr) {
		WarnMsg("UpdateNav() failed");
	}
}


/* OLD:
		function ShowClientAreaMenu() {
			clientAreaMenu.style.display = "block";
			// Mozilla compatibility: disable parent link when child links disabled
			if(UA.moz) {
				aClientArea.oldHref = aClientArea.href;
				aClientArea.removeAttribute("href");
			}
		}
		function HideClientAreaMenu() {
			clientAreaMenu.style.display = "none";
			if(UA.moz) {
				aClientArea.href = aClientArea.oldHref;
			}
		}
*/

