$().ready(function(){
    /*
     * FORMATIERUNG DER INPUTFELDER:
     *   Felder mit "title" werden mit diesem als Ausfll-Hinweis vorbesetzt
     *   Bei focus() wird der Hinweis ausgeblendet
     *   Ohne Eingabe wird bei blur() der Hinweis wieder angezeigt
     */
    $('input[title]:not(:password)').each(function() {
      $(this)
        .addClass("hint")
        .val($(this).attr("title"))
        .bind("focus", function(){
          $(this).removeClass("hint").val("");
        })
        .bind("blur", function(){
          if($(this).val() == "" || $(this).val() == $(this).attr("title"))
            $(this).addClass("hint").val($(this).attr("title"));
        })
    });

    $('textarea[title]').each(function() {
      $(this)
        .addClass("hint")
        .val($(this).attr("title"))
        .bind("focus", function(){
          $(this).removeClass("hint").val("");
        })
        .bind("blur", function(){
          if($(this).val() == "" || $(this).val() == $(this).attr("title"))
            $(this).addClass("hint").val($(this).attr("title"));
        })
    });

    $('#submit').mouseover(function() { $(this).attr("src", "./gfx/button_o.png") });
    $('#submit').mouseout(function() { $(this).attr("src", "./gfx/button.png") });
    $('#submit').click(function() { check(); });
    $('#form').submit(function() { check(); });

    function check() {
      $("input.iError").removeClass("iError").addClass("i");
      if($("#name").val() == "" || $("#name").val() == $("#name").attr("title")) {
        $("#name").addClass("iError");
      }
      else if($("#email").val() == "" || $("#email").val() == $("#email").attr("title")) {
        $("#email").addClass("iError");
      }
      else if($("#msg").val() == "" || $("#msg").val() == $("#msg").attr("title")) {
        $("#msg").addClass("iError");
      }
      else {
        $.ajax({
          url   : "ajax_form.php",
          type  : "GET",
          data  : {
            "name"  :$("#name").val(),
            "email" :$("#email").val(),
            "msg"   :$("#msg").val()
          },
          dataType: "json",
          timeout: 1000,
          error : function(){
            alert('Ihre Anfrage konnte nicht bearbeitet werden. Bitte richten Sie Ihren Anfrage direkt an info@3d-stadtmarketing.de');
          },
          success : function(data){
            if(data.error == "") {
              $('#form').empty('').append('<div class="reply">Ihre Daten wurden versendet! Wir werden uns schnellstmöglich mit Ihnen in Verbindung setzen. Vielen Dank.</div>');
            }
            else{
              alert(data.msg);
            }
          } //success	: function(data){
        }); //$.ajax({
      } //if/else/else/elseif
    } //function


    $('.fan_box .connect_top').css('padding', '5px !important');

});


