$(document).ready(function() {

	//Selects the proper top level category for the current page
	var cat = $.url().segment(1);
	if(cat === "")
		$("#nav a[name='home']").addClass("current");
	else {
		var slug = /([^\.]+)/i.exec(cat);
		$("#nav a[name='"+slug[0]+"']").addClass("current");
	}
	var page = $.url().segment(2);
	if(page !== "") {
		var slug = /([^\.]+)/i.exec(page);
		$("#subnav a[name='"+slug[0]+"']").addClass("current");
	}

	var current = $("#nav li a.current");
	var speed = 100;
	$("#nav li").hover(function() {
		current.stop().animate({backgroundPosition: "50% 28px"}, speed).removeClass("current");
		$(this).find("a").stop().animate({backgroundPosition: '50% 16px'}, speed).addClass('current');
		},
		function() {
		$(this).find("a").stop().animate({backgroundPosition: '50% 28px'}, speed).removeClass('current');
		current.stop().animate({backgroundPosition: "50% 16px"}, speed).addClass("current");
		});

	$("#subnav li a:first").addClass("first");

	$("#worship").click(function() {
			window.location = "/worship";
			});
	$("#worship").hover(addPointer);
	$("#directions").click(function() {
			window.location = "/who-we-are/directions";
			});
	$("#directions").hover(addPointer);
	$("#wednesdays").click(function() {
			window.location = "/grow/midweek";
			});
	$("#wednesdays").hover(addPointer);
	$("#giving").click(function() {
			window.location = "/serve/online-giving";
			});
	$("#giving").hover(addPointer);


	function addPointer() {
		$(this).css("cursor", "pointer");
	}
});

