
$(document).ready(function()
{
	loadNav();
});

function loadNav() 
{
	//This parses nav.xml for the navigation and dynamically creates the titles and links
	$.ajax({type: "GET",url: "/nav.xml",dataType: "xml", 
		success: function(xml) 
		{
			var currentPage = $.url.attr("path");
			var menuList = $(xml).find('menu');
			
			menuList.each(function() {
				
				var name_text = $(this).attr('name');
				var menu_num = $(this).attr('number');
				
				var $container = $('<div></div>').addClass('navContainer');
				var $menu = $('<div></div>').addClass('navBlock').attr('id','nav' + menu_num);
				var $menu_title = $('<div></div>').html(name_text).addClass('navTitle');
				
				$("#nav").append($container);
				$container.append($menu);
				$menu.append($menu_title);
				
				if(parseInt(menu_num) == menuList.length)
				{
					$container.addClass("lastNav");
				}
				
				$container.hover(slideNavUp,slideNavDown);
				
				var itemList = $(this).find('item');
				
				itemList.each(function() {
					var title_text = $(this).attr('title');
					var url_text = $(this).attr('url');
					var menu_item = $('<a></a>').html(title_text).attr('href',url_text).appendTo($menu);
					
					if(currentPage == url_text)
					{
						menu_item.addClass("current");
					}
					
				}); //close itemList each
			
			}); //close menuList each
			
			if(typeof(hold_nav) != 'undefined')
			{
				currentNav(hold_nav);
			}
			
		} //close success function
	}); //close ajax
	
	//This sets the animation for mouse over on the navigation blocks	
	function slideNavUp() {
		$(this).find('.navBlock').stop().animate({top:-1},{queue:false,duration:300});
	};
	
	//This sets the animation for mouse out on the navigation blocks
	function slideNavDown() {
		$(this).find('.navBlock').animate({top:101},{queue:false,duration:300});
	}
	
}

function currentNav(navBlock)
{
	$(navBlock).parent().unbind('mouseover').unbind('mouseout');
	
	$(navBlock).css("top",-1);
}
