google.setOnLoadCallback(function() {
	
	// Email Callout
	$.extend( $.easing,
		{
			easeOutQuart: function(x, t, b, c, d) {
				if ((t/=d/2) < 1) return c/2*t*t*t*t + b;
				return -c/2 * ((t-=2)*t*t*t - 2) + b;
			},
			easeInQuart: function(x, t, b, c, d) {
				return c*(t/=d)*t*t*t + b;
			}
		});
	$('#email-callout a').click(function() {
		$('#email-overlay').fadeIn('fast',function() {
			$('#envelope-holder').show();
			$('#envelope-holder').animate(
				{
					opacity:1,
					marginTop:'+=200px'
				},
				600,
				'easeOutQuart',
				function() {
					$('form',this).fadeIn(100);
				});
		});
		
		return false;
	});
	$('#email-overlay').click(function() {
		em_close($('#envelope-holder'));
		$(this).fadeOut('fast');
	});
	$('#envelope img.close').click(function(){
		em_close($('#envelope-holder'));
	});
	function em_close(t)
	{
		$('form',t).fadeOut(100,function() {
			$(t).animate(
				{
					opacity:0,
					marginTop:'-=200px'
				},
				300,
				'easeInQuart',
				function() {
					$(this).css({marginTop:'0'}).hide();
					$('#email-overlay').fadeOut('fast');
				});
		});
	}
	// EMAIL LIST FORM VALIDATION
	$('div#envelope form').validate({
		rules: {
			name: 'required',
			email: {
				required: true,
				email: true
			}
		},
		messages: {
			name: 'Please enter your name.',
			email: {
				required: 'Please enter your email address.',
				email: 'Please enter a valid email address.'
			}
		},
		errorClass: 'error',
		errorContainer: '#envelope .error-box',
		errorLabelContainer: '#envelope .error-box',
		wrapper: 'p'
	});
	
	
	
	// Our Team Tabs
	if ($('#content div.team').length || $('#content div.testimonials').length) {
		$('#content div.team .tab,#content div.testimonials .tab')
			.not('.tab-index')
			.css({opacity:0,display:'none'});
		$('#content div.team ul.index a,#content div.testimonials ul.index a')
			.click(function() {
				var tab = this.className;
				if ($('#content div.team').length)
				{
					var pre = '#content div.team div.';
					var newHeight = $(pre+tab).height()+50;
					var newPic = '';
					if (tab=='index') newPic = 'obj_group_picture.png';
					if (tab=='tab-a') newPic = 'obj_janae_picture.png';
					if (tab=='tab-b') newPic = 'obj_jason_picture.png';
					if (tab=='tab-c') newPic = 'obj_jeremy_picture.png';
					if (tab=='tab-d') newPic = 'obj_tami_picture.png';
					if (tab=='tab-e') newPic = 'obj_virg_picture.png';
					if (tab=='tab-f') newPic = 'obj_aaron_picture.png';
				}
				else if ($('#content div.testimonials').length)
				{
					var pre = '#content div.testimonials div.';
					var newHeight = $(pre+tab).height()+50;
					var newPic = '';
					if (tab=='index') newPic = 'obj_group_picture.png';
					if (tab=='tab-a') newPic = 'obj_janae_picture.png';
					if (tab=='tab-b') newPic = 'obj_jason_picture.png';
					if (tab=='tab-c') newPic = 'obj_jeremy_picture.png';
				}
				if ($(pre+'tab-index').css('opacity')==1)
				{
					$(pre+'tab-index')
						.animate({
							opacity:0
						},200,function() {
							$(this).hide();
						});
					$('#content div.team,#content div.testimonials')
						.animate({
							height:newHeight+'px'
						},400,function(){
							$(pre+tab)
								.show()
								.animate({
									opacity:1
								},400);
						});
				} else {
					$(pre+'tab')
						.animate({
							opacity:0
						},200,function() {
							$(this).hide();
						});
					$('#content div.team,#content div.testimonials')	
						.animate({
							height:newHeight+'px'
						},400,function(){
							$(pre+'tab').stop();
							$(pre+tab)
								.show()
								.animate({
									opacity:1
								},400);
						});
				}
				$('#object').fadeOut('200',function() {
					$(this).css({backgroundImage:'url(/images/uploads/'+newPic+')'}).fadeIn('200');
				});
				return false;
			});
	}
	
	
	
	// Contact Form Validation
	if ($('form#contact').length)
	{
		$('form#contact').validate({
			rules: {
				fname: 'required',
				lname: 'required',
				street1: 'required',
				city: 'required',
				state: 'required',
				postalcode: 'required'
			},
			messages: {
				fname: 'First Name',
				lname: 'Last Name',
				street1: 'Address',
				city: 'City',
				state: 'State',
				postalcode: 'Zip'
			},
			errorClass: 'error',
			errorContainer: '.error-box',
			errorLabelContainer: '.error-box ul',
			wrapper: 'li'
		});
	}
});
