$(function() {
  Cufon.replace('h2, h3, h4, .project p');

  // CONTENT MOVER
  $(".contact-link").click(function() {
    $(".projects-link").removeAttr('id');
    $(this).attr('id', 'selected');
    $("#projects-list").fadeOut().animate( { top: '-500px'} );
    $("#projects-text").animate( { top: '-500px'} );

    $("#contact-form").fadeIn();
    $("#contact-text").animate( { top: '110px'} );
  })

  $(".projects-link").click(function() {
    $(".contact-link").removeAttr('id');
    $(this).attr('id', 'selected');
    $("#projects-list").animate( { top: '110px'} ).fadeIn();
    $("#projects-text").animate( { top: '110px'} );

    $("#contact-form").fadeOut();
    $("#contact-text").animate( { top: '-500px'} );
    
    $(".error").hide();
  })

  // EXTERNAL LINKS IN NEW WINDOW
  $('a[href^=http]').click( function() {
    window.open(this.href);
    return false;
  });
  
  // CONTACT BOX
  $(".contact-form").validator({
    lang: "de",
    position: "center right",
    offset: [0, 10]
  })
  .submit(function(e) {
    var form = $(this);

		if (!e.isDefaultPrevented()) {
      $.ajax({
        type: "POST",
        url: "/includes/contact-engine.php",
        data: form.serialize(),
        success: function(msg){
          $("#contact-form").html(msg);
        }
      });

  		e.preventDefault();
    }
  });

  $.tools.validator.localize("de", {
    ':email'  		: 'Not a correct email address',
    '[required]' 	: 'This field is mandatory'
  });
});