/*
This javascript file provides all the custom scripting which controls
the scroll effect, rollover effect, lighbox effect, form validation, 
and ajax form abilities.
*/

$(function() {	   
	
	/* SCROLL TO EFFECT ---------------------------------------------- */
	$(".scrollto").click(function(event){
		
		//prevent default action for scrollto links
		event.preventDefault(); 
		
		//scroll to the top of the element which was identified by the id name in the link 
		$('html,body').animate({scrollTop:$("#"+this.href.split("#")[1]).offset().top},'slow','swing');
		
	});	
	
	
	/* OPACITY ROLLOVER EFFECT --------------------------------------- */
	
	//set thumbnail up state opacity
	var tmbUp = .50; 
	$('ul.grid a img').css({'opacity':tmbUp});
	
	
	$("ul.grid a img").hover(function(){
    	
		//fade thumb in on mouseover. 
		$(this).fadeTo('fast', 1);
		
		},function(){
		
			//fade thumb out on mouseout. 
			$(this).fadeTo('slow', tmbUp);
		}
	);
	
	
	/* LIGHTBOX EFFECT (FANCYBOX PLUGIN) ----------------------------- */
	
	$('a.lbox').fancybox({
		'padding':0, 
		'titleShow': false,
		'overlayOpacity': .6,
		'overlayColor': '#000',
		'autoscale': false
		//for more options visit http://fancybox.net/api
	});

		
	/* CONTACT FORM VALIDATION (PLUGIN) AND AJAX (PLUGIN) ------------- */
	
	// fade in loading text
	$('.loading').ajaxStart(function(){
   		$(this).fadeIn();
 	});
	
	// bind form using form validate plugin
	$('#htmlForm').validate({
	  rules: {
		ruhuman: {
		  required: true,
		  range: [7, 7]
		}
	  }
	});
	
	// bind form using form plugin 
	$('#htmlForm').ajaxForm({ 
	
		// target identifies the element(s) to update with the server response 
		target: '#messageContainer', 
		
		// success identifies the function to invoke when the server response has been received
		success: function() { 
		
			// hide success message
			$('#messageContainer').hide();
			
			// slide up form, then slide down success/thanks message
			$("#htmlForm").slideUp('slow', function() {
			
			$('#messageContainer').slideDown('slow');	     
			
			});
		}
	}); 
	
});
