$(function(){

$('label:last, li:last-child, ul:last, div:last-child, article:last-child, section:last-child, ol:last-child').addClass('lastc');
$('label:first-child, li:first-child, ul:first-child, div:first-child, article:first-child, section:first-child, ol:first-child').addClass('firstc');

$('.acesseSuaLojaLnk a').toggle(
	function(){
	    $('.loginForm').slideDown('fast');
		$(this).parent().addClass('loginAberto')
	},
	function(){
		$('.loginForm').slideUp('fast');
		$(this).parent().removeClass('loginAberto')
});

$('.como-comprar .lista-passos li').addClass('divisoria')


$(document).ready(function() {
    $('#slider').nivoSlider({
		effect:'fold',
		pauseTime:5000
	});
});

	// abre e fecha div de indica empresa
	$('.showFormParceira').click(function() {
		$('.ct-indicar-empresa').show()		
		$('.empresa-nao-parceira').remove()
	})

	// Aplica estilo even a cada linha ímpar da tbl-representantes
	$('.tbl-representantes tbody tr:nth-child(even)').addClass('even')

	// aplica focus aos objetos do formularios
	$('input[type="text"],input[type="radio"],input[type="checkbox"],select,textarea').focus(function() {
		$(this).addClass('ipt-focus')
		}).blur(function() {
			$(this).removeClass("ipt-focus")
    });
	
	// Abre e fecha lista de perguntas
	$('.perguntasLista dt, .perguntasLista dd').removeClass('ativo');
	//$('.perguntasLista dt:first, .perguntasLista dd:first').addClass('ativo');
	$('.perguntasLista dt').toggle(
		function(){
		    $('.perguntasLista dd').slideUp();
		    $(this).next('dd').slideDown();
			$(this).addClass('ativo');
			$(this).next('dd').addClass('ativo');
		},
		function(){
		    $(this).next('dd').slideUp();
			$(this).removeClass('ativo');
			$(this).next('dd').removeClass('ativo');
	});

	
	// Ativa ou desativa tabela conforme estado clicado	
    $(".box-representantes").hide(); 
	$('.resultadoRepresentante').hide()
    $(".sl-estado").change (function() { 
		// Troca tabela de estados com representantes
		var selectedValue = $(this).val(); 
		$(".box-representantes").hide(); 
		$("#" + selectedValue).show().addClass('estadoAberto');
		$('.resultadoRepresentante').show()

		// Conta quantos representantes tem.
		var trCount = $('#'+selectedValue+'.estadoAberto table tbody tr').length;
		$('.qtdRepre').text(trCount);
		
		// Pega o nome do Estado.
	  	var nomeEstado = $(".sl-estado option:selected").html();
	    $(".estadoRepre").text(nomeEstado);
	})  
	
	
	//verifica a altura da lista de lojas na seleção
    $('.lista_empresas_conveniadas').each(function(){
    	var altura = $('.lista_empresas_conveniadas').height();
    	if ( altura >= 295){
    		$('.lista_empresas_conveniadas').css({height:295});
    	}
    })
	
});

