

 $(function(){

    ////////////////////////////////////////////////////////////////////////////////////////
    // Banner Index
    if ($('#img-destaque .item').size() > 1) {
    
        var index = 0;
        var cont = 0;
        var total = $('#img-destaque .item').size();
        var totalLink = total - 1;
        
        
        // Acresento os botoes de navegacao
        $('#img-destaque .item').each(function(){
            cont++;
            elemento = $(this);
            
            // Atribui o id do elemento
            elemento.attr('id', 'ban-' + cont);
            
            
            $('#bt-banner').append('<a class="bt-banner png" onclick="clearTimeout(bannerTempo);rotacionarBanner(this.id,' + total + ')" id="bt-' + cont + '">0' + cont + '</a>');
            
            // Posiciono o link 
            $('#bt-' + cont).css('right', (6 + (totalLink * 16)));
            totalLink = totalLink - 1;
            
            if (!(cont == total)) {
            
            }
        });
        
        rotacionarBanner("bt-"+total, total);
        
    }
	else {
		$('#ban-1').fadeIn();
	}

	
	////////////////////////////////////////////////////////////////////////////////////////
    // Formulario de receita
    $('#enviar-rec').click(function(event){
    
        email = $('#con-email').val();
        nome = $('#con-nome').val();        
        telefone = $('#con-telefone').val();
		titulo = $('#con-titulo').val();		
        categoria = $('#cad-horario').val();
		receita = $('#con-mensagem').val();
        
         
        
        
        
        error = false;
        errorList = [];
        
        if (nome == '' || nome == 'Insira seu nome ') {
            errorList.push('<strong>Nome inválido,</strong> por favor corrija o nome informado!');
            error = true;
        }
        
        if (nome == '' || nome == 'Insira seu nome completo') {
            errorList.push('<strong>Endereço inválido,</strong> por favor corrija o endereço informado!');
            error = true;
        }
        
      
        
        if (telefone == '') {
            errorList.push('<strong>Telefone inválido,</strong> por favor corrija o telefone informado!');
            error = true;
        }
        
        if (email == '' || email == 'Insira seu e-mail verdadeiro' || !validaEmail(email)) {
            errorList.push('<strong>E-mail inválido,</strong> por favor corrija o e-mail informado!');
            error = true;
            
        }
		
        
        if (categoria == '') {
            errorList.push('<strong>Categoria inválida,</strong> por favor selecione uma categoria!');
            error = true;
        }


		if (receita == '') {
            errorList.push('<strong>Receita inválida, </strong>por favor corrija a receita informada!');
            error = true;
        }
		

		if ($('#foto').val() != "") {			
			extensoesOk = ",.gif,.jpg,";
			extensao = $('#foto').val();
			extensao    = "," + extensao.substr(extensao.length - 4 ).toLowerCase() + ",";
			 if( extensoesOk.indexOf( extensao ) == -1 ){
			  errorList.push('<strong>Imagem inválida, </strong>Apenas imagens com extensão .jpg ou .gif são aceitas!');
            error = true;   			     
   			}
 			
		};
                
        
        
        $('#listErrors').slideUp().end();
        
        
        if (error == false) {
            $('#formulario-contato fieldset').append('<input type="hidden" name="ok" value="ok" /><div class="center" id="carregandoNew"><img src="{$host}/theme/img/carregando.gif" alt="Carregando" /></div>');
            return true;
            
        }
        else {
            errors = '';
            for (i = 0; i < errorList.length; i++) {
                errors += '<li>' + errorList[i] + '</li>';
            }
            
            $('#listErrors').html('<ul></ul>');
            $('#listErrors ul').html(errors);
            
            errors = '';
            errorList.length = 0;
            
            $('#listErrors').slideDown();
            
        }
        
        event.preventDefault(event);
        return false;
    });
    
	

    $('#bt-inscrever').toggle(function(){
    
    	$('#conteudo-cadastro').slideDown();
    
        event.preventDefault(event);
        return false;
    }, function(){
    
    	$('#conteudo-cadastro').slideUp();
    
        event.preventDefault(event);
        return false;
    });
    
    ////////////////////////////////////////////////////////////////////////////////////////
    // Formulario cadastro Curso
    $('#enviar-cad').click(function(event){
    
        email = $('#cad-email').val();
        nome = $('#cad-nome').val();
        endereco = $('#cad-nome').val();
        telefone = $('#cad-telefone').val();
        cidade = $('#cad-cidade').val();
        bairro = $('#cad-bairro').val();
        horario = $('#cad-horario').val()
        rg = $('#cad-rg').val();
        
        
        error = false;
        errorList = [];
        
        if (nome == '' || nome == 'Insira seu nome completo') {
            errorList.push('<strong>Nome inválido,</strong> por favor corrija o nome informado!');
            error = true;
        }
        
        if (nome == '' || nome == 'Insira seu nome completo') {
            errorList.push('<strong>Endereço inválido,</strong> por favor corrija o endereço informado!');
            error = true;
        }
        
        if (cidade == '') {
            errorList.push('<strong>Bairro inválido,</strong> por favor corrija o bairro informado!');
            error = true;
        }
        
        if (cidade == '') {
            errorList.push('<strong>Cidade inválido,</strong> por favor corrija a cidade informada!');
            error = true;
        }
        
        if (cidade == '') {
            errorList.push('<strong>RG inválido,</strong> por favor corrija o RG informado!');
            error = true;
        }
        
        
        if (telefone == '') {
            errorList.push('<strong>Telefone inválido,</strong> por favor corrija o telefone informado!');
            error = true;
        }
        
        if (email == '' || email == 'Insira seu e-mail verdadeiro' || !validaEmail(email)) {
            errorList.push('<strong>E-mail inválido,</strong> por favor corrija o e-mail informado!');
            error = true;
            
        }
        
        if (horario == '') {
            errorList.push('<strong>Horário inválido,</strong> por favor selecione um horário!');
            error = true;
        }
        
        
        
        $('#listErrors').slideUp().end();
        
        
        if (error == false) {
            $('#formulario-contato fieldset').append('<div class="center" id="carregandoNew"><img src="{$host}/theme/img/carregando.gif" alt="Carregando" /></div>');
            
            
            $.ajax({
                type: 'post',
                url: 'http://www.cocipa.com.br/ajax.php',
                data: {
                    'acao': 'cadastro',
                    'nome': nome,
                    'email': email,
                    'telefone': telefone,
                    'bairro': bairro,
                    'rg': rg,
                    'cidade': cidade,
                    'horario': horario,
                    'curso': $('.conteudo-meio .titulo').text()
                },
                dataType: 'json',
                success: function(valor){
                
                    // cadastro corretamente
                    if (valor.error == true) {
                    
                        $('.form-cad').fadeOut();
                        $('#listErrors').html('<ul></ul>');
                        $('#listErrors ul').html('<li>' + valor.msg + '</li>');
                        $('#listErrors').slideDown();
                        $('#carregandoNew').fadeOut().remove();
                        
                    }
                    else {
                        $('#listErrors').html('<ul></ul>');
                        $('#listErrors ul').html('<li>' + valor.msg + '</li>');
                        $('#listErrors').slideDown();
                        $('#carregandoNew').fadeOut().remove();
                    }
                }
            });
            
        }
        else {
            errors = '';
            for (i = 0; i < errorList.length; i++) {
                errors += '<li>' + errorList[i] + '</li>';
            }
            
            $('#listErrors').html('<ul></ul>');
            $('#listErrors ul').html(errors);
            
            errors = '';
            errorList.length = 0;
            
            $('#listErrors').slideDown();
            
        }
        
        event.preventDefault(event);
        return false;
    });
    
    
    
    
    
    
    
    ////////////////////////////////////////////////////////////////////////////////////////
    // funçao passar funcionarios
    if ($('#correr-funcionarios .box-img').size() > 1) {
    
        $('#correr-funcionarios .box-img:first').addClass('ativo');
        
        
        // Botão Avançar
        $('#fun-avancar').click(function(event){
        
            //alert($('#correr-funcionarios .box-img').size());
            
            
            if ($('#correr-funcionarios .ativo').next().next().hasClass('box-img')) {
                // Elemento a ser marcado como ativo
                elemento = $('#correr-funcionarios .ativo').next();
                
                // animação
                $('#correr-funcionarios .conteudo-funcionarios').animate({
                    "marginLeft": "-=145px"
                }, "slow");
                
                
                // removo o marcado do elemento atual
                $('#correr-funcionarios .ativo').removeClass('ativo');
                
                // Marco o elemento atual como ativo
                elemento.addClass('ativo');
            }
            event.preventDefault(event);
            return false;
        });
        
        // Botão Voltar
        $('#fun-voltar').click(function(event){
            if ($('#correr-funcionarios .ativo').prev().hasClass('box-img')) {
            
                // Elemento a ser marcado como ativo
                elemento = $('#correr-funcionarios .ativo').prev();
                
                // animação
                $('#correr-funcionarios .conteudo-funcionarios').animate({
                    "marginLeft": "+=145px"
                }, "slow");
                
                // removo o marcado do elemento atual
                $('#correr-funcionarios .ativo').removeClass('ativo');
                
                // Marco o elemento atual como ativo
                elemento.addClass('ativo');
            }
            event.preventDefault(event);
            return false;
        });
    }
    
    
    
    
    
    
    
    // cancela click 
    $('.not-click').click(function(event){
        event.preventDefault(event);
        return false;
    });
    
    $('.nome-funcionario').css({
        'opacity': .75
    })
    
    ////////////////////////////////////////////////////////////////////////////////////////
    // funçao passar galeria
    if ($('#galeria-fotos-conteudo .itemg').size() > 1) {
    
        $('#galeria-img .itemg:first').addClass('ativo');
        
        
        // Botão Avançar
        $('#galeria-avancar').click(function(event){
            if ($('#galeria-img .ativo').next().next().next().hasClass('itemg')) {
                // Elemento a ser marcado como ativo
                elemento = $('#galeria-img .ativo').next();
                
                // animação
                $('#galeria-img .galeria-content').animate({
                    "marginLeft": "-=145px"
                }, "slow");
                
                
                // removo o marcado do elemento atual
                $('#galeria-img .ativo').removeClass('ativo');
                
                // Marco o elemento atual como ativo
                elemento.addClass('ativo');
            }
            event.preventDefault(event);
            return false;
        });
        
        // Botão Voltar
        $('#galeria-voltar').click(function(event){
            if ($('#galeria-img .ativo').prev().hasClass('itemg')) {
            
                // Elemento a ser marcado como ativo
                elemento = $('#galeria-img .ativo').prev();
                
                // animação
                $('#galeria-img .galeria-content').animate({
                    "marginLeft": "+=145px"
                }, "slow");
                
                // removo o marcado do elemento atual
                $('#galeria-img .ativo').removeClass('ativo');
                
                // Marco o elemento atual como ativo
                elemento.addClass('ativo');
            }
            event.preventDefault(event);
            return false;
        });
    }
    
    
    
    
    
    
    
    
    
    ////////////////////////////////////////////////////////////////////////////////////////
    // funçao passar publicidade
    if ($('#publicidade .item').size() > 1) {
        //tempoSlide = setInterval('#publicidade .item', 10);
        //clearInterval(tempoSlide);
        
        
        $('#player-img .item:first').addClass('ativo');
        
        
        // Botão Avançar
        $('#player-avancar').click(function(event){
            if ($('#player-img .ativo').next().next().next().hasClass('item')) {
                // Elemento a ser marcado como ativo
                elemento = $('#player-img .ativo').next();
                
                // animação
                $('#player-img .content').animate({
                    "marginLeft": "-=185px"
                }, "slow");
                
                
                // removo o marcado do elemento atual
                $('#player-img .ativo').removeClass('ativo');
                
                // Marco o elemento atual como ativo
                elemento.addClass('ativo');
            }
            event.preventDefault(event);
            return false;
        });
        
        // Botão Voltar
        $('#player-voltar').click(function(event){
            if ($('#player-img .ativo').prev().hasClass('item')) {
            
                // Elemento a ser marcado como ativo
                elemento = $('#player-img .ativo').prev();
                
                // animação
                $('#player-img .content').animate({
                    "marginLeft": "+=185px"
                }, "slow");
                
                // removo o marcado do elemento atual
                $('#player-img .ativo').removeClass('ativo');
                
                // Marco o elemento atual como ativo
                elemento.addClass('ativo');
            }
            event.preventDefault(event);
            return false;
        });
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
    $('#new-nome,#new-email').focus(function(event){
        valorAntigo = $(this).attr('value');
        
        if (valorAntigo == 'Digite seu e-mail' || valorAntigo == 'Digite seu nome para receber novidades') {
            $(this).attr('value', '');
        }
        
    }).blur(function(event){
        if ($(this).attr('value') == '') {
            $(this).attr('value', valorAntigo);
        }
    });
    
    
    
    
    //////////////////////////////////////////////////////////////////////////////////////////
    // Color Box 	
    $('a[rel="popup"]').colorbox({
        slideshow: true
    });
    
    //////////////////////////////////////////////////////////////////////////////////////////
    // Color Box 	
    $('a[rel="popupFun"]').colorbox({
        slideshow: true
    });
    
    
    ////////////////////////////////////////////////////////////////////////////
    // Links Externos 
    $('.externo').attr('target', '_blanck');
    
    
    
    // Mapa da localizacao
    if ($('#mapa').size() > 0) {
        $('#mapa').html('<iframe width="765" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://maps.google.com/maps?f=q&amp;source=s_q&amp;hl=pt-BR&amp;geocode=&amp;q=In%C3%BAbia+Paulista+-+S%C3%A3o+Paulo,+Brasil&amp;sll=-21.798612,-50.881028&amp;sspn=179.075493,184.21875&amp;ie=UTF8&amp;hq=&amp;hnear=In%C3%BAbia+Paulista+-+S%C3%A3o+Paulo,+Brasil&amp;t=h&amp;ll=-21.770341,-50.96137&amp;spn=0.027898,0.06566&amp;z=14&amp;iwloc=A&amp;output=embed"></iframe>');
    }
    
    ////////////////////////////////////////////////////////////////////////////////////////
    // Formulario Newsletter
    $('#bt-enviar').click(function(event){
    
        email = $('#new-email').val();
        nome = $('#new-nome').val();
		
        
        error = false;
        
        $('.error, #error-categoria').hide();
        
        
        
        /*if (nome == '' || nome == 'Digite seu nome para receber novidades') {
         $('#new-nome').val('Nome inválido').css({'color': '#d60301'});
         error = true;
         }*/
        if (nome == '' || nome == 'Digite seu nome para receber novidades') {
            $('#error-nome').html('Nome inválido').fadeIn();
            error = true;
        }
        
        
        if (email == '' || email == 'Digite seu e-mail' || !validaEmail(email)) {
            $('#error-email').html('E-mail inválido').fadeIn();
            error = true;
        }
		
		if ($('#secoes-new input:checked').length == 0 ) {			
			$('#error-categoria').fadeIn();
			error = true;
		}
		
        
        
        if (error == false) {
        
            // $('#formulario-newsletter fieldset').append('<div id="carregandoNew"><img src="http://www.cocipa.com.br/theme/img/carregando.gif" alt="Carregando" /></div>');
            
			
            dados = $('#formulario-newsletter').serialize();
			
            $.ajax({
                type: 'post',
                url: 'http://www.cocipa.com.br/ajax.php',
                data: dados,
                dataType: 'json',
                success: function(valor){
                
                    // cadastro corretamente
                    if (valor.error == true) {
                        $('#new-email').val('Digite seu e-mail');
                        $('#new-nome').val('Digite seu nome para receber novidades');
                        $('#error-geral').html(valor.msg).fadeIn();
                        // Mostra mensagem cadastro Ok
                        $('#secoes-new').slideUp();
                        $('#carregandoNew').fadeOut().remove();
						$('#esconder').slideDown();
                        
                    }
                    else {
                    	$('#esconder').slideDown();
                        // Mostra Errors
                        $('#error-geral').html(valor.msg).fadeIn();
                        $('#carregandoNew').fadeOut().remove();
                    }
                }
            });
            
        }
        else {
         
         $('#esconder').slideDown();
		 $('#secoes-new').slideDown();
        
         
         }
         
        event.preventDefault(event);
        return false;
    });
    
    
    
    
    
    ////////////////////////////////////////////////////////////////////////////////////////
    // Formulario Contato
    $('#enviar-con').click(function(event){
    
        email = $('#con-email').val();
        nome = $('#con-nome').val();
        telefone = $('#con-telefone').val();
        assunto = $('#con-assunto').val();
        mensagem = $('#con-mensagem').val();
		cidade = $('#con-cidade').val();
        
        error = false;
        errorList = [];
        
        if (nome == '' || nome == 'Insira seu nome completo') {
            errorList.push('<strong>Nome inválido,</strong> por favor corrija o nome informado!');
            error = true;
        }
        
        if (email == '' || email == 'Insira seu e-mail verdadeiro' || !validaEmail(email)) {
            errorList.push('<strong>E-mail inválido,</strong> por favor corrija o e-mail informado!');
            error = true;
            
        }
		  if (cidade == ''  ) {
            errorList.push('<strong>Cidade inválida,</strong> por favor corrija a cidade informada!');
            error = true;
            
        }
        
        if (telefone == '') {
            errorList.push('<strong>Telefone inválido,</strong> por favor corrija o telefone informado!');
            error = true;
        }
        
        if (assunto == '') {
            errorList.push('<strong>Assunto inválido,</strong> por favor corrija o assunto informado!');
            error = true;
        }
        if (mensagem == '') {
            errorList.push('<strong>Mensagem inválida,</strong> por favor corrija a mensagem informada!');
            error = true;
        }
        
        
        $('#listErrors').slideUp().end();
        
        
        if (error == false) {
            $('#formulario-contato fieldset').append('<div class="center" id="carregandoNew"><img src="{$host}/theme/img/carregando.gif" alt="Carregando" /></div>');
            
            
            $.ajax({
                type: 'post',
                url: 'http://www.cocipa.com.br/ajax.php',
                data: {
                    'acao': 'contato',
                    'nome': nome,
                    'email': email,
                    'telefone': telefone,
                    'assunto': assunto,
                    'mensagem': mensagem,
					'cidade': cidade
                },
                dataType: 'json',
                success: function(valor){
                
                    // cadastro corretamente
                    if (valor.error == true) {
                    
                        $('.form-con').fadeOut();
                        $('#listErrors').html('<ul></ul>');
                        $('#listErrors ul').html('<li>' + valor.msg + '</li>');
                        $('#listErrors').slideDown();
                        $('#carregandoNew').fadeOut().remove();
                        
                    }
                    else {
                        $('#listErrors').html('<ul></ul>');
                        $('#listErrors ul').html('<li>' + valor.msg + '</li>');
                        $('#listErrors').slideDown();
                        $('#carregandoNew').fadeOut().remove();
                    }
                }
            });
            
        }
        else {
            errors = '';
            for (i = 0; i < errorList.length; i++) {
                errors += '<li>' + errorList[i] + '</li>';
            }
            
            $('#listErrors').html('<ul></ul>');
            $('#listErrors ul').html(errors);
            
            errors = '';
            errorList.length = 0;
            
            $('#listErrors').slideDown();
            
        }
        
        event.preventDefault(event);
        return false;
    });
    
    
    //////////////////////////////////////////////////////////////////
    // Slide Index Destaque
    /*
    if ($('#img-destaque img').size() > 1) {
        $('#des-1').fadeIn('slow');
        $('#item-1').fadeIn('slow');
        
        
        $('body').data('atual', 1);
        
        
        tempoSlideIndex = setInterval('slideIndex();', 5000);
        
        cont = 0;
        totalLink = $('#img-destaque img').size();
        // Acresento os botoes de navegacao
        $('#img-destaque img').each(function(){
            cont++;
            elemento = $(this);
            
            
            // Atribui o id do elemento
            elemento.attr('id', 'des-' + cont);
            
            // Crio o link de navegação
          //  $('#destaque').prepend('<a class="bt-destaque " onclick="slideIndex(' + cont + ')" id="bt-' + cont + '">0' + cont + '</a>');
            
            // Posiciono o link 
            $('#bt-' + cont).css('left', (995 - (totalLink * 25)));
            $('#bt-' + cont).css('top', 4);
            totalLink = totalLink - 1;
            
        });
        
        
        $('#bt-1').addClass('destaque');
        
    }
    else 
        if ($('#img-destaque img').size() == 1) {
            $('#des-1').fadeIn('slow');
            $('#item-1').fadeIn('slow');
            $('#bt-1').addClass('destaque');
        }
        else {
            $('#img-destaque-borda').hide();
        }
    
    
    */
    
    
    //////////////////////////////////////////////////////////////////////////////////////////
    // Slide Show Fornecedores
    if ($('#box-marcas-conteudo li').size() > 0) {
    
        $('#box-marcas-conteudo .inicio').fadeIn('slow');
        
        tempoSlide = setInterval('slideFornecedor("+");', 3000);
        
        
        $('#bt-voltar').click(function(event){
        
            clearInterval(tempoSlide);
            
            slideFornecedor('-');
            
            tempoSlide = setInterval('slideFornecedor("-");', 3000);
            
            event.preventDefault(event);
            return false;
        });
        
        $('#bt-avancar').click(function(event){
            clearInterval(tempoSlide);
            
            slideFornecedor('+');
            
            tempoSlide = setInterval('slideFornecedor("+");', 3000);
            
            event.preventDefault(event);
            return false;
        });
        
    }
    
    
    
    
    
    
    ////////////////////////////////////////////////////////////////////////////
    // Diminui a letra
    $('.letra-menor').click(function(){
        tamanhoFonte = $('#descricao').css('font-size');
        tamanhoLinha = $('#descricao').css('line-height');
        tamanhoFonte = parseInt(tamanhoFonte);
        tamanhoLinha = parseInt(tamanhoLinha);
        
        
        if (tamanhoFonte > 10) {
            $('#descricao').css({
                'font-size': tamanhoFonte - 2 + 'px',
                'line-height': tamanhoLinha - 2 + 'px'
            });
        }
        
    });
    
    ////////////////////////////////////////////////////////////////////////////
    // Aumenta a letra
    $('.letra-maior').click(function(){
        tamanhoFonte = $('#descricao').css('font-size');
        tamanhoLinha = $('#descricao').css('line-height');
        tamanhoFonte = parseInt(tamanhoFonte);
        tamanhoLinha = parseInt(tamanhoLinha);
        
        if (tamanhoFonte < 20) {
            $('#descricao').css({
                'font-size': tamanhoFonte + 2 + 'px',
                'line-height': tamanhoLinha + 2 + 'px'
            });
            
        }
        
    });
    
    
    //////////////////////////////////////////
    // Con telefone
    $("#con-telefone").mask("(99)9999-9999");
    
    
    
    // Botão Indique 
    $('.bt-indique').click(function(event){
    
        posicao = $(this).position();
        
        $('#indique-amigo').css({
            top: posicao.top + 40,
            left: posicao.left
        }).show();
        
        $('#indique-amigo .campo,#indique-amigo .botao, #fechar').show();
        $('.msg').hide();
        
        event.preventDefault(event);
        return false;
    });
    
    
    // Botão Fechar
    $('#fechar').live('click', function(event){
    
        $('#indique-amigo').hide();
        event.preventDefault(event);
        return false;
    });
    
    
    
    // Botão Imprimir
    $('.bt-imprimir a').click(function(event){
        window.print();
        event.prevenDefault(event);
        return false;
    });
    
    
    //////////////////////////////////////////////////////////////////////////////////////
    // Botão fechar
    $('#bt-fechar').click(function(event){
        $('#overlay').remove();
        $('#form-orcamento').hide();
        
        event.preventDefault(event);
        return false;
    });
});




function slideFornecedor($acao){

    atual = $('#box-marcas-conteudo .inicio');
    
    if ($acao == undefined || $acao == '+') {
        // Slide anadando para frente
        if (atual.next().hasClass('item')) {
            atual.fadeOut('slow').next().fadeIn('slow').addClass('inicio');
            atual.removeClass('inicio');
        }
        else {
            atual.removeClass('inicio').fadeOut('slow');
            $('#box-marcas-conteudo li:first').addClass('inicio').fadeIn('slow');
        }
    }
    else {
        // Slide voltando para tras		
        if (atual.prev().hasClass('item')) {
            atual.fadeOut('slow').prev().fadeIn('slow').addClass('inicio');
            atual.removeClass('inicio');
        }
        else {
            atual.removeClass('inicio').fadeOut('slow');
            $('#box-marcas-conteudo li:last').addClass('inicio').fadeIn('slow');
        }
        
    }
    
    
    
}






function validaEmail(mail){
    var er = RegExp(/^[A-Za-z0-9_\-\.]+@[A-Za-z0-9_\-\.]{2,}\.[A-Za-z0-9]{2,}(\.[A-Za-z0-9])?/);
    if (er.test(mail) == false) {
        return false;
    }
    
    return true;
}

function getPageScroll(){
    var xScroll, yScroll;
    if (self.pageYOffset) {
        yScroll = self.pageYOffset;
        xScroll = self.pageXOffset;
    }
    else 
        if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict
            yScroll = document.documentElement.scrollTop;
            xScroll = document.documentElement.scrollLeft;
        }
        else 
            if (document.body) {// all other Explorers
                yScroll = document.body.scrollTop;
                xScroll = document.body.scrollLeft;
            }
    arrayPageScroll = new Array(xScroll, yScroll);
    return arrayPageScroll;
};




function slideIndex($acao){

    atual = $('body').data('atual');
    
    if ($acao == undefined) {
        proximo = atual + 1;
        
        
        if (proximo > $('#img-destaque img').size()) {
            proximo = 1;
        }
        
        $('#des-' + proximo).fadeIn('slow');
        $('#item-' + proximo).fadeIn('slow');
        
        
        $('#des-' + atual).fadeOut('slow');
        $('#item-' + atual).fadeOut('slow');
        
        $('.bt-destaque').removeClass('destaque');
        $('#bt-' + proximo).addClass('destaque');
        $('body').data('atual', proximo);
        
        
        
        
    }
    else {
        clearInterval(tempoSlideIndex);
        proximo = $acao;
        
        
        if (atual != proximo) {
            if (proximo > $('#img-destaque img').size()) {
                proximo = 1;
            }
            
            $('#des-' + proximo).fadeIn('slow');
            $('#item-' + proximo).fadeIn('slow');
            
            $('#des-' + atual).fadeOut('slow');
            $('#item-' + atual).fadeOut('slow');
            
            $('.bt-destaque').removeClass('destaque');
            $('#bt-' + proximo).addClass('destaque');
            
            $('body').data('atual', proximo);
            
        }
        tempoSlideIndex = setInterval('slideIndex();', 5000);
        
    }
}






// Função p/ Mostrar as mensagens de error
function mostraError($campo, msg, error){

    // Tamanho do elemento 
    var wElemento = parseInt($campo.outerWidth());
    
    // Posicao
    var posicao = $campo.offset();
    
    // Cria a mensagem error
    $('body').append('<div class="errorPform" id="error' + error + '">' + msg + '</div>');
    
    // Posiciona a mensagem de error
    $('#error' + error).css({
        position: 'absolute',
        top: posicao.top - 15,
        left: posicao.left + wElemento - 110
    });
    
}









///////////////////////////////////////////////////////////////////////////////
// Enquete
$(function(){
    var loader = $('#loader');
    var pollcontainer = $('#pollcontainer');
    loader.fadeIn();
    idEnquete = $('#enquete-id').text();
    
    
    if (idEnquete != "") {
        //Load the poll form
        $.get('http://www.cocipa.com.br/poll.php', {
            "id": idEnquete
        }, function(data, status){
            pollcontainer.html(data);
            animateResults(pollcontainer);
            
            
            pollcontainer.find('#viewresult').click(function(){
                //if user wants to see result
                loader.fadeIn();
                $.get('http://www.cocipa.com.br/poll.php', {
                    "id": idEnquete,
                    "result": 1
                }, function(data, status){
                    pollcontainer.fadeOut(1000, function(){
                        $(this).html(data);
                        animateResults(this);
                    });
                    loader.fadeOut();
                });
                //prevent default behavior
                return false;
            }).end().find('#pollform').submit(function(){
                var selected_val = $(this).find('input[name=poll]:checked').val();
                if (selected_val != '') {
                    //post data only if a value is selected
                    loader.fadeIn();
                    $.post('http://www.cocipa.com.br/poll.php', $(this).serialize(), function(data, status){
                        $('#formcontainer').fadeOut(100, function(){
                            $(this).html(data);
                            animateResults(this);
                            loader.fadeOut();
                        });
                    });
                }
                //prevent form default behavior
                return false;
            });
            loader.fadeOut();
        });
        
    }
    else {
        $('#box-enquete').hide();
    }
    
    function animateResults(data){
        $(data).find('.bar').hide().end().fadeIn('slow', function(){
            $(this).find('.bar').each(function(){
                var bar_width = $(this).css('width');
                $(this).css('width', '0').animate({
                    width: bar_width
                }, 1000);
            });
        });
    }
    
});





Array.prototype.remove = function(from, to){
    var rest = this.slice((to || from) + 1 || this.length);
    this.length = from < 0 ? this.length + from : from;
    return this.push.apply(this, rest);
};


var timeout = 0;
var closetimer = 0;
var ddmenuitem = 0;

function jsddm_open(){

    $('#menu ul ul').css({
        'visibility': 'hidden'
    
    });
    jsddm_canceltimer();
    minW = $(this).width();
    $(this).addClass('over');
    ddmenuitem = $(this).find('ul').css({
        'visibility': 'visible',
        'min-width': minW
    });
    
    
    $(this).find('ul').children('li:last').children('a').css({
        'border-bottom-color': '#3d8b25',
        'border-bottom-style': 'dashed',
        'border-bottom-width': '1px'
    });
}

function jsddm_close(){
    if (ddmenuitem) 
        ddmenuitem.css('visibility', 'hidden');
}

function jsddm_timer(){
    $(this).removeClass('over');
    closetimer = window.setTimeout(jsddm_close, timeout);
}

function jsddm_canceltimer(){
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}

$(document).ready(function(){
    $('#menu > ul > li').bind('mouseover', jsddm_open)
    $('#menu > ul > li').bind('mouseout', jsddm_timer)
});

document.onclick = jsddm_close;




// Function Rotaciona banner
function rotacionarBanner(idBanner, total){


    atualElemento = $('#' + idBanner);
    atualNumero = atualElemento.attr('id');
    atualNumero = parseInt(atualNumero.replace('bt-', ''));
    atualElemento = $('#ban-' + atualNumero);
    
    $('.bt-banner').removeClass('ativo');
    
    if (atualNumero == total) {
        mostraElemento = $('#ban-1');
        $('#bt-' + total).addClass('ativo');
        atualNumero = 1;
    }
    else {
        mostraElemento = atualElemento.next();
		
		
        $('#bt-' + ( atualNumero )).addClass('ativo');
        atualNumero++;
    }
    
    $('#img-destaque .conteudo .item').css('z-index', 90).fadeOut('fast');
    mostraElemento.css('z-index', 100).fadeIn('fast');
    
    
    
    bannerTempo = setTimeout('rotacionarBanner("bt-' + atualNumero + '", ' + total + ');', 9000)
    return true;
}


