jQuery(document).ready(function($) {

	
	
	if (jQuery('#newsletterInput').length > 0) {
		jQuery('#newsletterInput').focus(inputFocus);
		jQuery('#newsletterInput').blur(inputBlur);
		jQuery('#newsletterInput').val("");
		jQuery('#newsSbmt').click(submitNewsletterSignup);
	}
	
	if (jQuery('.work').length > 0) {
		jQuery('.work .mainText a.zoom').fancyZoom({directory: '/wp-content/themes/acoustic/images/zoom', closeOnClick: true});
	}
	
	if (jQuery('#clientlogintab').length > 0) {
		jQuery('#username, #password').val("");
		jQuery('#username, #password').focus(inputFocus);
		jQuery('#username, #password').blur(inputBlur);
		
		jQuery('#clientlogintab').click(function() {
			  jQuery('#bclogin').slideToggle("slow");
			  return false;
		});
		jQuery('.signinbtn').click(function() {
			jQuery('#bcform').submit();			
		});
	}
	
	if (jQuery('#contact_form').length > 0) {
		jQuery('#contact_form :input').val("");
		jQuery('#contact_form input, #contact_form textarea, #newsLetterInput').focus(inputFocus);
		jQuery('#contact_form input, #contact_form textarea, #newsLetterInput').blur(inputBlur);
		jQuery('.submitbtn').click(submitContactForm);
	}
	
	if (jQuery('#carousel').length > 0) {
	    jQuery('#carousel').jCarouselLite({
	        visible:1,
	        easing: 'easeOutExpo',
	        speed:1500,
	        //start:1,
	        auto:4500,
	        circular:true
	    });
	}
});

function inputFocus() {
	jQuery(this).prev('label').hide();
}

function inputBlur() {
	if (jQuery.trim(jQuery(this).val()).length == 0) {
		jQuery(this).prev('label').show();
	}
}

function submitNewsletterSignup() {
	
}

/**
 * Called when contact form is submitted.
 */
function submitContactForm() { 
	//console.log(jQuery('#feedback_form').serialize());
	jQuery('#form_status h4').hide(); 
	if (!validateContactForm()) {
		return false;
	}
		
	jQuery('.busy').show();
	
	var formData = jQuery('#contact_form').serialize();
	jQuery.ajax({
		   type: 	'POST',
		   url: 	'/wp-admin/admin-ajax.php',
		   data:  	formData+'&action=contact_form',
		   dataType:'json',
		   success: function(resp) {
				if (resp.status == 'success') {
					jQuery('.busy').hide();
					jQuery('#contact_success').show();
					//_gaq.push(['_trackEvent', 'Contact Form', 'Submitted', 'Home Page Contact Form']);
					//_gaq.push(['_trackEvent', 'Contact Form Submission', 'Contact Form Submitted']);
				}
				else {
					
					//_gaq.push(['_trackEvent', 'Contact Form', 'Mail Not Sent - Server Error', 'Home Page Contact Form']);
					jQuery('#form_container .busy').hide();
					jQuery('#form_container #contact_fail').show();
				}
				jQuery('.submitbtn').show();
			},
		   error: function () {
				//_gaq.push(['_trackEvent', 'Contact Form', 'Mail Not Sent - Couldn\'t Communicate with server', 'Home Page Contact Form']);
				jQuery('#form_container .busy').hide();
				jQuery('#form_container #contact_fail').show();
				
			}
	});
	return false;
}

function validateContactForm() {
	var result = jQuery('#name_field').val() && jQuery('#name_field').val().length > 0 &&
					jQuery('#email_field').val() && jQuery('#email_field').val().length > 0 &&
					jQuery('#msg_field').val() && jQuery('#msg_field').val().length > 0;
	if (!result) {
		jQuery('#required_fields').show();
	}
	return result;
		
					

}

function disableFormFields() {
	jQuery("#contact_form :input").each(
		function() {
			jQuery(this).disabled = true;			
		}
	);
}

function enableFormFields() {
	jQuery("#contact_form :input").each(
			function() {
				jQuery(this).disabled = false;			
			}
	);
}

