function menuSwitch(item, before, after) {
	item.attr("src", item.attr("src").replace(before,after));
}

$(function() {
	// Select the menu item for the current page
	var currPageName = $("body").attr("id").replace("page","").replace("Sub","");
	var currLink = $("#link"+currPageName+" img");
	if (currLink.length) {
		currLink.addClass("selected");
		menuSwitch(currLink,"OFF","ON")
	}
	
	// Do menu bar image swapping
	$("#topNav img, #sideNav img").hover(
		function() {
			menuSwitch($(this),"OFF","ON")
		}, 
		function() {
			if (! $(this).hasClass("selected")) {
				menuSwitch($(this),"ON","OFF")
			}
		}
	);

	// Do external links in a new window in a way that's compliant with HTML Strict
	// http://www.sitepoint.com/article/standards-compliant-world/
	$("a[rel='external']").attr("target","_blank");
	
	// Enable cool slide open effect in the Thank You page.
	$(".trigger").click(function(event) {
		event.preventDefault();
		openSlide = $(".slide").not(":hidden");
		var clicked = $(this);
		if (openSlide.length) {
			openSlide.slideUp("normal", function() {
				clicked.next().slideDown();
			});
		} else {
			clicked.next().slideDown();
		}
	});			

	// Setup the defaults for thickbox based on the linked url.
	if($("#pageMusic").length) {
		$("#pageMusic td a").addClass("thickbox");
		$("#pageMusic td a[href*='lyrics']").each(function() {
			$(this).attr("href",$(this).attr("href")+"?TB_iframe=true&width=500&height=440");
		});			
		$("#pageMusic td a[href*='demo']").each(function() {
			$(this).attr("href",$(this).attr("href")+"?TB_iframe=true&width=420&height=220");
		});
	}
});

