$(document).ready(function(){
    $('#menu a').trigger('hover');
    $('a#menu-contacto').tooltip({position:'bottom center',effect:'slide'});
    $('#contacto').bind('submit',function(){
        var $this = $(this),
        data = $this.serialize(),
        reset = function () {
            $this.find('input,textarea').removeAttr('disabled');
            
            setTimeout(function(){
                $this.find('.enviando').hide('fast',function(){
                    $(this).remove();
                });
            },3000);
        };
        
        if (!$this.nextAll('.enviando').length) {
            $this.find('[type=submit]').after('<span class="enviando"></span>');
        }
        $this.find('.enviando').text('Enviando mensaje...');
        
        $this.find('input,textarea').attr('disabled','disabled');
        $.ajax({
            url: 'enviado.php',
            type: 'POST',
            data: data,
            error: function(){
                $this.find('.enviando').text('El mensaje no pudo ser enviado, por favor intenta nuevamente en unos minutos');
                reset();
            },
            success: function(){
                $this.find('.enviando').text('Mensaje enviado, ¡gracias!');
                reset();
            }
        });
        
        return false;
    });
});
