$(function () {
  $('.error').hide();
  $('#loading').hide();
  
  $('input.text-input').css({backgroundColor:"#FFFFFF"});
  $('input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });

  $(".button").click(function() {
		// validate and process form
		// first hide any error messages
    $('.error').hide();
		
	var email = $("input#email").val();
	if (email == "" || email.indexOf('@') == -1) {
      $("label#email_error").show();
      $("input#email").focus();
      return false;
    }
    
    if ($("input#betabox:checked").val()) {
    	var beta = "Yes";
    } else {
    	var beta = "No";
    }
    /*var beta = $("input#betabox:checked").val();*/
    

		var dataString = 'email='+ email + '&beta=' + beta;
		//alert (dataString);return false;
		
	$("#submitBtn").hide();
	$('#loading').fadeIn("slow");
	$("form").fadeOut("slow");
		/*return false;*/
	$.ajax({
      type: "POST",
      url: "js/bin/process.php",
      data: dataString,
      success: function() {
        $('#theform').html("<div id='message'></div>");
        $('#message').html('<h2 class="form" style="padding: 0px 0px 10px 0px;">Contact Form Submitted!</h2>')
        .append('<p style="font-size: 13px;">Thank you for your interest. We will be in touch soon.</p>')
        .hide()
        .fadeIn(1500, function() {
        });
        Cufon.replace('h2.form', { fontFamily: 'TrashHand' });
        Cufon.replace('p', { fontFamily: 'Rockwell' });
        /*alert('should be success');*/
      }
     });
    return false;
	});
	
	var adVar = 0;
	var conVar = 0;
	
	function conOpen(newTop) {
		$('#contact').animate({
			top: newTop,
			opacity: 1
			}, 500, function() {
			// Animation complete.
		});
	}
	
	function adOpen(newTop) {
		$('#advisors').animate({
			top: newTop,
			opacity: 1
			}, 500, function() {
			// Animation complete.
		});
	}
	
	$(".advisorBtn").click(function() {
		if(!adVar) {
			adVar = 1;
			adOpen(40);
			if(conVar) {
				conVar = 0;
				conOpen(-190);
			}
		} else {
			adVar = 0;
			adOpen(-265);
		}
	});

	$(".contactBtn").click(function() {
		if(!conVar) {
			conVar = 1;
			conOpen(40);
			if(adVar) {
				adVar = 0;
				adOpen(-265);
			}
		} else {
			conVar = 0;
			conOpen(-190);
		}
	});
  
  
});
runOnLoad(function(){
  $("input#name").select().focus();
});

