function getTop(el) {
	iPos = 0;
	while (el!=null) {
	 	iPos += el.offsetTop;
		el = el.offsetParent;
	}
	return iPos;
}

function getLeft(el) {
	iPos = 0;
	while (el!=null) {
	 	iPos += el.offsetLeft;
		el = el.offsetParent;
	}
	return iPos;
}

function addEvent (el, evName, evFunction) {
	if (isIE) {
		eval("el.attachEvent('" + evName + "'," + evFunction + ")"); 
	} else {
		eval("el." + evName + " = " + evFunction);
	}
}

function getTarg (e) {
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	return targ;
}

function itemOver(e) {
	var targ = getTarg(e);
	targ.style.backgroundColor = targ.parentNode.onColor;
}

function itemOut(e) {
	var targ = getTarg(e);
	targ.style.backgroundColor = targ.parentNode.offColor;
}

function itemClick(e) {
	var targ = getTarg(e);
	location.href = targ.URL;
}

function menuOver(e) {
	clearTimeout(lastTimeout);
}

function menuOut(e) {
	var targ = getTarg(e);
	while (!targ.chanCode) {
		targ = targ.parentNode;
	}
	menuOffProcess(targ.chanCode);
}

function menuOffNow (chanCode) {
	getEl(chanCode).style.visibility = hid;
	if (isIE) selectVis(vis);
}

function menuOffProcess (chanCode) {
	lastTimeout = setTimeout("menuOffNow('" + chanCode + "Menu')", 1000);
}

function menuOnProcess (el) {
	clearTimeout(lastTimeout);
	if (el.style.visibility != vis) {
		rfrshMenuAd(el.chanCode);
		if (actMenu != "") getEl(actMenu+"Menu").style.visibility = hid;
		actMenu = el.chanCode;
		el.style.visibility = vis;
		if (isIE) selectVis(hid);
	}
}

function selectVis(state) {
	selects = document.getElementsByTagName("select");
	for (selectIndex = 0; selectIndex < selects.length; selectIndex++) {
		selects[selectIndex].style.visibility = state;
	}
}

function areaOver (e) {
	var targ = getTarg(e);
	menu = getEl(targ.chanCode + "Menu");
	menuOnProcess(menu);
}

function areaOut (e) {
	var targ = getTarg(e);
	menu = getEl(targ.chanCode + "Menu");
	menuOffProcess(targ.chanCode);
}

function newMenu (chanCode) {
	var menuDiv = makeEl("DIV");
	menuDiv.className = "outerMenu";
	menuDiv.id = chanCode + "Menu";
	menuDiv.chanCode = chanCode;
	menuDiv.offColor = (chanCode == activeTab) ? cColor : oColor;
	menuDiv.onColor = (chanCode == activeTab) ? hlActColor : actColor;
	menuDiv.style.zIndex = zInd++;
	menuDiv.style.visibility = hid;
	menuDiv.style.position = "absolute";
	addEvent (menuDiv, mOv, "menuOver");
	addEvent (menuDiv, mOt, "menuOut");
	addTopEl(menuDiv);
	positionMenu(menuDiv);
	var area = getEl(chanCode + "Area");
	area.chanCode = chanCode;
	addEvent(area, mOv, "areaOver");
	addEvent(area, mOt, "areaOut");
	return menuDiv;
}

function positionMenu(el) {
	var area = getEl(el.chanCode + "Area");
	if (area) {
		var menuTop = getTop(chanGif) + 17;
		var coords = area.coords.split(",");
		var width = 93;
		var left = ((getLeft(chanGif)) + parseInt(coords[0]));
		el.style.top = menuTop + px;
		el.style.width = width + px;
		//if (isIE) el.ieWidth = width;
		el.style.left = left + px;
	}
}

function posAllMenus() {
	for (menu in cm) {
		positionMenu(cm[menu]);
	}
	if (pCnt == 0) window.clearInterval(posLoop);
	
	pCnt--;
}

function makeEl(tagName) { return document.createElement(tagName); }
function makeTextEl (text) { return document.createTextNode(text) }
function addText (el, text) { el.appendChild( makeTextEl(text) ) }
function getEl (elName) { return document.getElementById(elName) }
function addTopEl (el) { document.body.insertBefore(el, document.body.firstChild) }
function areaExists (chanCode) { return (getEl(chanCode + "Area") ? true : false); }

function nIt ( menu, itemName, itemURL) {
	var itemDiv = makeEl("DIV");
	//if (isIE) itemDiv.style.width = menu.ieWidth - 1 + px;
	itemDiv.className = "item";
	addText(itemDiv, itemName);
	itemDiv.URL = itemURL;
	itemDiv.style.backgroundColor = menu.offColor;
	addEvent (itemDiv, mOv, itemOver)
	addEvent (itemDiv, mOt, itemOut)
	addEvent (itemDiv, "onclick", itemClick)
	menu.appendChild(itemDiv);
}

function rfrshMenuAd (chanCode) {
	var adVars = "chan=" + chanCode + "&sub=" + chanCode + "menu&adsize=88x31&pagepos=8&var=" + (Math.random() * 1000000000000000000);
	if (getEl(chanCode + "MenuAdLink")) getEl(chanCode + "MenuAdLink").href = "http://ads.businessweek.com/click.ng/" + adVars;
	getEl(chanCode + "MenuAdTrack").src = "http://ads.businessweek.com/image.ng/" + adVars;
}

function addAd ( menu, imgSrc ) {
	var chanCode = menu.chanCode;

	var adTrack = makeEl("IMG");
	adTrack.className = "menuAdTrack"
	adTrack.id = chanCode + "MenuAdTrack";
	addTopEl(adTrack);

	var adHref = makeEl("A");
	adHref.setAttribute ("HREF", "#");
	adHref.target = "_blank";
	adHref.id = menu.chanCode + "MenuAdLink";

	if ( imgSrc != "") {
		var adImg = makeEl("IMG");
		adImg.src = imgSrc;
		adImg.className = "menuAdImg";

		var itemDiv = makeEl("DIV");
		//if (isIE) itemDiv.style.width = menu.ieWidth - 1 + px;
		itemDiv.className = "item sponsorText";
		itemDiv.style.backgroundColor = (menu.chanCode == activeTab) ? cColor : oColor;
		addText(itemDiv, "Sponsored by:");
		itemDiv.appendChild(makeEl("BR"));

		adHref.appendChild(adImg)
		itemDiv.appendChild(adHref);
		menu.appendChild(itemDiv);
	}
}

UA = navigator.userAgent;
chanGif = getEl ("channelGif");

if (//UA.indexOf("Opera") == -1 && 
	//UA.indexOf("Safari") == -1 && 
	!(UA.indexOf("MSIE") != -1 && UA.indexOf("Mac") != -1) &&
	chanGif &&
	getEl("channelMap")) {
	
	var lastTimeout;
	actMenu = "";
	actColor = "#FFF";		// rollover color for regular menus
	hlActColor = "#dfdfdf";	// rollover color for highlighed menus
	cColor = "#FFF";	// highlighted menu item color
	oColor = "#DFDFDF";	// regular menu item bgcolor
	isIE = (UA.indexOf("MSIE") != -1) ? true : false;
	activeTab = getEl("channelGif").src;
	activeTab = activeTab.substring(activeTab.lastIndexOf("/")+1, activeTab.lastIndexOf("/")+3);
	mOv = "onmouseover";
	mOt = "onmouseout";
	px = "px";
	hid = "hidden";
	vis = "visible";
	zInd = 600;
	b = "http://www.businessweek.com";
	
	cm = new Object();
	
	ch = "hp";
	if (areaExists(ch)) {
	cm[ch] = newMenu(ch);
	nIt(cm[ch],"Latest News",b+"/index.html");
	nIt(cm[ch],"Tech News",b+"/index.html#tech");
	nIt(cm[ch],"Investing News",b+"/index.html#investing");
	nIt(cm[ch],"Smallbiz News",b+"/index.html#smallbiz");
	nIt(cm[ch],"Company News",b+"/index.html#company");
	nIt(cm[ch],"Political News",b+"/index.html#politics");
	nIt(cm[ch],"Global News",b+"/index.html#global");
	nIt(cm[ch],"B-Schools News","/index.html#bschools");
	nIt(cm[ch],"Viewpoint",b+"/index.html#views");
	nIt(cm[ch],"Polls",b+"/index.html#poll");
	nIt(cm[ch],"Special Reports",b+"/index.html#specrep");
	nIt(cm[ch],"Video Views",b+"/index.html#video");
	
	addAd(cm[ch],"");
	}
	
	ch = "mz";
	if (areaExists(ch)) {
	cm[ch] = newMenu(ch);
	nIt(cm[ch],"Latest Issue",b+"/contents.htm");
	nIt(cm[ch],"Magazine Search",b+"/search/index.html?chan=mz");
	nIt(cm[ch],"Special Reports",b+"/common/special01.htm?chan=mz");
	nIt(cm[ch],"Tools",b+"/common/tools.htm?chan=mz");
	nIt(cm[ch],"Scoreboards",b+"/common/tools.htm?chan=mz");
	nIt(cm[ch],"BWTV Videos",b+"/mediacenter/list/bwtv001.htm?chan=mz");
	nIt(cm[ch],"Lifestyle",b+"/lifestyle/index.html?chan=mz");
	nIt(cm[ch],"Subscribe to BW","https://www.neodata.com/ITPS2.cgi?ItemCode=BWEK&OrderType=Reply+Only&iResponse=BWEK.SUBSCRIBEUSCAN");
	nIt(cm[ch],"Newsletter",b+"/newsletters.htm");
	addAd(cm[ch],"http://www.businessweek.com/sponsors/sas/88x31_logo_sponsor.gif");
	}
	
	ch = "db";
	if (areaExists(ch)) {
	cm[ch] = newMenu(ch);
	nIt(cm[ch],"Top News",b+"/bwdaily/index.html");
	nIt(cm[ch],"News Archive",b+"/bwdaily/list/news01.htm");
	nIt(cm[ch],"News Search",b+"/search/search.htm");
	nIt(cm[ch],"Special Reports",b+"/common/special01.htm");
	nIt(cm[ch],"Lifestyle",b+"/lifestyle/index.html");
	nIt(cm[ch],"Newsmaker Videos",b+"/mediacenter/list/newsmakers001.htm");
	nIt(cm[ch],"Newsletter ",b+"/newsletters.htm");
	addAd(cm[ch],"http://s0b.bluestreak.com/ix.e?ir&s=371223&n=Insert_Time_Date_Stamp_Here");
	}
	
	ch = "pi";
	if (areaExists(ch)) {
	cm[ch] = newMenu(ch);
	nIt(cm[ch],"Investing Main",b+"/investing/index.html");
	nIt(cm[ch],"Markets",b+"/investor/markets.html");
	nIt(cm[ch],"Stocks",b+"/investor/stocks.html");
	nIt(cm[ch],"Funds",b+"/investor/funds.html");
	nIt(cm[ch],"Sectors",b+"/investor/sectors.html");
	nIt(cm[ch],"Economy & Bonds",b+"/investor/economybonds.html");
	nIt(cm[ch],"Investing Columns",b+"/investor/list/mcoltoc01.htm");
	nIt(cm[ch],"Newsletter ",b+"/newsletters.htm");
	addAd(cm[ch],"");
	}
	
	ch = "gb";
	if (areaExists(ch)) {
	cm[ch] = newMenu(ch);
	nIt(cm[ch],"Global Main",b+"/globalbiz/index.html");
	nIt(cm[ch],"Asian News",b+"/globalbiz/asia_index.html");
	nIt(cm[ch],"European News",b+"/globalbiz/europe_index.html");
	nIt(cm[ch],"Special Reports",b+"/common/special01.htm#globalbiz");
	nIt(cm[ch],"Newsletter",b+"/newsletters.htm");
	addAd(cm[ch],"");
	}
	
	ch = "tc";
	if (areaExists(ch)) {
	cm[ch] = newMenu(ch);
	nIt(cm[ch],"Technology Main",b+"/technology/index.html");
	nIt(cm[ch],"Recent Features",b+"/technology/list/featured01.htm");
	nIt(cm[ch],"Info Tech 100",b+"/magazine/toc/04_25/B38880425it100.htm");
	nIt(cm[ch],"Special Reports",b+"/common/special01.htm#technology");
	nIt(cm[ch],"CNET Reviews",b+"/technology/index.html#cnetreviews");
	nIt(cm[ch],"Science & Health",b+"/technology/list/science01.htm");
	nIt(cm[ch],"Tech Columns",b+"/common/columns.htm#technology");
	nIt(cm[ch],"Tech Videos",b+"/mediacenter/list/technology001.htm");
	nIt(cm[ch],"Newsletter",b+"/newsletters.htm");
	addAd(cm[ch],"");
	}
	
	ch = "sb";
	if (areaExists(ch)) {
	cm[ch] = newMenu(ch);
	nIt(cm[ch],"SmallBiz Main",b+"/smallbiz/index.html");
	nIt(cm[ch],"Viewpoint",b+"/smallbiz/index.html#viewpoint");
	nIt(cm[ch],"Smart Answers",b+"/smallbiz/index.html#smart");
	nIt(cm[ch],"Success Stories",b+"/smallbiz/index.html#success");
	nIt(cm[ch],"The Pulse",b+"/smallbiz/index.html#poll");
	nIt(cm[ch],"Marketing",b+"/smallbiz/index.html#marketing");
	nIt(cm[ch],"Sales","/smallbiz/index.html#sales");
	nIt(cm[ch],"Leadership",b+"/smallbiz/index.html#leadership");
	nIt(cm[ch],"Offbeat",b+"/smallbiz/index.html#offbeat");
	nIt(cm[ch],"Technology",b+"/smallbiz/index.html#technology");
	nIt(cm[ch],"After Work",b+"/smallbiz/index.html#work");
	nIt(cm[ch],"Resource Centers",b+"/smallbiz/index.html#resources");
	addAd(cm[ch],"http://www.businessweek.com/sponsors/mastercard/MC_logo_88x31.gif");
	}
	
	ch = "bs";
	if (areaExists(ch)) {
	cm[ch] = newMenu(ch);
	nIt(cm[ch],"B-Schools Main",b+"/bschools/index.html");
	nIt(cm[ch],"MBA Insider",b+"/bschools/mbainsider/index.html");
	nIt(cm[ch],"Calendar","http://bwnt.businessweek.com/calendar/index.asp");
	nIt(cm[ch],"Forums","http://forums.businessweek.com/bw-bschools/start/");
	nIt(cm[ch],"MBA Rankings & Profiles",b+"/bschools/04/geographic.htm");
	nIt(cm[ch],"Admissions Q&As",b+"/bschools/mbainsider/admission_qa_index.html");
	nIt(cm[ch],"MBA Journals",b+"/bschools/mbajournal/index.htm");
	nIt(cm[ch],"B-School Videos",b+"/mediacenter/list/bschools001.htm");
	nIt(cm[ch],"Newsletter",b+"/newsletters.htm");
	addAd(cm[ch],"http://www.businessweek.com/sponsors/carnegie_mellon/CMU_pulldown.gif");
	}
	
	ch = "ca";
	if (areaExists(ch)) {
	cm[ch] = newMenu(ch);
	nIt(cm[ch],"Careers Main",b+"/careers/index.html");
	nIt(cm[ch],"News Archive",b+"/careers/resultlist/newsarch01.htm");
	nIt(cm[ch],"Compare Salaries","http://swz-businessweek.salary.com/salarywizard/layoutscripts/swzl_newsearch.asp");
	nIt(cm[ch],"Compare Living Costs",b+"/common_frames/ca.htm?http://businessweek.monstermoving.com/Find_a_Place/Relosmart/rs.asp");
	nIt(cm[ch],"Exec MBA Search","http://bwnt.businessweek.com/embasearch/");
	nIt(cm[ch],"EMBA Comparator","http://bwnt.businessweek.com/embasearch/compare.asp");
	nIt(cm[ch],"Careers Videos",b+"/mediacenter/list/careers001.htm");
	nIt(cm[ch],"Newsletter",b+"/newsletters.htm");
	addAd(cm[ch],"");
	}

	pCnt = 10;
	posLoop = window.setInterval("posAllMenus()", 1000);

}

