// Determine browser type (Netscape 6 or IE 5.5).

var isIE4 = (navigator.userAgent.indexOf("MSIE 4") > 0) ? 1 : 0;
var isIE5 = (navigator.userAgent.indexOf("MSIE 5") > 0) ? 1 : 0;
var isIE55 = (navigator.userAgent.indexOf("MSIE 5.5") > 0) ? 1 : 0;
var isNS6 = (navigator.userAgent.indexOf("Gecko")    > 0) ? 1 : 0;
// Global variable for tracking the currently active button.

var activeButton = null;
if (isIE55 || isIE5 || isIE4 || isNS6) {
	document.write('<div id="momsMenu" class="menu">')
	document.write('<a class="menuItem" href="http://www.mommytips.com/mt/Moms/Healthy_Moms/">Health</a>')
	document.write('<a class="menuItem" href="http://www.mommytips.com/mt/Moms/Home/">Household</a>')
	document.write('<a class="menuItem" href="http://www.mommytips.com/recipes">Recipes</a>')
	document.write('<a class="menuItem" href="http://www.mommytips.com/mt/Moms/Parenting/">Parenting</a>')
	document.write('<a class="menuItem" href="http://www.mommytips.com/mt/Moms/Pregnancy/">Pregnancy</a>')
	document.write('<a class="menuItem" href="http://www.mommytips.com/mt/Moms/Stay-At-Home-Mom/">Stay at Home</a>')
	document.write('<a class="menuItem" href="http://www.mommytips.com/mt/Moms/Work_at_Home_Moms/">Work at Home</a>')
	document.write('<a class="menuItem" href="http://www.mommytips.com/mt/Moms/Working/">Working</a>')
	document.write('<a class="menuItem" href="http://www.mommytips.com/mt/Moms/">More...</a>')
	document.write('</div>')

	document.write('<div id="kidsMenu" class="menu">')
	document.write('<a class="menuItem" href="http://www.mommytips.com/mt/Kids/Education/">Education</a>')
	document.write('<a class="menuItem" href="http://www.mommytips.com/mt/Kids/Family_Fun/">Family Fun</a>')
	document.write('<a class="menuItem" href="http://www.mommytips.com/mt/Kids/Family_Fun/Kids_Crafts/">Crafts</a>')
	document.write('<a class="menuItem" href="http://www.mommytips.com/mt/Kids/Healthy_Kids/">Health</a>')
	document.write('<a class="menuItem" href="http://www.mommytips.com/mt/Kids/Safety/">Safety</a>')
	document.write('<a class="menuItem" href="http://www.mommytips.com/mt/Kids/Infants/">Infants</a>')
	document.write('<a class="menuItem" href="http://www.mommytips.com/mt/Kids/Toddlers/">Toddlers</a>')
	document.write('<a class="menuItem" href="http://www.mommytips.com/mt/Kids/Schoolers/">Schoolers</a>')
	document.write('<a class="menuItem" href="http://www.mommytips.com/mt/Kids/Teens/">Teens</a>')
	document.write('<a class="menuItem" href="http://www.mommytips.com/mt/Kids/">More...</a>')
	document.write('</div>')

	document.write('<div id="tipsMenu" class="menu">')
	document.write('<a class="menuItem" href="http://www.mommytips.com/tips/New">New Tips</a>')
	document.write('<a class="menuItem" href="http://mommytips.com/tips/">Categories</a>')
	document.write('</div>')

	document.write('<div id="communityMenu" class="menu">')
	document.write('<a class="menuItem" href="http://www.mommytips.com/cgi-bin/mt/jump.cgi?ID=497">Chat</a>')
	document.write('<a class="menuItem" href="http://www.mommytips.com/cgi-bin/mt/jump.cgi?ID=177">Boards</a>')
	document.write('<a class="menuItem" href="http://www.mommytips.com/cgi-bin/mt/jump.cgi?ID=178">Classifieds</a>')
	document.write('<a class="menuItem" href="http://www.mommytips.com/cgi-bin/mt/jump.cgi?ID=181">Ecards</a>')
	document.write('</div>')

	document.write('<div id="bargainsMenu" class="menu">')
	document.write('<a class="menuItem" href="http://www.mommytips.com/bargains/Freebies/">Freebies</a>')
	document.write('<a class="menuItem" href="http://www.mommytips.com/bargains/">Shopping</a>')
	document.write('</div>')

	document.write('<div id="contestMenu" class="menu">')
	document.write('<a class="menuItem" href="http://www.mommytips.com/cgi-bin/mt/jump.cgi?ID=186">Tips Contest</a>')
	document.write('<a class="menuItem" href="http://www.mommytips.com/cgi-bin/mt/jump.cgi?ID=185">Recipe Contest</a>')
	document.write('<a class="menuItem" href="http://www.mommytips.com/mt/Contests/">More...</a>')
	document.write('</div>')

}

// Capture mouse clicks on the page so any active button can be deactivated.

if (isIE55 || isIE5 || isIE4)
  document.onmouseout = pageMouseout;
if (isNS6)
  document.addEventListener("mouseout", pageMouseout, true);

function pageMouseout(event) {
  /* var className; */
  if (!isIE5 && !isNS6 && !isIE55 && !isIE4) return;
  var fromObj;
  var toObj;
  var fromIsChildOfMenu= false;
	var toIsChildOfMenu= false;
  var fromIsChildOfButton= false;
	var toIsChildOfButton= false;
  var testObj

if (!activeButton) {
	return;
}
if (!activeButton.menu) {
	return;
}
if (isIE55 || isIE5 || isIE4)
	{
	toObj = window.event.toElement;
	fromObj = window.event.fromElement;
	}
if (isNS6) {
    toObj = event.relatedTarget
  	fromObj = event.target
	}
if (toObj) {
	testObj = toObj;
	while (testObj) {
		if (testObj == activeButton.menu) {
			toIsChildOfMenu=true;
			}
		testObj = getParent(testObj);
		}
	}
if (fromObj) {
	testObj = fromObj;
	while (testObj) {
		if (testObj == activeButton.menu) {
			fromIsChildOfMenu=true;
			}
		testObj = getParent(testObj);
		}
	}

 
if (fromIsChildOfButton) {
	if (!toIsChildOfMenu) {
		resetButton(activeButton);
		return;
	}
}

if (fromIsChildOfMenu && !toIsChildOfMenu) {
		resetButton(activeButton);
		return;
		}
} 


function buttonMouseover(button, menuName) {
  if (!isIE5 && !isNS6 && !isIE55 && !isIE4) return;
	button.blur();
  // Associate the named menu to this button if not already done.

  if (!button.menu){
  if (isIE5 || isIE4) {
  	button.menu = eval("document.all." + menuName)
	}  else {
    button.menu = document.getElementById(menuName);
	}
  // Reset the currently active button, if any.
}
  if (activeButton&& activeButton != button) {
    resetButton(activeButton);
	}

    depressButton(button);

  return false;
}



function depressButton(button) {

  // For IE, force first menu item to the width of the parent menu,
  // this causes mouseovers work for all items even when cursor is
  // not over the link text.

  
  if (isIE5 && !button.menu.firstChild.style.width)
    button.menu.firstChild.style.width =
      button.menu.offsetWidth + "px";

  // Position the associated drop down menu under the button and
  // show it. Note that the position must be adjusted according to
  // the brower type.

  x = getPageOffsetLeft(button);
  y = getPageOffsetTop(button) + button.offsetHeight;
  if (isNS6) {
    x--;
    y--;
  }
  button.menu.style.left = x + "px";
  button.menu.style.top  = y + "px";
  button.menu.style.visibility = "visible";

  // Set button state and let the world know which button is
  // active.

  button.isDepressed = true;
  activeButton = button;
}

function resetButton(button) {

 // Hide the button's menu.

  if (button.menu)
    button.menu.style.visibility = "hidden";

  // Set button state and clear active menu global.

  button.isDepressed = false;
  activeButton = null;
}

function getPageOffsetLeft(el) {

  // Return the true x coordinate of an element relative to the page.

  return el.offsetLeft + (el.offsetParent ? getPageOffsetLeft(el.offsetParent) : 0);
}

function getPageOffsetTop(el) {

  return el.offsetTop + (el.offsetParent ? getPageOffsetTop(el.offsetParent) : 0);
}

function getParent(item) {
  if (isIE55 || isIE5 || isIE4) {
  	return item.parentElement
  }
  if (isNS6) {
  	return item.parentNode;
  }
}
