(function($) {
	window.$fn = {
		nav: function() {
			$("#nav li").each(function() {
				var npid = 9999;
				var a = this.getElementsByTagName("a")[0];
				var t = "pid"+npid;
				if (a.id == t) {
					$(this).addClass("active temple");
					$(this).parents("ul:not(#nav),li").addClass("active temple");
				}
			});
			$("#nav li.active>a").addClass("active");
			$("#nav li.active>ul").addClass("active temple");
		},
		setnav: function(l1, l2) {
			var count = 0;
			var that;
			$("#nav>li").each(function() {
				if (count == l1) {
					$(this).addClass("active temple");
					that = $(this).find("li");
				}
				count++;
			});
			count = 0;
			if (that.length > 0) {
				that.each(function() {
					if (count == l2) {
						$(this).addClass("active temple");
					}
					count++;
				});
			}
			$("#nav li.active>a").addClass("active");
			$("#nav li.active>ul").addClass("active temple");
		},
		equal: function(col1, col2) {
			col1 = col1 || "#main";
			col2 = col2 || "#page .sidebar:eq(0)";
			p = "#page";
			h = Math.max($(col1).height(), $(col2).height(), $(p).height());
			minh = 565;
			if (h < minh) {
				$(col1).height(minh + "px");
				$(col2).height(minh + "px");
			}
			//$(col1).height($(p).height() + "px");
			//$(col2).height($(p).height() + "px");
			//if($(col1).height() <= $(col2).height()) {
				//$(col1).height($(col2).height() + "px");
			//} else {
				//$(col2).height($(col1).height() + "px");
			//}
		}
	}
	$(document).ready(function() {
		$("#nav a").bind("mouseover", function() {
			var that = $(this).parents("li")[0];

			var ul = that.getElementsByTagName("ul")[0];

			if(typeof ul != "undefined" || $(that).parents("li").length > 0) {
				$("#nav *").removeClass("active");
			} else {
				$fn.nav();
			}

			$(that).parents("ul,li").addClass("active");

			$(ul).addClass("active")

			if($(that).hasClass("temple") || $(that).parents("li").eq(0).hasClass("temple")) {
				$(ul).find(".temple").addClass("active");
			}

			$("#nav li.active>a").addClass("active");
		});

		$("#nav>li").bind("mouseout", function() {
			$("#nav *").removeClass("active");
			$fn.nav();
		});
		if($("#affiliations").length > 0) {
			$("#affiliations").cycle({
				fx: "fade",
				speed: 1200
			});
		}
		//$fn.equal();
	});
})(jQuery)


