jQuery(document).ready(function(){
	$('body').addClass('hasJQ');
	if ($('#our_work').length) {
		tabber();
	}
	if ($('#cta_form').length) {
		$('#cta_form').validate({
			errorClass:"invalid",
			errorElement:"span",
			success: function(){
				$(this).addClass('valid').parent("li").find("span").eq(0).remove();
			},
			errorPlacement: function(error, element) {
			     error.appendTo( element.parent("li") ).parent("li").find("span").eq(0).remove();
			   },
			rules: {
				name: {
				       required: true,
				       minlength: 3
				     },
				message: {
				       required: true,
				       minlength: 20
				     },
				email: {
					required:true,
					email:true
				}
			},
			submitHandler: function(form) {
				// prepare Options Object 
				var options = { 
					resetForm:true,
				    success:function(rtn) { 
				        if(rtn == "success") 
						{
							$('#cta_form ul li').remove();
							var successMessage = "<li class='success'>Success! We got your message.<br />We&#8217;ll be in touch within 24 hours.</li>";
							$('#contact_form').append(successMessage);
						}
				    } 
				};
			   	$(form).ajaxSubmit(options);
			}
		}); // ends validate
	};
});

// Allows a tabbed interface for the sub sections
function tabber() {
	var tabContainers = $('#our_work .page_body article');
	tabContainers.hide().filter(':first').show();
	
	jQuery('#portfolio_listing a').click(function () {
		tabContainers.hide();
		tabContainers.filter(this.hash).fadeIn(750);
		jQuery('#portfolio_listing li').removeClass('active');
		jQuery(this).parent().addClass('active');
		return false;
	}).filter(':first').click();
};
