$(document).ready(function() {
	$('.nav a').handleMouseovers();
});

// handle mouseovers, mouseouts, preloading of nested <img>s
(function($) {
	$.fn.handleMouseovers = function() {

		$offsrc	= '_off';
		$onsrc	= '_fork';

		// preload images
		this.each(function() {
			// Set the original src
			rollsrc = $(this).children("img").attr("src");
			rollON = rollsrc.replace($offsrc,$onsrc);
			newImg = new Image(); 				// create new image obj
			$(newImg).attr("src", rollON);	// set new obj's src
		});

		this.mouseover(function(){
			imgsrc = $(this).children("img").attr("src");
			if (typeof(imgsrc) != 'undefined') {
				imgsrcON = imgsrc.replace($offsrc,$onsrc);
				$(this).children("img").attr("src", imgsrcON);
			}
		});

		this.mouseout(function(){
			if (typeof(imgsrc) != 'undefined') {
				$(this).children("img").attr("src", imgsrc);
			}
		});
		return this;
	};
})(jQuery);

