$(document).ready(function() {

	// NAV HOVER
	$("#nav a").hover(
				// over
				function(){
					// store the original image src
					$(this).children(":first-child").attr( "originalsrc" , $(this).children(":first-child").attr("src") );
					
					// add -over to the image
					$(this).children(":first-child").attr( "src", $(this).children(":first-child").attr("src").replace(/-active/, "") );
					$(this).children(":first-child").attr( "src", $(this).children(":first-child").attr("src").replace(/\.gif/, "-over.gif") );
					

					$("#panel_" + $(this).attr('id') ).show();
					
				},
				
				// out
				function(){
					// replace the original src
					$(this).children(":first-child").attr(
						"src", $(this).children(":first-child").attr("originalsrc")
					);
					
					$(this).children(":first-child").attr(
						"originalsrc", null
					);
					
					$(".hoverPanel").hide();
				}
			);


	// SUBNAV HOVER
	$("#subnav a").hover(
				// over
				function(){
					// store the original image src
					$(this).children(":first-child").attr( "originalsrc" , $(this).children(":first-child").attr("src") );
					
					// add -over to the image unless it is already -over
					if (!$(this).children(":first-child").attr("src").match(/-over/) ) {
						$(this).children(":first-child").attr( "src", $(this).children(":first-child").attr("src").replace(/\.gif/, "-over.gif") );
					}
					
				},
				
				// out
				function(){
					// replace the original src
					$(this).children(":first-child").attr(
						"src", $(this).children(":first-child").attr("originalsrc")
					);
					
					$(this).children(":first-child").attr(
						"originalsrc", null
					);
				}
			);

	
});

window.onload = function() {
		// preload
		$("#nav a img, #subnav a img").each(
			function() {
				if (!$(this).attr("src").match(/-over/) && !$(this).attr("src").match(/-active/) ) {
					$("<img>").attr( "src", $(this).attr("src").replace(/\.gif/, "-over.gif") );
				}
			}
		);
}



function clearField(field, defaultText) {
	if (field.value == defaultText) {
		field.value = "";
	}
}
