// <![CDATA[

function playMovie() { document.getElementById("flash-phone").Play(); }
function stopMovie() { document.getElementById("flash-phone").StopPlay(); }

$(function(){
	$(window).load(function() {
		dropDownPhone();
	});
	/*
	var windowWidth = $(document).width() + "px";
	$(".cloud-one").animate({left:windowWidth},60000,function callback() {
		animateCloudOne();	
	});
	function animateCloudOne () {
		$(".cloud-one").css({left:"-343px"}).animate({left:windowWidth},60000);
		$(".cloud-one").animate({opacity:1.0},10000,function callback() {
			$(".cloud-one").stop().animate({left:windowWidth},10000,function callback() { animateCloudOne(); });
		});
	}
	
	$(".cloud-two").animate({left:windowWidth},80000,function callback() { animateCloudTwo(); });
	function animateCloudTwo() {
		$(".cloud-two").stop().animate({left:windowWidth},80000,function callback() { animateCloudTwo(); });
	}
	$(".cloud-three").animate({left:windowWidth},80000,function callback() { animateCloudThree(); });
	function animateCloudThree() {
		$(".cloud-three").stop().animate({left:windowWidth},80000,function callback() { animateCloudThree(); });
	}
	
	
	$(".cloud-four").animate({left:windowWidth},40000,function callback() { animateCloudFour(); });
	function animateCloudFour() {
		$(".cloud-four").stop().animate({left:windowWidth},80000,function callback() { animateCloudFour(); });
	}
	*/
	$("#start-video").click(function() {
		playMovie();
		$("#start-video").fadeOut(400);
		$("#stop-video").fadeIn(400);
	});
	$("#stop-video").click(function() {
		stopMovie();
		$("#start-video").fadeIn(400);
		$("#stop-video").fadeOut(400);
	});
});


function showPlayButton() {
	$(function(){
		$("#start-video").fadeIn(400);
		$("#stop-video").fadeOut(400);
	});
	
}
function dropDownPhone() {
	$(function(){
		$("#phone").animate({top:"145px"},600);
		$("#phone-shadow").fadeIn(800,function callback() {
			$("#phone-screenshot").fadeIn(300);	
		});
	});
}

/* Feedback form JS */
$(document).ready(function() {
	$("#show-captcha").click(function() {
		
		//$('.error').hide();
		var error = false;
		var name = $("input#name").val();
		if (name == "") {
			//$("label#name_error").show();
			$("input#name").addClass('form-error');;
			error = true;
			$(".error-name").fadeIn(300);
		} else {
			$("input#name").removeClass('form-error');
			$(".error-name").fadeOut(300);
		}
		var email = $("input#email").val();
		var regex = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
		if (email == "" || !regex.test(email)) {
			//$("label#email_error").show();
			$("input#email").addClass('form-error');
			error = true;
			$(".error-email").fadeIn(300);
		} else {
			$("input#email").removeClass('form-error');
			$(".error-email").fadeOut(300);
		}
		var message = $("textarea#message").val();
		if (message == "") {
			//$("label#message_error").show();
			$("textarea#message").addClass('form-error');
			$(".error-message").fadeIn(300);
			error = true;
		} else {
			$("textarea#message").removeClass('form-error');
			$(".error-message").fadeOut(300);
		}
		if (error) { return false; $('.form-error:first').focus(); }
		$("#hidden-form").fadeOut(300);
		$("#hidden-captcha").fadeIn(500);
	});
});


$(document).ready(function() {
	
	$("#submit").click(function() {
	
		var formData = {
			realname: $("input#name").val(),
			email: $("input#email").val(),
			message: $("textarea#message").val(),
			recaptcha_challenge_field:  $("input#recaptcha_challenge_field").val(),
			recaptcha_response_field:  $("input#recaptcha_response_field").val(),
			mail_options: "CharSet=UTF-8,TemplateMissing=n/a,Exclude=_;recaptcha_challenge_field;recaptcha_response_field,FromLineStyle=QuotedNameRouteAddr,KeepLines"
		};

		var html = $.ajax({
			type: "POST",
			url: "/feedback/formmail.php",
			cache: false,
			data: formData,
			success: function(data, textStatus) {
				
				if (data.indexOf("SUCCESS") != -1) {
					$("#hidden-captcha").fadeOut(0);
					$(".footer-title2").fadeOut(0);
					$("#hidden-thanks").fadeIn(500);
					$(".footer-title3").fadeIn(500);
					
					// send Optify tracking
					//$.post("http://service.optify.net/form/submit", $("#contact").serialize());
					
				} else if (data.indexOf("incorrect-captcha-sol") != -1) {
					Recaptcha.reload();
					$("#hidden-captcha h6").text("The reCAPTCHA wasn't entered correctly. Please try again.").css({color:"red"});
				} else {
					// alert("Response: "+data); 
					$("#hidden-captcha").fadeOut(0);
					$("#hidden-error").fadeIn(500);
				}
			},
			error: function(XMLHttpRequest, textStatus, errorThrown) {
				// alert("Error Response: "+textStatus+" ! "+errorThrown); 
				$("#hidden-captcha").fadeOut(0);
				$("#hidden-error").fadeIn(500)
			}  
		});
		
		return false;
	}); 
	
	$(".edit-message").click(function() {
		$("#hidden-captcha").fadeOut(300);
		$("#hidden-error").fadeOut(300);
		$("#hidden-form").fadeIn(500);
	});

});


