

function addFlash(file, width, height, id, wmode, version,flashvars)
{
    var params = {
        'wmode':wmode,
        'allowscriptaccess': "always"
    };
    var attributes = {'id':id};
    swfobject.embedSWF(file, id, width, height, version,"site/js/expressInstall.swf", flashvars, params, attributes);
}

function abreAtendimento () {
     var width = 450;
     var height = 465;
     var left = (screen.width - width)/2;
     var top = (screen.height - height)/2;;   
     window.open('../atd/view/?action=AppUsr/login','atendimento', 'width='+width+', height='+height+', top='+top+', left='+left+', scrollbars=no, status=no, toolbar=no, location=no, directories=no, menubar=no, resizable=no,maximized=no,titlebar=no, fullscreen=no');
}


$(function(){

  $('header nav li ').not('li ul li a').css({backgroundPosition: "0 -90px"});  
  
  $('header nav  li').not('li ul li').hover(function(){
    $(this).stop().animate({backgroundPosition: '0 0px'},100).children('a').stop().animate({fontSize:'1.9em'},300);
    $(this).children('ul').stop().slideDown();
  }, function(){
    $(this).stop().animate({backgroundPosition: '0 -90px'},300).children('a').stop().animate({fontSize:'1.7em'},200);
    $(this).children('ul').hide();   
  })

  $('h6#shownews a').click(function(){
     if ($('#newsletter').is(':hidden'))
     {
        $('#newsletter').fadeIn();
     } else {
        $('#newsletter').fadeOut();       
     }
     return false;
  })

   
  $('.banner-inf a, .banner-infdir a').hover(function(){
    $(this).find('img').stop().animate({'margin-right':'15px'},500);  
  }, function(){
    $(this).find('img').stop().animate({'margin-right':'20px'},500);  
  })
  
  $('footer nav li:last-child').css({'border':'0'});
  
    var email_regexp = new RegExp(/^(("[\w\-\s]+")|([\w\-]+(?:\.[\w\-]+)*)|("[\w\-\s]+")([\w\-]+(?:\.[\w\-]+)*))(@((?:[\w\-]+\.)*\w[\w\-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);

    function valid_email(email) {
        return email_regexp.test(email);
    }  
    
   $("a[rel=example_group]").fancybox();    
   

  /*----------------------------LIMPA CAMPOS---------------------*/
  
 $('input, textarea').focusin(function(){
    if ($(this).val()==$(this).attr('placeholder'))
    {
     $(this).val('');
    }
   });    
  
  $('input, textarea').blur(function(){
    if ($(this).val()==='')
    {
     $(this).val($(this).attr('placeholder'));
    }
   });

jQuery(function($){ 
 
  $('#form_contato').submit(function(e){
    e.preventDefault(); //Prevevir o envio do formulario
		$('#resposta-contato').html('');
		if ($('#nome').val() == '' || $('#nome').val() == $('#nome').attr('placeholder')) {
			$('#resposta-contato').html('! Campo Nome :: Obrigatório');
      $('#nome').focus();
		} else if ($('#email2').val() == '' || $('#email2').val() == $('#email2').attr('placeholder')) {
			$('#resposta-contato').html('! Campo E-mail :: Obrigatório');
      $('#email2').focus();
    } else if (!valid_email($('#email2').val())) {
			$('#resposta-contato').html('! Campo E-mail :: Inválido');
      $('#email2').focus();  
    } else if ($('#texto').val() == '' || $('#texto').val() == $('#texto').attr('placeholder')) {
			$('#resposta-contato').html('! Campo Mensagem :: Obrigatório');
      $('#texto').focus();  
    }else{
      $('#resposta-contato').html('<span style="color:#6D6D6D">Enviando contato...</span>');
      $.ajax({
				url: 'http://www.baretaautopecas.com.br/site/envia_contato.php',
				type: 'POST',
				data: $('#form_contato').serialize(),
				success: function(data) {
					if (data == 'true') {
            $('#resposta-contato').html('<span style="color:#00D025">Mensagem enviada com sucesso!</span>');
            setTimeout(function(){
                $('#resposta-contato').html('');
            },1500);
            $('#form_contato')[0].reset();
            $('#form_contato input,#form_contato textarea').blur();
					}else{
						this.error();
					}
				},
				error: function(){
					$('#resposta-contato').html('<strong style="color: #db653b;">Erro: A mensagem não pode ser enviada.</strong>');
				}
			});
    }
    return false;
  });
  
});

/*----------------------------NEWSLETTER---------------------*/

$('#newsletter_form').submit(function(){
  var email = $('#email_news').val();

  $.post('grava_newsletter.php',{email_news:email}, function(retorno){
    
    if (email ==='E-mail' )
   {
     $('#resposta').empty().text('Todos os campos são obrigatórios.').fadeIn().delay(2000).fadeOut();
     email = '';
   }
   
    if (email!=='')
    {
      if (retorno==='true' || retorno==='inserido'){
        
        alert('E-mail gravado!');
        $('#newsletter_form :input').each(function(){
          var padrao = $(this).attr('placeholder');
          $(this).val(padrao);
          $('#newsletter').fadeOut();
        });
      } 
    }
   });
   return false;
})
    
/*----------------------------NEWSLETTER---------------------*/

    $('#sticker').innerfade({speed:'slow',timeout:7000});
  
})//finaliza function

var email_regexp = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);

function valid_email(email) {
    return email_regexp.test(email);
}

jQuery(function($){
    
    jQuery.placeholderize();

});

(function($){

    $.placeholderize = function(){

        // Verifica se o browser suporta o atributo placeholder
        if ( true ) {

            // Fallback para o atributo placeholder
            $('[placeholder]').each(function(){

                var input = $(this);

                input

                    .bind('focus, focus.mask', function(){
                        if (input.val() == input.attr('placeholder')) {
                            input.val('');
                        }
                    })

                    .bind('blur, blur.mask', function(){
                        if (input.val() == '') {
                            input.addClass('placeholder').val(input.attr('placeholder'));
                        }
                    })

                    .bind('focus, focus.mask', function(){
                        input.removeClass('placeholder');
                    })

                    // Invoca o evento, para aplicar a função de fallback
                    .blur();
            });

        }
    };
})(jQuery);

