function addMenuSupport() {
    // create, and post process menus
    if (document.getElementById('top_header') != null) {

        addTopNavContent();

    }

}
var topNavNew = ['Home','News','Missions','Multimedia','Connect','Aboutus'];

function addTopNavContent() {

    var navData = topNavNew;

    var bodyTag = document.getElementsByTagName('body')[0];

    var mainNavTag = document.getElementsByTagName('main-nav');

    var i;
    var mainDivTag = document.getElementById('main-nav');

    var subDivTag = document.createElement('div');

    subDivTag.id = "dropper_wrapper";

    for (i = 0; i < navData.length; i++) {

        var headerTag = document.createElement('h2');
        if (navData[i].toLowerCase() == 'aboutus') {
            navData[i] = "aboutnasa";
        }
        headerTag.id = "shelf-nav-" + navData[i].toLowerCase();
        headerTag.className = "nav-" + navData[i].toLowerCase() + "-out";

        if (navData[i].toLowerCase() == 'home') {

            headerTag.style.width = "129px"
        } else if (navData[i].toLowerCase() == 'connect') {

            headerTag.style.width = "124px"
        }

        var anchorTag = document.createElement('a');
        if (navData[i].toLowerCase() == 'aboutnasa') {
            navData[i] = "aboutus";
        }
        anchorTag.id = "topnav_" + navData[i].toLowerCase() + "link";

        anchorTag.rel = "topnav_" + navData[i].toLowerCase() + "link_submenu";
        if (navData[i].toLowerCase() == 'home') {

            anchorTag.style.width = "129px"
        } else if (navData[i].toLowerCase() == 'connect') {

            anchorTag.style.width = "124px"
        }

        if (navData[i].toLowerCase() == 'home') {

            anchorTag.href = "http://www.nasa.gov/home/index.html";
        } else if (navData[i].toLowerCase() == 'news') {

            anchorTag.href = "http://www.nasa.gov/news/index.html";
        } else if (navData[i].toLowerCase() == 'missions') {

            anchorTag.href = "http://www.nasa.gov/missions/index.html";
        } else if (navData[i].toLowerCase() == 'multimedia') {

            anchorTag.href = "http://www.nasa.gov/multimedia/index.html";
        } else if (navData[i].toLowerCase() == 'connect') {

            anchorTag.href = "http://www.nasa.gov/connect/index.html";
        } else {

            anchorTag.href = "http://www.nasa.gov/about/index.html";
        }

        if (navData[i].toLowerCase() != 'home') {

            anchorTag.rev = "http://www.nasa.gov/templateimages/redesign/shelfnav/" + navData[i].toLowerCase() + "_topnav.html";
        }

        var spanTag = document.createElement('span');
        if ((navData[i].replace(" ", "")).toLowerCase() == 'aboutus') {
            navData[i] = "About Us";
        }
        spanTag.style.display = "none";
        spanTag.innerHTML = navData[i];

        anchorTag.appendChild(spanTag);
        headerTag.appendChild(anchorTag);

        var divTag = document.createElement("div");
        divTag.id = "topnav_" + (navData[i].replace(" ", "")).toLowerCase() + "link_submenu";
        divTag.className = "dropdownmenu";

        subDivTag.appendChild(headerTag);
        subDivTag.appendChild(divTag);
    }

    mainDivTag.appendChild(subDivTag);

}


var dropdowncontent = {
    disableanchorlink: false,
    //when user clicks on anchor link, should link itself be disabled (always true if "revealbehavior" above set to "click")
    hidedivmouseout: [true, 100],
    //Set hiding behavior within Drop Down DIV itself: [hide_div_onmouseover?, miliseconds_before_hiding]
    ajaxloadingmsg: "Loading content. Please wait...",
    //HTML to show while ajax page is being feched, if applicable
    ajaxbustcache: false,
    //Bust cache when fetching Ajax pages?
    getposOffset: function (what, offsettype) {
        return (what.offsetParent) ? what[offsettype] + this.getposOffset(what.offsetParent, offsettype) : what[offsettype]
    },

    isContained: function (m, e) {
        var e = window.event || e
        var c = e.relatedTarget || ((e.type == "mouseover") ? e.fromElement : e.toElement)
        while (c && c != m) try {
            c = c.parentNode
        } catch (e) {
            c = m
        }
        if (c == m) return true
        else
        return false
    },

    show: function (anchorobj, subobj, e) {
        if ((!this.isContained(anchorobj, e) || (e && e.type == "click")) && !(window['dropDownMenusDisabled'] == true)) {
            var e = window.event || e
            if (e.type == "click" && subobj.style.visibility == "visible") {
                subobj.style.visibility = "hidden"
                return
            }
            var anchorId = anchorobj.getAttribute("id");
            //alert("anchorId:"+anchorId);
            if (anchorId == 'topnav_homelink') {
                document.getElementById('shelf-nav-home').className = "nav-home-over";
            }
            if (anchorId == 'topnav_newslink') {
                document.getElementById('shelf-nav-news').className = "nav-news-over";
            }
            if (anchorId == 'topnav_missionslink') {
                document.getElementById('shelf-nav-missions').className = "nav-missions-over";
            }
            if (anchorId == 'topnav_multimedialink') {
                document.getElementById('shelf-nav-multimedia').className = "nav-multimedia-over";
            }
            if (anchorId == 'topnav_connectlink') {
                document.getElementById('shelf-nav-connect').className = "nav-connect-over";
            }
            if (anchorId == 'topnav_aboutuslink') {
                document.getElementById('shelf-nav-aboutnasa').className = "nav-aboutnasa-over";
            }

            var horizontaloffset = (subobj.dropposition[0] == "left") ? -(subobj.offsetWidth - anchorobj.offsetWidth) : 0 //calculate user added horizontal offset			
            var verticaloffset = (subobj.dropposition[1] == "top") ? -subobj.offsetHeight : anchorobj.offsetHeight //calculate user added vertical offset
            //alert(this.getposOffset(anchorobj, "offsetLeft") + horizontaloffset + "px");
            //added this to get the hope anchor position always.
            var homeanchorObj = document.getElementById('topnav_homelink');

            subobj.style.left = "0px"; //this.getposOffset(homeanchorObj, "offsetLeft") + horizontaloffset + "px"			
            subobj.style.top = ((this.getposOffset(homeanchorObj, "offsetTop") + verticaloffset) - 2) + "px"
            subobj.style.visibility = "visible"
            subobj.startTime = new Date().getTime()
            subobj.contentheight = parseInt(subobj.offsetHeight)
            if (typeof window["hidetimer_" + subobj.id] != "undefined") //clear timer that hides drop down box?
            clearTimeout(window["hidetimer_" + subobj.id])
            this.slideengine(subobj, (subobj.dropposition[1] == "top") ? "up" : "down")
        }
    },

    curveincrement: function (percent) {
        return (1 - Math.cos(percent * Math.PI)) / 2 //return cos curve based value from a percentage input
    },

    slideengine: function (obj, direction) {
        var elapsed = new Date().getTime() - obj.startTime //get time animation has run
        if (elapsed < obj.glidetime) { //if time run is less than specified length
            var distancepercent = (direction == "down") ? this.curveincrement(elapsed / obj.glidetime) : 1 - this.curveincrement(elapsed / obj.glidetime)
            var currentclip = (distancepercent * obj.contentheight) + "px"
            obj.style.clip = (direction == "down") ? "rect(0 auto " + currentclip + " 0)" : "rect(" + currentclip + " auto auto 0)"
            window["glidetimer_" + obj.id] = setTimeout(function () {
                dropdowncontent.slideengine(obj, direction)
            }, 10)
        } else { //if animation finished
            obj.style.clip = "rect(0 auto auto 0)"
        }
    },

    hide: function (activeobj, subobj, e) {
        if ((!dropdowncontent.isContained(activeobj, e)) && !(window['dropDownMenusDisabled'] == true)) {
            window["hidetimer_" + subobj.id] = setTimeout(function () {

                var anchorId = activeobj.getAttribute("id");

                if (anchorId == 'topnav_homelink_submenu') {
                    document.getElementById('shelf-nav-home').className = "nav-home-out";
                }
                if (anchorId == 'topnav_newslink_submenu') {
                    document.getElementById('shelf-nav-news').className = "nav-news-out";
                }
                if (anchorId == 'topnav_missionslink_submenu') {
                    document.getElementById('shelf-nav-missions').className = "nav-missions-out";
                }
                if (anchorId == 'topnav_multimedialink_submenu') {
                    document.getElementById('shelf-nav-multimedia').className = "nav-multimedia-out";
                }
                if (anchorId == 'topnav_connectlink_submenu') {
                    document.getElementById('shelf-nav-connect').className = "nav-connect-out";
                }
                if (anchorId == 'topnav_aboutuslink_submenu') {
                    document.getElementById('shelf-nav-aboutnasa').className = "nav-aboutnasa-out";
                }

                subobj.style.left = subobj.style.top = '-1300px';
                clearTimeout(window["glidetimer_" + subobj.id])
            }, dropdowncontent.hidedivmouseout[1])
        }
    },

    hidediv: function (subobjid) {
        document.getElementById(subobjid).style.visibility = "hidden"
    },

    ajaxconnect: function (pageurl, divId) {
        var page_request = false
        var bustcacheparameter = ""
        if (window.XMLHttpRequest) // if Mozilla, IE7, Safari etc
        page_request = new XMLHttpRequest()
        else if (window.ActiveXObject) { // if IE6 or below
            try {
                page_request = new ActiveXObject("Msxml2.XMLHTTP")
            } catch (e) {
                try {
                    page_request = new ActiveXObject("Microsoft.XMLHTTP")
                } catch (e) {}
            }
        } else
        return false
        document.getElementById(divId).innerHTML = this.ajaxloadingmsg //Display "fetching page message"
        page_request.onreadystatechange = function () {
            dropdowncontent.loadpage(page_request, divId)
        }
        if (this.ajaxbustcache) //if bust caching of external page
        bustcacheparameter = (pageurl.indexOf("?") != -1) ? "&" + new Date().getTime() : "?" + new Date().getTime()
        page_request.open('GET', pageurl + bustcacheparameter, true)
        page_request.send(null)
    },

    loadpage: function (page_request, divId) {
        if (page_request.readyState == 4 && (page_request.status == 200 || window.location.href.indexOf("http") == -1)) {
            document.getElementById(divId).innerHTML = page_request.responseText
        }
    },

    init: function (anchorid, pos, glidetime, revealbehavior, htmlcontent) {



        var anchorobj = document.getElementById(anchorid)

        if (anchorobj) var subobj = document.getElementById(anchorobj.getAttribute("rel"))
        if (!anchorobj || !subobj) return

        document.getElementById(anchorobj.getAttribute("rel")).innerHTML = htmlcontent;
        //this.ajaxconnect(subobjsource, anchorobj.getAttribute("rel"))
        subobj.dropposition = pos.split("-")
        subobj.glidetime = glidetime || 1000
        subobj.style.left = subobj.style.top = 0
        if (typeof revealbehavior == "undefined" || revealbehavior == "mouseover") {
            anchorobj.onfocus = anchorobj.onmouseover = function (e) {
                dropdowncontent.show(this, subobj, e)
            }
            anchorobj.onblur = anchorobj.onmouseout = function (e) {
                dropdowncontent.hide(subobj, subobj, e)
            }
            if (this.disableanchorlink) anchorobj.onclick = function () {
                return false
            }
        }
/*else if (typeof revealbehavior=="undefined" || revealbehavior=="onfocus"){
			anchorobj.onfocus=function(e){dropdowncontent.show(this, subobj, e)}
			anchorobj.onblur=function(e){dropdowncontent.hide(subobj, subobj, e)}
			if (this.disableanchorlink) anchorobj.onclick=function(){return false}
		}*/
        else
        anchorobj.onclick = function (e) {
            dropdowncontent.show(this, subobj, e);
            return false
        }
        if (this.hidedivmouseout[0] == true) //hide drop down DIV when mouse rolls out of it?
        subobj.onmouseout = function (e) {
            dropdowncontent.hide(this, subobj, e)
        }
    }
}

var topMenu_curr_event = 0;

function nextNasaEventsInMenu() {

    var nasaeventobj = document.getElementById("menu_nasa_nasaevents");
    var evetn_child_elements = nasaeventobj.getElementsByTagName('li');

    topMenu_curr_event = eval(topMenu_curr_event + 1);
    if (topMenu_curr_event > eval(evetn_child_elements.length - 1)) {
        topMenu_curr_event = 0;
    }
    for (var i = 0; i < evetn_child_elements.length; i++) {
        var childObj = evetn_child_elements[i];
        if (i == topMenu_curr_event) {
            childObj.style.display = "block";
        } else {
            childObj.style.display = "none";
        }
    }
    var nasaeventcntobj = document.getElementById("top_menu_event_count");

    var evntCntTxt = (topMenu_curr_event + 1) + " / " + evetn_child_elements.length;
    nasaeventcntobj.innerHTML = evntCntTxt;

}

function prevNasaEventsInMenu() {

    var nasaeventobj = document.getElementById("menu_nasa_nasaevents");
    var evetn_child_elements = nasaeventobj.getElementsByTagName('li');

    topMenu_curr_event = eval(topMenu_curr_event - 1);
    if (topMenu_curr_event < 0) {
        topMenu_curr_event = evetn_child_elements.length - 1;
    }
    for (var i = 0; i < evetn_child_elements.length; i++) {
        var childObj = evetn_child_elements[i];
        if (i == topMenu_curr_event) {
            childObj.style.display = "block";
        } else {
            childObj.style.display = "none";
        }
    }

    var nasaeventcntobj = document.getElementById("top_menu_event_count");

    var evntCntTxt = (topMenu_curr_event + 1) + " / " + evetn_child_elements.length;
    nasaeventcntobj.innerHTML = evntCntTxt;
}


//document.observe('contentloaded', function () {
Event.observe(window, "load", function() {
    dropdowncontent.init("topnav_newslink", "right-bottom", 100, "mouseover", newsHTML);
    dropdowncontent.init("topnav_missionslink", "right-bottom", 100, "mouseover", missionsHTML);
    dropdowncontent.init("topnav_multimedialink", "right-bottom", 100, "mouseover", multimediaHTML);
    dropdowncontent.init("topnav_connectlink", "right-bottom", 100, "mouseover", connectHTML);
    dropdowncontent.init("topnav_aboutuslink", "right-bottom", 100, "mouseover", aboutusHTML);


});
