$(document).ready(function() {
  $("#contact-us-btn").click(function() {
    if($("#contact-us-text").css("opacity") != "1" && $("#contact-us-text").is(":not(animated)")) {
      $("#contact-us").slideToggle("slow");
      $("#contact-us-text")
      .animate({delay:1}, 500)
      .animate({"opacity": "1.0"}, 500);
    }
    else {
      $("#contact-us-text")
      .animate({"opacity": "0"}, 100);
      $("#contact-us").slideToggle("slow");
    }
  return false;
  });
	
  $("a.zoom").fancybox({
    'titleShow'		: false,
    'transitionIn'	: 'elastic',
    'transitionOut'	: 'elastic'
  });
  $("input, textarea").focus(function() {
  if( this.value == this.defaultValue ) {
    this.value = "";
  }
  }).blur(function() {
    if( !this.value.length ) {
      this.value = this.defaultValue;
    }
  });
  
  $('#top').click(function () {
    $( 'html, body' ).animate( { scrollTop: 0 }, 'slow' );
  });
});

$(function() {
    $('.error').hide();
    $(".button").click(function() {

      $('.error').hide();
  	  var name = $("input#name").val();
  		if (name == "" || name == "Name" || name == "Namn") {
        $("label#name_error").fadeIn(400);
        $("input#name").focus();
        return false;
      }
  		var email = $("input#email").val();
  		if (email == "" || email == "Mail" || email == "E-post") {
        $("label#email_error").fadeIn(400);
        $("input#email").focus();
        return false;
      }
  		var message = $("textarea#message").val();
  		if (message == "" || message == "Message" || message == "Meddelande") {
        $("label#message_error").fadeIn(400);
        $("textarea#message").focus();
        return false;
      }
		
		var dataString = 'name='+ name + '&email=' + email + '&message=' + message;
		
		$.ajax({
      type: "POST",
      url: "bin/process.php",
      data: dataString,
      success: function() {
        $('#contact_form').html("<div id='message'></div>");
        $('#contact_form').html("<h2>Your message has been sent!</h2>")
        .append("<p>Thank you for contacting us, we will be in touch soon.</p>")
        .hide()
        .fadeIn(1500, function() {
          $('#message').append("<img id='checkmark' src='images/check.png' />");
        });
      }
     });
    return false;
	});
});
 

