$(document).ready(function(){
	
	// HOVER
	$("#nav 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
			theImg.attr("src", theImg.data("originalsrc")).data("originalsrc", null);
		}
	);
	
	// ADDITIONAL VIEWS
	$("#additionalViews a").click(function(e){
		e.preventDefault();
		$("#detailImage").attr('src', $(this).attr('href'));
		$("#additionalViews a img").removeClass('selected');
		$(this).children().addClass('selected');
	});
	

	$('.guarantee').click(function (e) {
		e.preventDefault();
		$("#guarantee").modal({
				opacity : '80', 
				closeHTML: '<a href="" class="closeLink">close</a>'
		});

	});	
	
	
});


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