$(document).ready(function() {
	$("#nav a, a.teaserImg, #tabNav 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
					);
				}
			);
	
	// hide all sections
	$(".tab:visible").not('.first').hide();
	
	$('#tabNav a, .tabNav').click(function(){
		var theDiv = $(this).attr("href").substring(1);
		
		// hide all
		$("#tabs .tab:visible").hide();

		// show selected
		$("#" + theDiv).fadeIn('fast');
		
		// reset nav
		$("#tabNav a img").each(function(){
			if ($(this).attr("src").match(/-over/) ) {
				$(this).attr( "src", $(this).attr("src").replace(/-over/, "") );
			}
		});
		
		// set current hot
		var current = "#tabNav_" + theDiv;
		$(current).children(":first-child").attr( "src", $(current).children(":first-child").attr("src").replace(/\./, "-over.") );
		$(current).children(":first-child").attr( "originalsrc", $(current).children(":first-child").attr("src") );
		
		return false;
	});	
	
	
});

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

