var annotatorInit = function() {
    $(".input-element").focus(function(){
        $(this).toggleClass("active-form-element");
    });
    $(".input-element").blur(function(){
        $(this).toggleClass("active-form-element");
    });
    $("#annotator").submit(function(){
        if ($("#annotator-title").val() != "" &&
            $("#annotator-content").val() != "") {
            $("#annotator-submit").attr("disabled","true");
            $(".form-message").hide();
            $("#message-waiting").css("display","inline");
            $.ajax({ url:      $("#annotator").attr("action"),
                     type:     "POST",
                     data:     $("#annotator").serialize(),
                     success:  function(){
                       $(".form-message").hide();
                       $("#message-success").css("display","inline");
                     },
                     dataType: "text",
                     error:    function(request, settings){
                       $(".form-message").hide();
                       $("#message-failed").css("display","inline");
                       $("#annotator-submit").attr("disabled",false);
                     }});
            return false;
        } else {
            $(".form-message").hide();
            $("#message-fill-all").css("display","inline");
            return false;
        }
    });
}

jQuery(document).ready(function(){annotatorInit();});
