$(function() {
    
    
    $('#banner-wrapper').cycle({fx: 'fade',delay:  -1600,timeout:6000,speed:2000,pause: true,prev:'#prev',next:'#next'});
    
    $(".zoom").attr('rel', 'galeria').fancybox({
            'showNavArrows'    : true,
            'titlePosition'         : 'inside',
            'transitionIn'	:	'elastic',
            'transitionOut'	:	'elastic',
            'speedIn'		:	600,
            'speedOut'		:	200,
            'overlayShow'	:	false,
            'hideOnContentClick': true
    });
    
    //Cursos e Oficinas
    $('.home-cursos-square').hover(function(){
            $(this).find('.home-cursos-img').animate({top:'-158px'},{queue:false,duration:500});
            $(this).find('.home-cursos-txt').animate({top:'0px'},{queue:false,duration:500});
    }, function(){
            $(this).find('.home-cursos-img').animate({top:'0px'},{queue:false,duration:500,easing: 'easeOutExpo'}).fadeIn(660);
            $(this).find('.home-cursos-txt').animate({top:'168px'},{queue:false,duration:500,easing: 'easeOutExpo'});
    });
    
    //:: TAG ÚTIL ::\\
    $('#tagutil a').hover(function(){$(this).animate({marginTop:'-38px'},{queue:false,duration:500})},function(){$(this).animate({marginTop:'0px'},{queue:false,duration:500,easing: 'easeOutBounce'}).fadeIn(660)});
      
});

/*/////////// VALIDACAO //////////////*/
function validacao(form){
    var cont = 0;
    var eEmail = /^[\w-]+(\.[\w-]+)*@(([A-Za-z\d][A-Za-z\d-]{0,61}[A-Za-z\d]\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
    //Inputs
    $(form).find('input[type="text"],textarea, select').not('.naovalidar').each(function(){
            if(this.value == this.defaultValue){
                $(this).parent().find('span').fadeIn().html('Obrigatório');
                cont = cont + 1;
            }else if(this.value != '') {
                //Fone
                if($(this).attr('id')=='fone')
                {
                     if ($(this).val().length < 14) {
                        $(this).parent().find('span').html('Fone Inválido!').fadeIn();
                         cont = cont + 1;
                     }else $(this).parent().find('span').fadeOut(100);
                //Email
                }else if($(this).attr('id')=='email' || $(this).attr('id')=='emaildestino')
                {
                   var vEmail = $(this).val();
	  	     if (!(eEmail.test(vEmail))) {
                        $(this).parent().find('span').html('E-mail Inválido!').fadeIn();
                         cont = cont + 1;
                     }else $(this).parent().find('span').fadeOut(100);
                }else $(this).parent().find('span').fadeOut(100);
            }else cont = cont + 1;
    });
    return cont;
}

function enviarEmail(form){
    var cont = validacao(form);
    if(cont==0)
    {
        var assu = $('#assunto').val() ? $('#assunto').val() : '-';
        var email_site = $('#email_site').val() ? $('#email_site').val() : '-';
        var nome = $('#nome').val() ? $('#nome').val() : '-';
        var fone = $('#fone').val() ? $('#fone').val() : '-';
        var emai = $('#email').val() ? $('#email').val() : '-';
        var msg = $('#msg').val() ? $('#msg').val() : '-';
        $.ajax({
                url: 'mail/_sendMail.php',
                dataType: 'html',
                data:{assunto:assu,nome:nome,fone:fone,email:emai,msg:msg,email_site:email_site},
                type: 'GET',
                timeout: 10000,
                beforeSend: function(){
                   $('#mailReturn').empty().fadeIn().html('<img src="images/loadp.gif" />..Aguarde...Enviando...');
                   $('#_send').hide();
                },
                success: function(data, textStatus) {
                     if(data)
                     {
                    	 $('#mailReturn').html('Enviado com Sucesso ! Obrigado!').fadeIn('slow').addClass('sucesso');
                    	 $(':input','#frmContato').not(':button, :submit, :reset, :hidden').val('').removeAttr('checked').removeAttr('selected');
                     } 
                },
                error: function(xhr , er) {
                }
        });
    }   
}
function mascara(d,b,g){var c=d.value.replace(/\W/gi,""),f;for(f=0;f<c.length;f++){if(!/[#A9%]/.test(b.charAt(f))){c=c.splice(f,1,b.charAt(f)+c.charAt(f))}}var a="";for(f=0;f<c.length;f++){if((b.charAt(f)=="A"&&/[a-z]/i.test(c.charAt(f)))||(b.charAt(f)=="9"&&/[0-9]/.test(c.charAt(f)))||(b.charAt(f)=="%"&&/[0-9a-fA-F]/.test(c.charAt(f)))||(b.charAt(f)=="#"&&/\w/.test(c.charAt(f)))){a+=c.charAt(f)}else{if(b.charAt(f)==c.charAt(f)){a+=c.charAt(f)}}}if(a.replace(/\W/gi,"")==""){a=""}d.value=a}String.prototype.splice=function(a,c,b){if(a<0){a=this.length+a}return this.substr(0,a)+(b||"")+this.substr(a+c,this.length)};

