$(document).ready(function() {
	
	/*var $submit = $("input[type=submit]");
		if ($("input:empty")) {
		$submit.attr("disabled","disabled");
		} else {
		$submit.removeAttr("disabled");
		}*/
	
	/*$('#contactForm input').blur(function() {
		if( !$(this).val() ) {
		$('#contactForm dl dd:nth-child(1)').addClass('warning');
		} else if ($(this).val()) {
		$('#contactForm dl dd:nth-child(1)').removeClass('warning');		}
	});*/
	
	/*$('#contactForm').submit(function() {
		alert('Handler for .submit() called.');
		return false;
	});*/
	
	$('ul.navigation li a').click(function() {
		 var path = location.pathname;
		 var home = "/";
		$("a[href='" + [path || home] + "']").parents("li").each(function() {   
        $(this).addClass("active");
	});
	
	var path = location.pathname.substring(1);
     if ( path )
     $('ul.navigation a[href$="' + path + '"]').addClass('active');
	});
	 
	 $("ul.navigation a").each(function() {
   		   if (location.pathname.indexOf(this.href) > -1)
     	 {
      	  $(this).addClass("active");
     	 }
   	 });
	
	// start of image animation and loading for homepage1
	$('ul.thumbnails a').click(function(evt) {
		//don't follow link
		 evt.preventDefault();
		 //get path to new image
	   var imgPath = $(this).attr('href');
		 //get reference to old image
		var oldImage = $('#photo img');
			 //create HTML for new image
		var newImage = $('<img src="' + imgPath +'">');
			 //make new image invisible
			newImage.hide();
			 //add to the #photo div
			$('#photo').prepend(newImage);
			newImage.fadeIn(1000);
			 //fade out old image and remove from DOM
			oldImage.fadeOut(1000,function(){
		     $(this).remove();
				});
	});

		 //fade in new image
		$('ul.thumbnails a:eq(0)').click();
	// end of image animation and loading for homepage1
	
//$('a[href^=mailto:]').replace

$('#gallery img').each(function(i) {
	var imgFile = $(this).attr('src');
	var preloadImage = new Image();
    var imgExt = /(\.\w{3,4}$)/;
    preloadImage.src = imgFile.replace(imgExt,'_h$1');
		
	$(this).hover(function() {
			$(this).attr('src', preloadImage.src);
			},
		          function() {
			var currentSource=$(this).attr('src');
			$(this).attr('src', imgFile);
	}); // end hover
}); // end each
	
	$('#gallery a').click(function(evt) {
		//don't follow link
		 evt.preventDefault();
		 //get path to new image
	     var imgPath = $(this).attr('href');
		 //get reference to old image
		 var oldImage = $('#photo img');
		 //check to see if they're the same image
	
		 //create HTML for new image
		 var newImage = $('<img src="' + imgPath +'">');
		 //make new image invisible
		 newImage.hide();
		 //add to the #photo div
		 $('#photo').prepend(newImage);
		 //fade in new image
		 newImage.fadeIn(1000);
			 
		 //fade out old image and remove from DOM
		 oldImage.fadeOut(1000,function(){
		 $(this).remove();
		});
		 
	}); // end click
		
		$('#gallery a:first').click();
		
	// contact form ------------------------------------------------------------- //
	$('.error').hide();
	
	$('#fouldsComments').click(function() {
		$('.error').hide();
		var name = $('input#name').val();
		if (name == "") {
			$('label#errorName').show();
			$('input#name').focus();
			return false;
		}
		var email = $('input#email').val();
		if (email == "") {
			$('label#errorEmail').show();
			$('input#email').focus();
			return false;
		}
		var howFind = $('select#howFind').val();
		if (howFind == "") {
			$('label#errorHowFind').show();
			$('input#howFind').focus();
			return false;
		}
		var about = $('input#about').val();
		if (about == "") {
			$('label#errorAbout').show();
			$('input#about').focus();
			return false;
		}
		var message = $('textarea#comments').val();
		if (message == "") {
			$('label#errorComments').show();
			$('input#comments').focus();
			return false;
		}
		{
		$('#sent').html('<div id="message"></div>');
		$('#message').html("<h2>Contact form submitted!</h2>")
		.append("<p>We will be in touch if necessary.</p>")
		.hide()
		.fadeIn(1500, function() {
		$('#message').append("<img id='checkmark' src='/images/check.png' />");
        });
      }	
	  
	  });
	
	//var dataString = 'name'+ name + '&amp;email=' + email + '&amp;how did you find us=' + howFind + '$amp;subject' + subject + '&amp;message=' + message;
	//alert (dataString);return false;
	 

			
}); // end of function

runOnLoad(function(){
  $("input#name").select().focus();
});
                           


