$(document).ready(function(){
    $.meta.setType("attr", "validate");

    $("#contact_form").validate({
        submitHandler: function(form) {
            // show overlay widget
            var form = $("#contact_form");
            $("#contact_form").prepend( '<div id="overlay"><div class="background"><div class="image"></div></div></div>' )
            $("#overlay .background").css({
                width:  form.width(),
                height: form.height()
            });


            // get portfolio data
            $.getJSON( Catalyst.uri_for('/enquiry'),
                       {
                            name    : $('#name',    form).val(),
                            email   : $('#email',   form).val(),
                            subject : $('#subject', form).val(),
                            message : $('#message', form).val()
                        },
                        function( data ) {
                            // hide contact form
                            $("#contact_form").hide();

                            // show success message
                            $("#right .success").show();
                        }
                );

            return false;
        },

        // remove default error placement handler
        errorPlacement: function() {}
    });
})
