/*

author: Scott Lenger
last updated: September 2009

instructions:
1. add link to this file in <head>
2. add "setJs();" to onload script in document head
3. for accordion nav add "setNav();" to onload script in document head

*/


// adds replaces class="nojs" with class="js" for styling js based behaviors
function setJS() {
	if (document.getElementsByTagName("body")) {
		var addClass = document.getElementsByTagName("body");
		for (var i=0; i<addClass.length; i++) {
			addClass[i].className = "js";
		}
	}
}


// a quickie to make full li clickable from: http://www.webdesignerwall.com/tutorials/jquery-tutorials-for-designers/
function clickableLI($navlistitem) {
	$($navlistitem).click(function(){
		window.location=$(this).find("a").attr("href"); return false;
	});
}


// a softer hover effect
function softHover($hoverelement, $displayelement) {
	$($displayelement).hide();
	$($hoverelement).hover(function() {
		$($displayelement).fadeIn();
	}, function() {
		$($displayelement).fadeOut("slow");
	});
}


// adds accordion navigation via mouseover
function setNav($alldescendants, $currentdescendant, $trigger) {

	$($alldescendants).hide();
	$($currentdescendant).show(); 
	$($trigger).hoverIntent({
		sensitivity: 7, 
		interval: 300, 
		over: hideNav, 
		timeout: 10, 
		out: missing
	});
	
	var t;
	function hideNav() {
		if ($(this).parents().filter("li").hasClass("active")) {
			$(this).children('ul').slideDown();
			$(this).addClass("active").siblings().removeClass("active");
			$(this).siblings().children('ul').slideUp();
		} else {
			var li = $(this); 
			t = setTimeout(function(){showCurrent(li); return;}, 500);
		}
	}
	
	function missing() {clearTimeout(t);}
	
	function showCurrent(li) {
		li.addClass("active").siblings().removeClass("active");
		li.siblings().children('ul').slideUp();
		li.children('ul').slideDown();
	}
	
}