window.onload = function() {	
  $('#nav li ul').hover(
    function(){
    	if($(this).siblings('a').html() == "Donate") {
		  $(this).siblings('a').css('background',"#0eb3e9 url(/atf/cf/%7B21FBB354-5ACC-433E-92E1-3E1BEB8DCF4B%7D/thcf_fade.png) repeat-x scroll 0 0");
		}else if($(this).siblings('a').html() == "Why Give") {
		  $(this).siblings('a').css('background',"#DD539E url(/atf/cf/%7B21FBB354-5ACC-433E-92E1-3E1BEB8DCF4B%7D/thcf_fade.png) repeat-x scroll 0 0");
		}else if($(this).siblings('a').html() == "Events") {
		  $(this).siblings('a').css('background',"#94CB65 url(/atf/cf/%7B21FBB354-5ACC-433E-92E1-3E1BEB8DCF4B%7D/thcf_fade.png) repeat-x scroll 0 0");
		}else if($(this).siblings('a').html() == "Our Donors") {
		  $(this).siblings('a').css('background',"#FAA845 url(/atf/cf/%7B21FBB354-5ACC-433E-92E1-3E1BEB8DCF4B%7D/thcf_fade.png) repeat-x scroll 0 0");
		}else if($(this).siblings('a').html() == "The Foundation") {
		  $(this).siblings('a').css('background',"#E84347 url(/atf/cf/%7B21FBB354-5ACC-433E-92E1-3E1BEB8DCF4B%7D/thcf_fade.png) repeat-x scroll 0 0");
		}
		$(this).siblings('a').css('color','white');
     },function(){
		$(this).siblings('a').css('background','');
		$(this).siblings('a').css('color','#fff');
     });

  $('#nav li ul').siblings('a').hover(
    function(){
		if($(this).html() == "Donate") {
		  $(this).css('background',"#0eb3e9 url(/atf/cf/%7B21FBB354-5ACC-433E-92E1-3E1BEB8DCF4B%7D/thcf_fade.png) repeat-x scroll 0 0");
		}else if($(this).html() == "Why Give") {
		  $(this).css('background',"#DD539E url(/atf/cf/%7B21FBB354-5ACC-433E-92E1-3E1BEB8DCF4B%7D/thcf_fade.png) repeat-x scroll 0 0");
		}else if($(this).html() == "Events") {
		  $(this).css('background',"#94CB65 url(/atf/cf/%7B21FBB354-5ACC-433E-92E1-3E1BEB8DCF4B%7D/thcf_fade.png) repeat-x scroll 0 0");
		}else if($(this).html() == "Our Donors") {
		  $(this).css('background',"#FAA845 url(/atf/cf/%7B21FBB354-5ACC-433E-92E1-3E1BEB8DCF4B%7D/thcf_fade.png) repeat-x scroll 0 0");
		}else if($(this).html() == "The Foundation") {
		  $(this).css('background',"#E84347 url(/atf/cf/%7B21FBB354-5ACC-433E-92E1-3E1BEB8DCF4B%7D/thcf_fade.png) repeat-x scroll 0 0");
		}
		$(this).css('color','white');
    },function(){
		$(this).css('background','');
		$(this).css('color','#fff');
    });

}

$(document).ready(function(){
	if (document.getElementById('home') != null ) {
	addIds(document.getElementById('nav'));
	} else {  
	addIds(document.getElementById('navInner'));
	}
});

sfHover = function() {
	// Support the standard nav without a class of nav.
	var el = document.getElementById("nav");
	if(!/\bnav\b/.test(el.className) && el.tagName == "UL")
		setHover(el);
	// Find all unordered lists.
	var ieNavs = document.getElementsByTagName('ul');
	for(i=0; i<ieNavs.length; i++) {
		var ul = ieNavs[i];
		// If they have a class of nav add the menu hover.
		if(/\bnav\b/.test(ul.className))
			setHover(ul);
	}
}

function setHover(nav) {
	var ieULs = nav.getElementsByTagName('ul');
	if (navigator.appVersion.substr(22,3)!="5.0") {
		// IE script to cover <select> elements with <iframe>s
		for (j=0; j<ieULs.length; j++) {
			var ieMat=document.createElement('iframe');
			if(document.location.protocol == "https:")
				ieMat.src="https://www.kintera.org/site/n.gif";
			else if(window.opera != "undefined")
				ieMat.src="";
			else
				ieMat.src="javascript:false";
			ieMat.scrolling="no";
			ieMat.frameBorder="0";
			ieMat.style.width=ieULs[j].offsetWidth+"px";
			ieMat.style.height=ieULs[j].offsetHeight+"px";
			ieMat.style.zIndex="-1";
			ieULs[j].insertBefore(ieMat, ieULs[j].childNodes[0]);
			ieULs[j].style.zIndex="101";
		}

		// IE script to change class on mouseover
		var ieLIs = nav.getElementsByTagName('li');
		for (var i=0; i<ieLIs.length; i++) if (ieLIs[i]) {
			// Add a sfhover class to the li.
			ieLIs[i].onmouseover=function() {
				if(!/\bsfhover\b/.test(this.className))
					this.className+=" sfhover";
			}
			ieLIs[i].onmouseout=function() {
				if(!this.contains(event.toElement))
					this.className= "";
			}
		}
	} else {
		// IE 5.0 doesn't support iframes so hide the select statements on hover and show on mouse out.
		// IE script to change class on mouseover
		var ieLIs = document.getElementById('nav').getElementsByTagName('li');
		for (var i=0; i<ieLIs.length; i++) if (ieLIs[i]) {
			ieLIs[i].onmouseover=function() {this.className+=" sfhover";hideSelects();}
			ieLIs[i].onmouseout=function() {this.className=this.className.replace(' sfhover', '');showSelects()}
		}
	}
}

// If IE 5.0 hide and show the select statements.

function hideSelects(){
	var oSelects=document.getElementsByTagName("select");
	for(var i=0;i<oSelects.length;i++)
		oSelects[i].className+=" hide";
}

function showSelects(){
	var oSelects=document.getElementsByTagName("select");
	for(var i=0;i<oSelects.length;i++)
		oSelects[i].className=oSelects[i].className.replace(" hide","");
}

// Run this only for IE.
$.each($.browser, function(i) {
  if($.browser.msie && $('body').attr("id")=="home" ){
	$(document).ready(function(){
	sfHover();
	});
  }
});

function arrows () {
	//Define HTML for arrow here
	var arrowCode = ' >>';
	//Do Not Edit Below Here
	var links = document.getElementById("nav").getElementsByTagName("a");
	for (i=0;i<links.length; i++) {
		if (links[i].className.indexOf("firstLevel") < 0) {
			if(links[i].nextSibling!=null && links[i].nextSibling.nodeName=="UL" && links[i].innerHTML.substring(0,4).toLowerCase()!="<img"){
				links[i].innerHTML += arrowCode;
			}
		}
	}
}

function trim(stringToTrim) {
  return stringToTrim.replace(/^\s+|\s+$/g,"");
}

//Add ids to list items
function addIds(ul) {
  var list_items = ul.childNodes;
  for(var item in list_items) {
    if(list_items[item].childNodes) {
      var list_children = list_items[item].childNodes;
      for(var child in list_children) {
        if(list_children[child].nodeName && list_children[child].nodeName.toLowerCase() == 'a') {
          var id = trim(list_children[child].innerHTML);
          id = id.toLowerCase();
          id = id.replace(/\s/g,'_');
          list_items[item].id = id;
        }
      }
    }
  }
}