//Flyout navigation by Brandon More

function flyOuts(){
	
	//settings
	var easing = 500;
	var method = "easeInOutQuad";
	var theDelay = 800;
	
	var lists = jQuery("#menu-main-menu li ul");
	var listCount = lists.length;
	var navLinks = jQuery("#menu-main-menu").children("li");
	var currentList = "";
	var currentId = "";
	var pastId = "";
	var lastList = "";
	var delay = "";
	var subs = jQuery.makeArray("");
	

	for(k=0; k<listCount; k=k+1){
		var thisList = jQuery(lists[k]);
		var listCells = jQuery(thisList).children("li");
		var listNum = listCells.length;
		var thisArray = jQuery.makeArray("");
		var total = 0;
				
		for(j=0; j<listNum; j=j+1){
			var thisCell = jQuery(listCells[j]);
			var thisWidth = jQuery(thisCell).width();
			thisArray[j] = thisWidth;
		}
		
		for(g=0; g<thisArray.length; g=g+1){
			total = total + thisArray[g];
		}
				
		subs[k] = total;
		
		thisList.css("width", total+"px");
				
	}
	
	lists.css("display", "none");
	lists.css("visibility", "visible");
	
	
				
	
	for(i=0; i<listCount; i=i+1){
		
	}
	
	function showList(theList){
		theList.stop(true,true).fadeIn(easing);
		
		
	}
	
	function hideList(theList){
		theList.stop(true,true).fadeOut(easing);
				
	}
		
	navLinks.hover(
			function(){
				currentList = jQuery(this).children("ul");
				currentId = currentList.parent().attr("id");
				jQuery(this).addClass("current");
				showList(currentList);
				
				
				if(pastId == currentId && delay != ""){
					window.clearTimeout(delay);
									
				}else if(pastId != currentId && delay != "" && pastId != ""){
					window.clearTimeout(delay);
					hideList(lastList);
				}
				
							
										
			},
			function(){
				lastList = jQuery(this).children("ul");
				pastId = lastList.parent().attr("id");
				jQuery(this).removeClass("current");
				delay = window.setTimeout(function(){hideList(lastList)}, theDelay);
				//hideList(lastList);
				
				
			}
	)
	
	lists.click(
		function(){
			lists.css("display", "none");
		}
	);
	
	

};


