$(document).ready(function(){
	
	
	
	
	///////////// BACKGROUND RESIZE
	$('#bg').jmc_resizr({
		cropType : 'fill_outer',
		binding : {
			vertical : 'top',
			horizontal : 'center'
		}
	},
		function() {
			$('#bg').fadeIn('slow');
	});
	
	///////////// SLIDERS
	$(".slider-trigger").click(function(e){
		e.preventDefault;
		$this = $(this);
		var isVisible = $this.next().is(":visible");
		
		$(".slider-content").stop(true,true).slideUp('slow');
		$(".trigger-symbol").attr('src', '/images/layout/slider/plus.png');
		
		var $pie = $this.closest('.slider');
		
		
		if (!isVisible) {
			$this.find(".trigger-symbol").attr('src', '/images/layout/slider/minus.png');
			$this.next().stop(true,true).slideDown('slow',function(){
				$('html,body').animate({scrollTop: $pie.offset().top}, 'slow');
				});
			
		}
						
		return false;
	});
	
	
	
	$("#contact-form").submit(function(e){
		var $this = $(this);
		
		var $nameField = $this.find("input[name=full_name]");
		if (!$nameField.val())
			{
				alert('Please enter your Name.');
				$nameField.focus();
				return false;
			}	
	
		var $emailField = $this.find("input[name=email_real]");
		if (!$emailField.val())
			{
				alert('Please enter your Email.');
				$emailField.focus();
				return false;
			}
		
		var $phoneField = $this.find("input[name=phone]");
		if (!$phoneField.val())
			{
				alert('Please enter your Phone.');
				$phoneField.focus();
				return false;
			}	
		

		 var params = $this.serialize();
		$.post("/cgi-bin/contact.cgi", params + '&random=' + Math.random(),
		   	function(data){
			$this.find(".btn-submit").fadeOut('slow', function(){
				$this.find("input[type=text], input[type=email], textarea").val('')
				$this.find(".btn-submit").after(data);
				$("#response").fadeIn('slow');
			});
			
			setTimeout(function(){
					$("#response").fadeOut('slow',function(){
						$("#response").remove();
						$this.find(".btn-submit").fadeIn('slow');
					});
				}, 10000);
	
		});
		
		return false;
		
	});
	
	
	$("#easement-form").submit(function(e){
		var $this = $(this);
		
		var $nameField = $this.find("input[name=full_name]");
		if (!$nameField.val())
			{
				alert('Please enter your Name.');
				$nameField.focus();
				return false;
			}	
	
		var $emailField = $this.find("input[name=email_real]");
		if (!$emailField.val())
			{
				alert('Please enter your Email.');
				$emailField.focus();
				return false;
			}
		
		var $phoneField = $this.find("input[name=phone]");
		if (!$phoneField.val())
			{
				alert('Please enter your Phone.');
				$phoneField.focus();
				return false;
			}	
		

		 var params = $this.serialize();
		$.post("/cgi-bin/easement_inquiry.cgi", params + '&random=' + Math.random(),
		   	function(data){
			$this.find(".btn-submit").fadeOut('slow', function(){
				$this.find("input[type=text], input[type=email], textarea").val('')
				$this.find(".btn-submit").after(data);
				$("#response").fadeIn('slow');
			});
			
			setTimeout(function(){
					$("#response").fadeOut('slow',function(){
						$("#response").remove();
						$this.find(".btn-submit").fadeIn('slow');
					});
				}, 10000);
	
		});
		
		return false;
		
	});
	
	
	$("#vision-form").submit(function(e){
		var $this = $(this);
		
		 var params = $this.serialize();
		$.post("/cgi-bin/vision.cgi", params + '&random=' + Math.random(),
		   	function(data){
			$this.find(".btn-submit").fadeOut('slow', function(){
				$this.find("textarea").val('')
				$this.find("input:radio").attr("checked", false);
				$this.find(".btn-submit").after(data);
				$("#response").fadeIn('slow');
			});
			
			setTimeout(function(){
					$("#response").fadeOut('slow',function(){
						$("#response").remove();
						$this.find(".btn-submit").fadeIn('slow');
					});
				}, 10000);
	
		});
		
		return false;
		
	});
	
	
	
});









