$(document).ready(function(){
	$("#siteNav a").hover( 
		// over
		function(){
			var theImg = $(this).find('img:first');
			// store the original image src
			theImg.data( "originalsrc" , theImg.attr("src") );
			
			// add -over to the image unless it is already -over
			if (!theImg.attr("src").match(/-over/) ) {
				theImg.attr( "src", theImg.attr("src").replace(/\./, "-over.") );
			}
			
		},
		
		// out
		function(){
			var theImg = $(this).find('img:first');
			// replace the original src
			if (theImg.data("originalsrc") !== null) {
				theImg.attr("src", theImg.data("originalsrc"));
			}
		}
	);

	$('input:text[placeholder]').placeholderLabel();

    $("#siteNav li").hoverIntent(function(){
		$('ul:first',this).css('display', 'block');
    }, function(){
   	     $('ul:first',this).css('display', 'none');
    });
	
});

window.onload = function() {
		// preload
		$("#siteNav a img").each(
			function() {
				if (!$(this).attr("src").match(/-over/) && !$(this).attr("src").match(/-active/) ) {
					$("<img>").attr( "src", $(this).attr("src").replace(/\./, "-over.") );
				}
			}
		);

}
