if (!$.browser.msie || ($.browser.msie && $.browser.version > 6)) {
$(document).ready(function() {
	
	/* --------------------------------
	    Proper spacing for nav items
	    This has to be done in javascript because different browsers
	    render small-caps differently. To get the spacing right, it
	    has to be calculated on the fly.
	   -------------------------------- */
	var navWidths = 0;
	var navItems = $("#nav > li");
	var navLeftMargin = 30;
	
	navItems.each(function() {
		var theLink = $(this).children("a");
		theLink.wrapInner("<span></span>");
		navWidths += $("span", theLink).innerWidth();
	});
	var neededPadding = Math.floor((($("#nav").innerWidth() 
	                                 - navWidths
	                                 - navLeftMargin)
	                                / navItems.length)
	                               / 2) - 1;
	navItems.css({
		width: "auto",
		marginLeft: "1px",
		marginRight: "2px"
	});
	navItems.children("a").css({
		width: "auto",
		paddingLeft: neededPadding,
		paddingRight: neededPadding
	});
	navItems.eq(0).css({
		marginLeft: neededPadding
	});
	
	
	/* --------------------------------
	    Submenu animation and positioning
	   -------------------------------- */
	var menuParentLinks = $("#nav li:has(ul) > a");
	var collapsedHeight = "2em";
	var expandedHeight = "3.5em";
	menuParentLinks.each(function() {
		// on load, reposition child menus
		var submenu = $(this).parent().children("ul");
		var submenuId = $(this).parent().attr("id");
		submenu.show();
		
		var childWidths = 0;
		submenu.children("li").each(function() {
			childWidths += $(this).outerWidth() + 2;
		});
		
		submenu.children("li:last").css("margin-right", 0);
		
		submenu.css({
			width: (childWidths + 1) + "px"
		});
		submenu.css({
			left: ($(this).outerWidth() - submenu.outerWidth()) / 2 + "px"
		});
		
		if (submenu.offset().left < $("#nav").offset().left) {
			submenu.css("left", $("#nav").offset().left - $(this).offset().left + "px");
		}
		
		if (!$("#nav").hasClass(submenuId)) {submenu.hide();} else {
			$(this).parent().addClass("openmenu");
			$("#nav").removeClass(submenuId);
			submenu.show();
		}
		
	}).bind("click", function() {
		if ($("#nav").is(":animated")) {$("#nav").stop();}
		var $this = $(this).parent();
		var submenu = $this.children("ul");
		
		if (submenu.is(":visible")) {
			$("#nav").animate({
						height: collapsedHeight
					  }, 250, "", 
					  function() {
						$this.removeClass("openmenu");
						$("#nav").removeClass("openmenu");
						submenu.hide();
					  });
			
		} else {
			$this.addClass("openmenu");
			$("#nav").animate({
			                   height: expandedHeight
			                  }, 250).addClass("openmenu");
			submenu.show();
			menuParentLinks.not(this)
			               .parent().removeClass("openmenu")
			               .children("ul").hide();
		}
		
		return false;
	});
	
	
	/* --------------------------------
	    Image borders and FancyBox zoom
	   -------------------------------- */
	$("#inner img").each(function() {
		var theImage = $(this);
		var theHeight = theImage.height();
		var theWidth = theImage.width();
		
		if (theHeight >= 100 && theHeight <= 515 && theWidth >= 100 && theWidth <= 670) {
			var theLink = theImage.parent("a");
			if (theLink.is("*")) {
				if (theLink.get(0).href.match(/\.(jpe?g|gif|png)$/i)) {
					theLink.fancybox({
						hideOnContentClick: true,
						zoomSpeedIn: 300,
						zoomSpeedOut: 250
					});
				}
			}
			
			var padHeight = 20;
			var padWidth = 21;
			var masterClass = "framed-image";
			
			if (theHeight > 335 || theWidth > 435) {
				padHeight = 42;
				padWidth = 43;
				masterClass += " big";
			} else if (theHeight > 225 || theWidth > 290) {
				padHeight = 29;
				padWidth = 30;
				masterClass += " med";
			}
			
			theImage.wrap(
				'<div class="' + masterClass + '"><div class="the-image"></div></div>'
			).parent(
			).parent(
			).css({
				width: theWidth + padWidth,
				height: theHeight + padHeight
			}).append(
				'<div class="top-left"></div><div class="top-right"></div><div class="bottom-left"></div><div class="bottom-right"></div>'
			).children("div.top-left, div.bottom-right").css({
				width: theWidth,
				height: theHeight
			});
		}
	});
	
	$("a#calendar-link").fancybox({
		hideOnContentClick: true,
		zoomSpeedIn: 300,
		zoomSpeedOut: 250
	});
	
	$("h1, h2", "#inner").css("background-image", "none").append("<span class='trebleclef'></span>");
	
	if($("h3#header-postal").is("*")) {
		$("div#form-email, div#form-postal").hide();
		$("h3#header-email, h3#header-postal").wrapInner("<a></a>").children("a").css("cursor", "pointer").bind("click", function() {
			$("div#form-email, div#form-postal").not($(this).parent().next()).hide("fast");
			$(this).parent().next().toggle("normal");
			return false;
		});
	}
});
}