$(document).ready(function(){

    $.img = Math.round(Math.random()*2);

    $.i = 0;
    while ($.i<=100){
      $.xPos = Math.round(Math.random()*500);
      $.yPos = Math.round(Math.random()*50);
      $.widthRdm = Math.round(Math.random()*50);
      $.colorFnd = Math.round(Math.random()*10);
      $('.header').append('<div class="fndImg" style="width: '+$.widthRdm+'px; background: url(img/fnd_img'+$.img+'.jpg) no-repeat -'+$.xPos+'px -'+$.yPos+'px"></div>');
      $.i++;
    }

    $('.header').slideDown('slow',function(){
        $('.nm').slideDown('normal',function(){
            $('.botonera').slideDown('normal',function(){
                $('.section_title').slideDown('normal',function(){
                    $('.section_cont').animate({opacity: 1, filter:'alpha(opacity=100)'}, 1000);
                });
            });

        });
    });


    function val_mail(mail){
        var mailOk  = /^(.+\@.+\..+)$/;
        return mailOk.test(mail);
    }

    $('.f_enviar').hover(function(){
            $(this).css({'background-color':'#00FF00','color':'#000000'});
        },function(){
            $(this).css({'background-color':'#333333','color':'#00FF00'});
    });

    $('.f_enviar').click(function(){
        if($('.f_nombre').val()!='' && $('.f_mail').val()!='' && $('.f_mensaje').val()!=''){
            if(val_mail($('.f_mail').val())){
                  $('.f_msj').html('Enviando...');
                  $.get('inc/sendmail.php',
                     {nombre:$('.f_nombre').val(),
                      mail:$('.f_mail').val(),
                      mensaje:$('.f_mensaje').val()},
                     function(v){
                        $('.f_nombre').val('');
                        $('.f_mail').val('');
                        $('.f_mensaje').val('');
                        $('.f_msj').html(v);

                     }
                  );
            }
            else{
                $('.f_msj').html('Ingresar un e-mail válido');
            }
        }
        else
            $('.f_msj').html('Todos los campos son obligatorios');
    });



});