﻿
// before rendering the page...
$(document).ready( function() {
	// figure out server
	var server = window.location.protocol + "//" + window.location.host;

	// main menu highlighting
	$('#nav ul a').each(function(){
		var href = $(this).attr('href');
		//adding special cases for giving and contact pages
		if(window.location.pathname.indexOf("giving")==1 || window.location.pathname.indexOf("contact")==1) {
			$('#nav ul a[href="/about/"]').addClass("current");
			$('#nav ul ul a[href="/about/"]').removeClass("current");
			//$(this).addClass("current");
		}
		if( window.location.href.indexOf( server + href ) >= 0 && href.length > 1 ) {
			$(this).addClass("current");
		}
	});

	// section menu highlighting
	var $currentAnchor = null;
	$('#nav ul li ul li a').each(function(){
		var href = $(this).attr('href');
		if( window.location.href.indexOf( server + href ) >= 0 && href.length > 1 ) {
			$(this).addClass("current");
			if ($currentAnchor != null) {
				$currentAnchor.removeClass("current"); // remove top-level section highlight
			} else {
				$currentAnchor = $(this);	
			}
		}
	});
	
	// add striping to tables and highlight a row on rollover
	$("tr")
		.mouseover(function() {
			$(this).addClass("rowhighlight");
		})
		.mouseout(function() {
			$(this).removeClass("rowhighlight");
		});
	$("tr:even").addClass("alt");
});

// page is fully loaded...
$(window).load(function () {
	// image captions
	$("#content img, #contact img").each(function() {
		$div = $(this).wrap("<div></div>").parent();
		$div.addClass("imgcaption").css({ width:$(this).width() });
		
		var text = "";
		if ($(this).attr("title"))
			text =  $(this).attr("title");
		else if ($(this).attr("alt"))
			text =  $(this).attr("alt");
		
		if (text != "")
			$div.append("<p class=\"imgcaptionTXT\" style=\""+$(this).width()+"px\">"+text+"</p>");
		
		if ($(this).hasClass("insetRight")) 
			$div.addClass("insetRight");
		
		if ($(this).hasClass("insetLeft")) 
			$div.addClass("insetLeft");
		
		$(this).attr("class","imgcaptionIMG");
	});
});