function topMenuHovers() {
    var navLis = document.getElementById("nav-site-wide").getElementsByTagName("li");
	for (var i=0; i < navLis.length; i++) {
		navLis[i].onmouseover = navLis[i].onfocus = function() {
			this.className += " hover";
		}
        navLis[i].onmouseout = navLis[i].onblur = function() {
			this.className = this.className.replace(new RegExp("\\bhover\\b"), "");
		}
	}
}
function addDropdownItem(parentId, childPath, childName) {
    topMenuBtn = document.getElementById("nav-site-wide-" + parentId);
    if (!topMenuBtn) return false;
    
    newLi = document.createElement('li');
    newA = document.createElement('a');
    newA.setAttribute('href', childPath);
    newA = newLi.appendChild(newA);
    newAText = document.createTextNode(childName)
    newA.appendChild(newAText);
    
    topMenuUls = topMenuBtn.getElementsByTagName('ul');
    if (topMenuUls.length > 0) {
        dropdown = topMenuUls[0];
    }
    else {
        newUl = document.createElement('ul');
        dropdown = topMenuBtn.appendChild(newUl);
    }
    dropdown.appendChild(newLi);
}
function populateDropdowns() {
addDropdownItem(2, '/about_us/history.php', 'history');
addDropdownItem(2, '/about_us/forward_thinking.php', 'forward thinking');
addDropdownItem(2, '/ttl_campaign/campaignoverview.php', 'touching tiny lives campaign');
addDropdownItem(2, '/about_us/paddington.php', 'paddington');
addDropdownItem(2, '/about_us/recruitment.php', 'current vacancies');
addDropdownItem(2, '/about_us/who_is_who.php', 'who\'s who');
addDropdownItem(2, '/about_us/contact_us.php', 'contact us');
addDropdownItem(2, '/about_us/FSB.php', 'fundraising standards board');
addDropdownItem(3, '/research_projects/project_database.php', 'our research');
addDropdownItem(3, '/research_projects/successes/index.php', 'our successes');
addDropdownItem(3, '/research_projects/research_training.php', 'research training');
addDropdownItem(3, '/research_projects/advisory_panel.php', 'our experts');
addDropdownItem(3, '/research_projects/applications.php', 'applications');
addDropdownItem(4, '/get_involved/challenge_events.php', 'challenge events');
addDropdownItem(4, '/get_involved/regional_events.php', 'regional events');
addDropdownItem(4, '/get_involved/volunteering.php', 'volunteering');
addDropdownItem(4, '/get_involved/bring_your_bear.php', 'bring your bear');
addDropdownItem(5, '/giving/donating.php', 'donate');
addDropdownItem(5, '/giving/direct_debits.php', 'give monthly');
addDropdownItem(5, '/sponsorship/', 'online sponsorship');
addDropdownItem(5, '/giving/legacies.php', 'legacies');
addDropdownItem(5, '/giving/touching_lives_fund.php', 'tribute funds');
addDropdownItem(5, '/giving/payroll_giving.php', 'payroll giving');
addDropdownItem(5, '/giving/company_giving.php', 'company giving');
addDropdownItem(5, '/giving/charitable_trusts.php', 'charitable trusts');
addDropdownItem(5, '/giving/share_giving.php', 'share giving');
addDropdownItem(5, '/giving/action_partners.php', 'action partners');
addDropdownItem(5, '/giving/recycling.php', 'recycling');
addDropdownItem(5, '/get_involved/truck_fest.php', 'truckin for tiny lives');
addDropdownItem(5, '/giving/Christmas_cards.php', 'Christmas cards');
addDropdownItem(6, '/news_media/news.php', 'news');
addDropdownItem(6, '/news_media/press_releases/', 'press releases');
addDropdownItem(6, '/ttl', 'touching tiny lives');
addDropdownItem(6, '/news_media/campaigns.php', 'previous campaigns');
addDropdownItem(6, '/touching_lives/', 'supporter magazine');
addDropdownItem(6, '/news_media/newsletter.php', 'e-newsletter');
addDropdownItem(28, '/giving/sponsorship/sponsor_friend.php', 'sponsor a friend');
addDropdownItem(28, '/giving/sponsorship/create_account.php', 'create your sponsorship account');
addDropdownItem(28, '/giving/sponsorship/your_account.php', 'login to your sponsorship account');
}
function clearSearchField(searchField) {
    // clear search fields of default text when first selected
    if (!searchField.getAttribute("cleared") != "cleared") {
        searchField.setAttribute("cleared", "cleared"); // remember that field has been cleared
        searchField.setAttribute("value", "");
    }
}
function initSearchFields() {
    site_search = document.getElementById("site-search-box");
    site_search.setAttribute("value", "search");
    if (list_signup = document.getElementById("list_signup_box")) {
        list_signup.setAttribute("value", "your email");
    }
}
function startup() {
    // stuff to do when page loads
    initSearchFields();
    populateDropdowns();
    topMenuHovers();
}
if (document.getElementById) window.onload = startup;
