$(document).ready(function() {
	/* Add special classes for styling */
//	$("#main_nav li:last").addClass('last');
	
	/* Preload our hover images */
	$("#main_nav img[rel]").each(function() {
		var img = new Image;
		img.src = $(this).attr('rel');
	});
	
	/* Attach our mouseover image-swap effect */
	$("#main_nav img[rel]").hover(function() {
		var hov_img = $(this).attr('rel');
		
		if(hov_img) {
			var static_img = $(this).attr('src');
			
			$(this).attr('src', hov_img);
			$(this).attr('oldsrc', static_img);
		}
	}, function() {
		var static_img = $(this).attr('oldsrc');
		
		if(static_img) {
			$(this).attr('src', static_img);
		}
	});
	
	/* Attach our animated hide-a-submenu effect */
	$("#main_nav li:has(ul)").toggle(function() {
		$(this).children("ul").slideDown();
		
		/* We don't want it to hide when a submenu is clicked */
		$(this).children("ul").click(function(event) {
			event.stopPropagation();
		});
	}, function() {
		$(this).children("ul").slideUp();
	});

	/* Make the currently selected section visible */
	$("#main_nav li:has(ul)").each(function() {
		var match = 0;
		$(this).find("a").each(function() {

			if ($(this).attr('href') == window.location.pathname) {
				match = 1;
			}
		});
		
		if(match) {
			$(this).click();
		}
	});
});
