$(document).ready(function() {
    $('#feedbacktab').click(function() {
        $('#feedbackdrop').show();
        $('#feedbackbox').show();
        $('.adbanner').hide();
    });
    $('#feedbackx').click(function() {
        $('#feedbackdrop').hide();
        $('#feedbackbox').hide();
        $('.adbanner').show();
    });

    function showRequest(formData, jqForm, options) { 
        // formData is an array; here we use $.param to convert it to a string to display it 
        // but the form plugin does this for you automatically when it submits the data 
        var queryString = $.param(formData); 
     
        // jqForm is a jQuery object encapsulating the form element.  To access the 
        // DOM element for the form do this: 
        // var formElement = jqForm[0]; 
 
        alert('About to submit: \n\n' + queryString); 
 
        // here we could return false to prevent the form from being submitted; 
        // returning anything other than false will allow the form submit to continue 
        return true; 
    } 
    function processJson(data) { 
        if (data.errors) {
            $('#feedbackform').before('<p></p>');
            $('#feedbackbox').find('.errorlist').remove();
            $('#feedbackform').prev('p').append('<ul class="errorlist"></ul>');
            $.each(data.errors, function(error, message) {
                $('#feedbackform').find('#'+error).parent().parent().addClass('errors');
                $('#feedbackbox .errorlist').append('<li>'+error+'</li>');
                $('#feedbackbox .errorlist:last-child li').append('<ul class="errorlist"></ul>');
                $('#feedbackbox .errorlist:last-child li ul').append('<li>'+message.toString().toLowerCase()+'</li>');
            });
        } else {
            $('#feedbackbox').find('.errorlist').hide();
            $('#feedbackform').hide();
            $('#feedbackbox .inner').append('<p>thanks for your message!</p>');
            //$('#feedbackbox .inner').children().remove();
            //$('#feedbackbox .inner').append('<p>thanks for your message!</p>');
            //$('#feedbackbox').fadeOut('slow', function() {
                //$('#feedbackdrop').fadeOut('slow');
        }
    }
    var options = {
        dataType: 'json',
        success: processJson,
        resetForm: true
    };
    $('#feedbackform').ajaxForm(options);
});

