/**
$(): utilizado em todas as funções que devem ser referenciadas a jQuery
document: expressão que indica o documento HTML
ready(): associado a leitura do documento enquanto está sendo carregado
*/
jQuery.noConflict();
jQuery(document).ready(function(){

    // Crio uma variável chamada $forms que pega o valor da tag form
    $forms = jQuery('#form_news');

    // hide(): esconde a div cadastro enquanto carrega o ready()
   // $('#conteudo-fiquepordentro-topo-conteudo-form-00').hide();

    /**
     bind(): é manipulador de  evento exemplo submit, click e/ou double click
     a: é a tag <a href>
    */

    jQuery('a').bind('click', function(){
        switch(this.id){
            case 'c':
                jQuery('#conteudo-fiquepordentro-topo-conteudo-form-00').show(); // show(): mostra div que está oculta (hide()).
                return false;
                break;
        }
    })

    $forms.bind('submit', function(){

        /**
        Crio a variável $button
        attr(): set a propriedade de um atributo, nesse exemplo foi desativado o botão com a tag button
        */
        var $button = jQuery('button',this).attr('disabled',true);

        /**
       Criada a variável params
        serialize(): pega os dados inseridos no formulário
        */
        var params = jQuery(this.elements).serialize();

        var self = this;
        jQuery.ajax({

            // Usando metodo Post
            type: 'POST',

            // this.action pega o script para onde vai ser enviado os dados
            url: this.action,

            // os dados que pegamos com a função serialize()
            data: params,

            // Antes de enviar
            beforeSend: function(){
                // mostro a div loading
                jQuery('#loading').show();

                //  html(): equivalente ao innerHTML
                jQuery('#loading').html("<p style=\"color:#FFF; margin-left:20px\" class=\"txt-preto-14-times\"><em>Aguarde,<strong> Carregando...</strong></em></p>");
            },
            success: function(txt){
                // Ativo o botão usando a função attr()
                $button.attr('disabled',false);

                // Escrevo a mensagem
                jQuery('#loading').html(txt);

                // Limpo o formulário
                self.reset();
            },

            // Se acontecer algum erro é executada essa função
            error: function(txt){
                jQuery('#loading').html(txt);
            }
        })
        return false;
    });
});

