$(document).ready(function() {
	
	
	
	$("#nav a:not('.noHover'), #states 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(/\./, "-over.") );
					}
					
				},
				
				// 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
					);
				}
			);
	
	$('a.accidentShow').click(
		function() {
			$(this).nextAll("div.accidentLayer:first").slideDown("slow");   		
    		return false;
  	});
	
	
	// track email events
	$(".contentPad a").each(function(){
		var href = $(this).attr('href');
		if ( href.match(/^mailto:/) ) {
			$(this).click(function() {
				var hrefClean = href.substring(7);
				pageTracker._trackEvent('Send An Email', hrefClean);
            });
		}
	});
	
	$(".fancyField").each(function(){
		var field = $(this);
		field.data('originalValue', field.attr('value'));
		
		field.bind('focus', function(){
			if (field.attr('value') == field.data('originalValue')) {
				field.attr('value', '');
			}
		});
		
		field.bind('blur', function(){
			if (field.attr('value') == '' ) {
				field.attr('value', field.data('originalValue'));
			}
		});
		
	});
	
});

window.onload = function() {
		// preload
		$("#nav a:not('.noHover') img, #states a img").each(
			function() {
				if (!$(this).attr("src").match(/-over/) ) {
					$("<img>").attr( "src", $(this).attr("src").replace(/\./, "-over.") );
				}
			}
		);
}


