$(document).ready(function(){
   
    //Função para carregar a foto maior (Hullen Gonzales)
    $('a.link').mouseover(function() {
         $(".slide .legenda_carros").css("display","none");
        

        var $thumb = $(this);
        var $titulo = "";

        $titulo = $($thumb).attr('title').split("|");

        $('#imageZoom').load($($thumb).attr('rel'), function() {

          $('#imageZoom').stop().animate({ opacity: 0 }, 200, function() {
            
          $(this).attr('src', $($thumb).attr('rel')).attr('alt', $($thumb).attr('title')).animate({ opacity: 1 }, 1900);
          $(".slide .legenda_carros strong").text($titulo[0]);
          $(".slide .legenda_carros span").text($titulo[1]);
          $(".slide #imageZoom").removeClass("move_right");
          });
        
      });

         $(".slide .legenda_carros").delay(1200).fadeIn();
         
        

        return false;
       
    });


    //Função para carregar a foto maior (Hullen Gonzales)

    $('a.link2').click(function() {
        $(".content .desc_destaque").css("display","none");
        $(".content .desc_destaque_01").css("display","none");
        $('a.link2').parent().removeClass('act');  
        $(this).parent().addClass('act');
 
        var $thumb = $(this);
   
        var $titulo = "";

        $titulo = $($thumb).attr('rel').split("|");

         $('#imageZoom').load($($thumb).attr('href'), function() {

          $('#imageZoom').stop().animate({ opacity: 0 }, 200, function() {

            $(this).css("background-image",$($thumb).attr('href')).animate({ opacity: 1 }, 1900);
            
            $(".content .desc_destaque h2").text($titulo[0]);
            $(".content .desc_destaque p").text($titulo[1]);
          
        });

          });
            
           $(".content .desc_destaque").delay(1200).fadeIn();

        return false;

    });

        //Função para carregar a foto maior (Hullen Gonzales)

    $('a img.thumb').click(function() {

        var $thumb = $(this);

        $('a img.thumb').load($($thumb).parent().attr('href'), function() {

          $('#imageZoom').stop().animate({ opacity: 0 }, 200, function() {

            $(this).attr('src', $($thumb).parent().attr('href')).attr('alt', $($thumb).parent().attr('title')).animate({ opacity: 1 }, 300);

          });

        });

        return false;

    });


 
});


function checkMail(mail){
    var er = new RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if(typeof(mail) == "string"){
        if(er.test(mail)){
            return true;
        }
    }else if(typeof(mail) == "object"){
        if(er.test(mail.value)){
            return true;
        }
    }else{
        return false;
    }
}

function finalizaOrca(){

    $('.contatoEsq').slideDown('slow', function() {
        // Animation complete.
        });


}

function addOrca(id, acao){

    $.post('addOrca.php',{
        id:id,
        acao: acao
    },function(data){

        if(data){

            if(acao == 'del'){
                location.href="carrinho.php";
            }else if(acao == 'addint'){

                alert('Adicionado com sucesso!');

                location.href="carrinho.php";

            }else{
                $('#suc_'+id).hide();
                $('#suc_'+id).fadeIn('slow', function() {

                    });
                $('#err_'+id).hide();
            }

        }else{
            $('#suc_'+id).hide();
            $('#err_'+id).show();
        }
    });

}
