var clearThem="";
var underlineThem="";
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 itemOver2(e) {
	var targ = getTarg(e);
	targ.style.backgroundColor = targ.parentNode.onColor2;
}

function itemOut2(e) {
	var targ = getTarg(e);
	targ.style.backgroundColor = targ.parentNode.offColor2;
}
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++)
 {
                if(selects[selectIndex].id == "soArea" || selects[selectIndex].id == "inArea"|| selects[selectIndex].id == "soArea" || selects[selectIndex].id == "ymArea" || selects[selectIndex].id == "swArea" || selects[selectIndex].id == "yrArea" || selects[selectIndex].id == "blArea")
                 {
		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.offColor2 = (chanCode == activeTab) ? cColor2 : oColor2;
	menuDiv.onColor2 = (chanCode == activeTab) ? hlActColor2 : actColor2;
	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) + 20;
		var coords = area.coords.split(",");
                if(el.chanCode == "yr")
                {
		var width = 135;
                }
                else
                {
		var width = 130;
                }
		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;
        if(itemName == "The 40+ Life")
         {
	  itemDiv.style.backgroundColor = "#666699";
          addEvent (itemDiv, mOv, itemOver2)
	  addEvent (itemDiv, mOt, itemOut2)
         }
        else
         {
	  itemDiv.style.backgroundColor = menu.offColor;
          addEvent (itemDiv, mOv, itemOver)
	  addEvent (itemDiv, mOt, itemOut)
         }
	itemDiv.align="left";

	addEvent (itemDiv, "onclick", itemClick)
	menu.appendChild(itemDiv);
}

function rfrshMenuAd (chanCode) {
	//var menuHierarchy247 = (adValues[chanCode] ? adValues[chanCode] : "");
	//var adVars = menuHierarchy247 + "/" + (Math.random() * 1000000000000000000) + "@Top2!Top2";
	//var adVars = "chan=" + chanCode + "&sub=" + chanCode + "menu&adsize=88x31&pagepos=8&var=" + (Math.random() * 1000000000000000000);
	//if (getEl(chanCode + "MenuAdLink")) getEl(chanCode + "MenuAdLink").href = "http://oascentral.businessweek.com/RealMedia/ads/click_nx.ads/businessweek.com" + adVars;
	//getEl(chanCode + "MenuAdTrack").src = "http://oascentral.businessweek.com/RealMedia/ads/adstream_nx.ads/businessweek.com" + 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 = "#024474";		// rollover color for regular menus
	hlActColor = "#024474";	// rollover color for highlighed menus
	actColor2 = "#333366";		// rollover color for regular menus
	hlActColor2 = "#333366";	// rollover color for highlighed menus
	cColor = "#6ea9ce";	// highlighted menu item color
	oColor = "#6ea9ce";	// regular menu item bgcolor
	cColor2 = "#666699";	// highlighted menu item color
	oColor2 = "#666699";	// 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;nd = 600;
	b = "";
	
	adValues = new Object();
        adValues["bl"] = "/";
	adValues["so"] = "/startingout";
	adValues["in"] = "/investing";
	adValues["ym"] = "/money";
	adValues["sw"] = "/rewards";
	adValues["yr"] = "/yourretirement";
	cm = new Object();
	
	ch = "bl";
	if (areaExists(ch)) {
	
	}	
	cm = new Object();
	
	ch = "so";
	if (areaExists(ch)) {
	cm[ch] = newMenu(ch);
	nIt(cm[ch],"Goals",b+"/starting/goals");
	nIt(cm[ch],"Careers",b+"/starting/careers");
	nIt(cm[ch],"Life",b+"/starting/life");
	nIt(cm[ch],"Play",b+"/starting/play");
	
	
	//addAd(cm[ch],"http://image.kiplinger.com/sponsors/circulation/BW_88x31_v1.gif");
	}
	
	ch = "in";
	if (areaExists(ch)) {
	cm[ch] = newMenu(ch);
	nIt(cm[ch],"Markets",b+"/investing/markets");
	nIt(cm[ch],"Funds",b+"/investing/funds");
	nIt(cm[ch],"Outlook",b+"/investing/outlook");
	nIt(cm[ch],"Inside Edge",b+"/investing/edge");
	nIt(cm[ch],"My Portfolio","/php/portfolio/portfolio.php3");
	
	
	//addAd(cm[ch],"http://image.kiplinger.com/sponsors/ca/calogo_88x31.gif");
	}
	
	ch = "ym";
	if (areaExists(ch)) {
	cm[ch] = newMenu(ch);
	nIt(cm[ch],"Credit & Money Management",b+"/money/credit");
	nIt(cm[ch],"College & Family",b+"/money/college");
	nIt(cm[ch],"Real Estate",b+"/money/realestate");
	nIt(cm[ch],"Taxes",b+"/money/taxes");
	nIt(cm[ch],"Insurance",b+"/money/insurance");
	//addAd(cm[ch],"http://image.kiplinger.com/sponsors/circulation/BW_88x31_v1.gif");
	}
	
	ch = "sw";
	if (areaExists(ch)) {
	cm[ch] = newMenu(ch);
	nIt(cm[ch],"Cars",b+"/spending/cars");
	nIt(cm[ch],"Travel & Entertainment",b+"/spending/travel");
	nIt(cm[ch],"Smart Buys",b+"/spending/smart/");
	nIt(cm[ch],"Technology",b+"/spending/tech");
	//addAd(cm[ch],"http://image.kiplinger.com/sponsors/circulation/BW_88x31_v1.gif");
	}
	ch = "yr";
	if (areaExists(ch)) {
	cm[ch] = newMenu(ch);
	nIt(cm[ch],"Build a Nest Egg",b+"/yourretirement/nestegg");
	nIt(cm[ch],"Make Money Last",b+"/yourretirement/money");
	nIt(cm[ch],"Live the Good Life",b+"/yourretirement/goodlife");
	nIt(cm[ch],"Leave a Legacy",b+"/yourretirement/legacy");
	nIt(cm[ch],"The 40+ Life",b+"/yourretirement/fortyplus/");
	//addAd(cm[ch],"http://image.kiplinger.com/sponsors/circulation/BW_88x31_v1.gif");
	}
	pCnt = 10;
	posLoop = window.setInterval("posAllMenus()", 1000);

}
