/*

	Thumbnails

*/

$(function(){
	
	// Change images to black and white
	$("#gallery ul img").each(function(){
		
		var thisImg = $(this);
		var colorImg = thisImg.attr("src");
		var bwImg = colorImg.substring(0, (colorImg.length - 4));
		thisImg.attr("src",bwImg + "-bw.jpg");
		
	});

	var img, imgSrc;
	
	$("#gallery ul a").hover(
		function(){
		
			img = $(this).find("img"); // Find <img>
			imgSrc = img.attr("src"); // Get filename
			var newImgSrc = imgSrc.substring(0, (imgSrc.length - 7)); // Get filename without -bw and extension.
			
			img.attr("src",newImgSrc + ".jpg");	
	
		},function(){
		
			img.attr("src",imgSrc);
		
	});

});



/*
	
	Fancybox
	
*/


$(function(){
	
	$("#gallery-videos a").fancybox({
		frameWidth: 560,
		frameHeight: 340,
		overlayOpacity: 0.9
	});
	
	$("#gallery-images a").fancybox();
	
});



/*
	
	Form Validation
	
*/

$(function(){

	$(".form .btn-submit").click(function(){
		
		var formContainer = $(this).closest(".form");
		var requiredFields = $(".required[value='']",formContainer);
		
		$(".required[value!='']").removeClass("error").siblings("span.error").remove();
		
		requiredFields.addClass("error");
		
		requiredFields.each(function(){
		
			if( $(this).hasClass("error") ) {
		
				if( $(this).siblings("span.error").size() != 1 ) {
					$(this).parent().append("<span class='error'>Required</span>").find(".error").fadeIn();
				}
			}
		
		});
		
		if (requiredFields.length > 0) {
		
			return false;
			
		}
	
	});

});
