$(function(){
	$('.section').each(function(){
		$(this).children('.thumb:first').addClass("first");
		$(this).tooltip({
			track: true, 
			delay: 0, 
			fade: 250 
		});
		if ($(this).children('.thumb').size() == 1) $(this).addClass('section-with-1-thumb');
		if ($(this).children('.thumb').size() == 2) $(this).addClass('section-with-2-thumb');
		if ($(this).children('.thumb').size() == 3) $(this).addClass('section-with-3-thumb');
		if ($(this).children('.thumb').size() == 4) $(this).addClass('section-with-4-thumb');
		if ($(this).children('.thumb').size() == 5) $(this).addClass('section-with-5-thumb');
	});

	$('#slider').nivoSlider({
		effect: 'fold',
		animSpeed:500,
		pauseTime:6000
	});
	
	$('ul#testimonials-animated').animatedinnerfade({ 
		speed: 'normal', 
		timeout:  9000, 
		type: 'sequence', 
		containerheight: '251px', 
		containerwidth: '226px', 
		animationSpeed: 0, 
		animationtype: 'fade',
		controlBox: 'show',
		controlBoxClass: 'mycontrolboxclass'
	});


	$('#contact-form INPUT, #contact-form TEXTAREA, #contact-form BUTTON').focus(function(){
		$(this).addClass('active');
	});
	$('#contact-form INPUT, #contact-form TEXTAREA, #contact-form BUTTON').blur(function(){
		$(this).removeClass('active');
	});


	$('#btn-submit').click(function(){
		var errors = new Array();
		if ($('#uname').val() == '') errors[errors.length] = '"Your Name"';
		if ($('#ucontacts').val() == '') errors[errors.length] = '"Email or Phone Number"';
		if ($('#message').val() == '') errors[errors.length] = '"Message"';
		if (errors.length != 0){
			var errortxt = errors.join(', ');
			$('#errormsg').show();
			$('#errormsg').text('Please enter the following required fields: ' + errortxt);
		}
		else{
			$('#contact-form').submit();
		}
	});
	
	$('#contact-form').submit(function(){
		var form = $(this);
		$.getJSON(form.attr('action')+'?'+form.serialize(),{},function(r){
			if(r.captchaError==1){
				alert('Wrong captcha code, please try again!');
				$('ucaptcha').focus();
			}
			if(r.emailSent==1){
				location.href='thank-you.shtml';
			}
		});
		
		return !1;
	});
	
/*
	$(".section a.thumb").fancybox({
		'zoomOpacity'			: true,
		'overlayShow'			: false,
		'zoomSpeedIn'			: 500,
		'zoomSpeedOut'			: 500
	});
*/

			$("a[rel^='group']").prettyPhoto({
				animationSpeed: 'normal', /* fast/slow/normal */
				padding: 40, /* padding for each side of the picture */
				opacity: 0.35, /* Value betwee 0 and 1 */
				showTitle: true, /* true/false */
				allowresize: true, /* true/false */
				counter_separator_label: '/', /* The separator for the gallery counter 1 "of" 2 */
				theme: 'dark_rounded', /* light_rounded / dark_rounded / light_square / dark_square */
				callback: function(){}
			});

	
});

