$(function(){
	
	$('#banner300x50 a, #banner315x280-2 a, .publicidade-centro a').attr('target', '_blank');
	$('.pub-centro a, #correr li a, #banner315x280 a').attr('target', '_blank');
	
	//mascaras
	$('#con_telefone').mask("(99) 9999-9999");
	$('#env_data').mask("99/99/999");
	
	////////////////////////////////////////////////////////////////////////////////////////
    // Slide das publicidades em carrocel   
    if ($('#correr .banner').size() > 0) {
	
		//setInterval("$('#bt-avancar').click()", 5000);
	
        // Botao Avancar
        $('#bt-avancar').click(function(event){
			
			clearInterval();
			
            atual = $('.ativo');
            filho = $('.ativo').next();
            
            if (filho.hasClass('banner')) {
            
                atual.removeClass('ativo');
                filho.addClass('ativo');
                
                $('#correr ul').animate({
                    "marginLeft": "-=153px"
                }, "slow");
            } else {
				
				atual.removeClass('ativo');
				$('.inicio').next().addClass('ativo');
				
                $('#correr ul').animate({
                    "marginLeft": "0px"
                }, "slow");
			}
			
            event.preventDefault();
            return false;
        });
        
        $('#bt-voltar').click(function(event){
			
			clearInterval();
			
            atual = $('.ativo');
            filho = $('.ativo').prev();
            
            if (!filho.hasClass('inicio')) {
            
                atual.removeClass('ativo');
                filho.addClass('ativo');
                
                $('#correr ul').animate({
                    "marginLeft": "+=153px"
                }, "slow");
            } else {
				for(i = 0; i < (($('#correr .banner').size()/2) - 2); i++) {
					$('#bt-avancar').click();
				}
			}
            event.preventDefault();
            return false;
        });
        
    }
	///////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	
	$('.lista-topo-noticia li:first').addClass('remove-space-noticia');
	
	$('#banner-flutuante a.fechar, #overlay-banner').live('click', function(event) {
		$('#overlay-banner').remove();
		$('#banner-flutuante').fadeOut('slow');
		event.preventDefault(event);
        return false;
	});
	setTimeout("$('#banner-flutuante a.fechar, #overlay-banner').click();", 10000);
	
	 $('#indicar').click(function(event) {
    
        WidthO = $('body').outerWidth();
        Width = (WidthO / 2) - 335;
        
        Height = parseInt($('body').height());
        
        Ph = getPageScroll();
        
        $('body').append('<div id="overlay"></div>');
        
        $('#overlay').css({
            'position': 'absolute',
            'width': WidthO,
            'height': Height,
            'top': 0,
            'left': 0,
            'z-index': 9999,
            'background-color': '#000000',
            'opacity': 0.75
        });
        
        $('.error').hide();
        
        $('#reportar-noticia').css({
            'position': 'absolute',
            'z-index': 99999,
            'left': Width,
            'top': Ph[1] + 50
        }).show();
        
        event.preventDefault(event);
        return false;
    });
	
	$('.fechar, #overlay').live('click', function(event) {
		$('#overlay').remove();
		$('#reportar-noticia').hide();
		event.preventDefault(event);
        return false;
	});
	
    // efeito correr e mostrar termos
    $('#termos-condicoes-item').click(function(){
		
		$(this).hide();
		
		$("#box-termos").slideDown();
		
        	$('html, body').animate({
            	scrollTop: $("#box-termos").offset().top
        	}, 1000, function(){
        });
    });
	
	$('#fechar-termos').click(function(){
		
		$('#termos-condicoes-item').show();
		
		$("#box-termos").slideUp();
		
        	$('html, body').animate({
            	scrollTop: $(".not-titulo").offset().top
        	}, 1000, function(){
        });
    });
	
	
	
	$('#txt-busca').click(function(){$(this).val('')});
	
	$('#box-facebook').html('<iframe src="//www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fpages%2FPop-Not%25C3%25ADcias%2F211752905578152&amp;width=315&amp;height=258&amp;colorscheme=light&amp;show_faces=true&amp;border_color=%23C1C1C0&amp;stream=false&amp;header=false" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:315px; height:258px;" allowTransparency="true"></iframe>');	
	
	 $('#bt-enviar-trab').click(function(event) {
    
        errors = false;
        
        // remover os erros 
        $('.error-form').remove();
        $('#env_nome, #env_email, #env_arquivos, #env_mensagem, #env_telefone').css('border', '1px solid #E0E0E0');
        
        if ($('#env_nome').val() == '') {
            errors = true;
            mostraErrorInterna($('#env_nome'), 'Digite o seu nome');
        }
        
		if ($('#env_telefone').val() == '') {
            errors = true;
            mostraErrorInterna($('#env_telefone'), 'Digite o seu telefone');
        }
	
        if ($('#env_email').val() == '' || !validaEmail($('#env_email').val())) {
            errors = true;
            mostraErrorInterna($('#env_email'), 'Digite um e-mail válido');
        }
        		
		if ($('#arquivo').val() == "" ) {
				errors = true;
				mostraErrorInterna($('#env_bt_arquivo'), 'Arquivo inválido');
		}		
		else  {
			if (!validaExtensaoCurriculo($('#arquivo').val())){
				errors = true;
				mostraErrorInterna($('#env_bt_arquivo'), 'Arquivo inválido');
			}			
		}
        
        if ($('#env_mensagem').val() == '') {
            errors = true;
            mostraErrorInterna($('#env_mensagem'), 'Digite o conteúdo');
        }
        
        if (errors == false) {
            $('#bt-enviar-trab').hide();
            $('.botao-enviar', '.form-interna').append('<img src="/theme/img/carregando.gif" alt="carregando" class="carregando-form" onclick="javascript:return false;" style="float:right;margin:5px 5px 0 0" />');
            return true;     
        }
        
        event.preventDefault(event);
        return false;
    });
	
	function mudarSlideIndex() {
		var elementoAtual = $('#box-galeria .thumb li.atual');	
		if(elementoAtual.next().hasClass('galeria-index')) {
			elementoAtual.next().click();
		} else {
			$('#item-1').click();
		}
	}
	
	$('#box-galeria .thumb li').click(function(){
		
		id = $(this).attr('id');
		id = id.replace('item-', '');
		
		$('#box-galeria .thumb .atual').removeClass('atual');
		$('#box-galeria .foto-principal a ').fadeOut();
		$('#box-galeria .titulo-data .item ').fadeOut();
				
		
		$(this).addClass('atual');
		$('#box-galeria .foto-principal .item-' + id).fadeIn();
		$('#box-galeria .titulo-data .item-' + id).fadeIn();		
		
	});
	
	if ( $('#box-galeria').size() > 0 ) {
		$('#box-galeria .thumb #item-1').click();
	}
	
	setInterval(mudarSlideIndex, 6000);
	
	$('#info #bt-1,#info #bt-2,#info #bt-3').click(function(event){
		
		clearInterval();
		
		id = $(this).attr('id');
		id = id.replace('bt-','');		
		
		$('#info .atual').removeClass('atual');
		
		$(this).addClass('atual');
		$('#info .cont-' + id).addClass('atual');
		
        event.preventDefault(event);
        return false;
	});
	
	
	

    // Botão Enviar Comunicado de erros
    $('#bt-enviar-env').click(function(event){
    
        errors = false;
        
        // remover os erros 
        $('.error-form').remove();
        $('#env_titulo, #env_data, #env_arquivos, #env_mensagem, #env_cidade, #env_estado').css('border', '1px solid #E0E0E0');
        
        if ($('#env_titulo').val() == '') {
            errors = true;
            mostraErrorInterna($('#env_titulo'), 'Digite o titulo');
        }
        
        if ($('#env_data').val() == '' || $('#env_data') == 'Adiciona ') {
            errors = true;
            mostraErrorInterna($('#env_data'), 'Digite a data');
        }
		
		
		if ($('#arquivo').val() != "") {
			if (!validaExtensao($('#arquivo').val())){
				errors = true;
				mostraErrorInterna($('#env_arquivos'), 'Arquivo inválido');
			}			
		}
        
        if ($('#env_mensagem').val() == '') {
            errors = true;
            mostraErrorInterna($('#env_mensagem'), 'Digite o conteúdo');
        }
        
        
        if ($('#env_cidade').val() == '') {
            errors = true;
            mostraErrorInterna($('#env_cidade'), 'Digite a sua cidade');
        }
        
        if ($('#env_estado').val() == '') {
            errors = true;
            mostraErrorInterna($('#env_estado'), 'Selecione o estado');
        }
        
        
        if (errors == false) {
            $('#bt-enviar-env').hide();
            $('.botao-enviar', '.form-interna').append('<img src="/theme/img/carregando.gif" alt="carregando" class="carregando-form" onclick="javascript:return false;" style="float:right;margin:5px 5px 0 0" />');
            
            return true;            
        }
        
        
        event.preventDefault(event);
        return false;
    });
    
    
    
    
    // Envie a sua Noticia 
    // Botão de arquivo
    $('#env_bt_arquivo').click(function(event){
    
        $('#arquivo').click();
        
        event.preventDefault(event);
        return false;
    });
    
    
    
    $('#arquivo').change(function(){
		
        $('#env_arquivos').val($('#arquivo').val());
    });
    
    
    // inicializa os banners 
    setTimeout('bannerTopo600x100();', 3000);
    setTimeout('bannerTopo180x100();', 5000);
    setTimeout('bannerLateral300x50();', 2000);
    setTimeout('bannerCentro315x180Coluna1();', 1000);
    setTimeout('bannerCentro315x180Coluna2();', 5000);
    setTimeout('bannerCentro315x180Coluna2();', 3000);
    setTimeout('bannerCentro315x195Coluna1();', 8000);
    setTimeout('bannerCentro315x195Coluna2();', 1000);
    
    
    // Botão Enviar Comunicado de erros
    $('#bt-enviar-ind').click(function(event){
    
        errors = false;
        
        // remover os erros 
        $('.error-form').remove();
        $('#ind_nome, #ind_email, #ind_destinatarios, #ind_mensagem').css('border', '1px solid #E0E0E0');
        
        if ($('#ind_nome').val() == '') {
            errors = true;
            mostraErrorInterna($('#ind_nome'), 'Digite seu nome');
        }
        
        if ($('#ind_email').val() == '' || !validaEmail($('#ind_email').val())) {
            errors = true;
            mostraErrorInterna($('#ind_email'), 'Digite um e-mail válido');
        }
        
        
        if ($('#ind_destinatarios').val() == '') {
            errors = true;
            mostraErrorInterna($('#ind_destinatarios'), 'Digite os destinatários');
        }
        
        if ($('#ind_mensagem').val() == '') {
            errors = true;
            mostraErrorInterna($('#ind_mensagem'), 'Digite sua mensagem');
        }
        
        if (errors == false) {
            $('#bt-enviar-ind').hide();
            $('.botao-enviar', '.form-interna').append('<img src="/theme/img/carregando.gif" alt="carregando" class="carregando-form" onclick="javascript:return false;" style="float:right;margin:5px 5px 0 0" />');
            
            $.get('/ajax.php', $(this).parents('form').serialize(), function(resp, evento, httpRequest){
            
                if (resp.retorno == true) {
                
                    $('.form-interna fieldset').hide().after('<div class="msg-sucesso"><p>Sua mensagem foi enviada com sucesso! Agradecemos a colaboração.</p><a class="bt-mostrar-formulario-interna" href="#">Mostrar formulário</a> </div>');
                    
                    $('#ind_nome, #ind_email, #ind_destinatarios, #ind_mensagem').val('');
                    
                }
                else {
                    alert('Não foi possivel enviar a sua mensagem por favor tente novamente mais tarde ou entre com contato. Obrigado');
                }
                
            }, 'json');
        }
        
        
        event.preventDefault(event);
        return false;
    });
    
    
    
    
    // Limpa os campos
    $('#txt-newsletter, #com_comentario, #com_nome, #com_email,#env_data').focus(function(event){
        valorAntigo = $(this).attr('value');
        
        if (valorAntigo == 'E-mail cadastrado com sucesso' ||
        valorAntigo == 'Digite seu e-mail' ||
        valorAntigo == 'Nome' ||
        valorAntigo == 'E-mail' ||
        valorAntigo == 'Comentário' ||
		valorAntigo == 'Adicione a data') {
            $(this).attr('value', '');
        }
        
		
		if ($(this).attr('id') == 'env_data') {
				$("#env_data").mask("99/99/9999");
			}
        
        
    }).blur(function(event){
        if ($(this).attr('value') == '') {
            if (valorAntigo == 'E-mail cadastrado com sucesso' ||
            valorAntigo == 'Digite seu e-mail' ||
            valorAntigo == 'Nome' ||
            valorAntigo == 'E-mail' ||
            valorAntigo == 'Comentário'||
		valorAntigo == 'Adicione a data') {
                $(this).attr('value', valorAntigo);
            }
        }
        
		
		if ($(this).attr('id') == 'env_data') {		
			$('#env_data').unmask();
		}
        
    });
    
    
    
    // Botão Enviar Comunicado de erros
    $('#bt-newsletter').click(function(event){
    
        errors = false;
        
        // remover os erros 
        $('.error-form').remove();
        //$('#comu_nome, #comu_email, #comu_area, #comu_mensagem').css('border', '1px solid #E0E0E0');     
        
        
        if ($('#txt-newsletter').val() == '' || !validaEmail($('#txt-newsletter').val())) {
            errors = true;
            mostraErrorNewsletter($('#txt-newsletter'), 'Digite um e-mail válido');
        }
        
        
        if (errors == false) {
            $('#bt-newsletter').hide();
            $('.botao-enviar', '#box-newsletter').append('<img src="/theme/img/carregando.gif" alt="carregando" class="carregando-form" onclick="javascript:return false;" style="float:right;margin:5px 0 0 20px" />');
            
            $.get('/ajax.php', $(this).parents('form').serialize(), function(resp, evento, httpRequest){
            
                if (resp.retorno == true) {
                
                    //   $('.form-interna fieldset').hide().after('<div class="msg-sucesso"><p>Sua mensagem foi enviada com sucesso! Agradecemos a colaboração.</p><a class="bt-mostrar-formulario-interna" href="#">Mostrar formulário</a> </div>');
                    
                    $('#bt-newsletter').show();
                    $('.carregando-form').remove();
                    
                    $('#txt-newsletter').val('');
					
					mostraErrorNewsletter($('#txt-newsletter'), 'E-mail cadastrado com sucesso', 'ok');
                    
                }
                else {
                
                    if (resp.msg != '') {
                        alert(resp.msg);
                        $('#bt-newsletter').show();
                        $('.carregando-form').remove();
                    }
                    else {
                        alert('Não foi possivel enviar a sua mensagem por favor tente novamente mais tarde ou entre com contato. Obrigado');
                        $('.carregando-form').remove();
                        $('#bt-newsletter').show();
                    }
                }
                
            }, 'json');
        }
        
        
        event.preventDefault(event);
        return false;
    });
	
	
	// Botão Enviar Comunicado de erros
    $('#bt-reportar').click(function(event){
    
        errors = false;
        
        // remover os erros 
        $('.error-form').remove();
        $('#comu_nome, #comu_email, #comu_area, #comu_mensagem').css('border', '1px solid #E0E0E0');
        
        if ($('#comu_nome').val() == '') {
            errors = true;
            mostraErrorInterna($('#comu_nome'), 'Digite seu nome');
        }
        
        if ($('#comu_email').val() == '' || !validaEmail($('#comu_email').val())) {
            errors = true;
            mostraErrorInterna($('#comu_email'), 'Digite um e-mail válido');
        }
        
        
        if ($('#comu_area').val() == '') {
            errors = true;
            mostraErrorInterna($('#comu_area'), 'Selecione uma área');
        }
        
        if ($('#comu_mensagem').val() == '') {
            errors = true;
            mostraErrorInterna($('#comu_mensagem'), 'Digite sua mensagem');
        }
        
        if (errors == false) {
            $('#bt-enviar-comu').hide();
            $('.botao-enviar', '.form-interna').append('<img src="/theme/img/carregando.gif" alt="carregando" class="carregando-form" onclick="javascript:return false;" style="float:right;margin:5px 5px 0 0" />');
            
            $.get('/ajax.php', $(this).parents('form').serialize(), function(resp, evento, httpRequest){
            
                if (resp.retorno == true) {
                
                    $('.form-interna fieldset').hide().after('<div class="msg-sucesso"><p>Sua mensagem foi enviada com sucesso! Agradecemos a colaboração.</p><a class="bt-mostrar-formulario-interna" href="#">Mostrar formulário</a> </div>');
                    
                    $('#comu_nome, #comu_email, #comu_mensagem').val('');
                    
                }
                else {
                    alert('Não foi possivel enviar a sua mensagem por favor tente novamente mais tarde ou entre com contato. Obrigado');
                }
                
            }, 'json');
        }
        
        
        event.preventDefault(event);
        return false;
    });
    
    
    
    // Botão Enviar Comunicado de erros
    $('#bt-enviar-comu').click(function(event){
    
        errors = false;
        
        // remover os erros 
        $('.error-form').remove();
        $('#comu_nome, #comu_email, #comu_area, #comu_mensagem').css('border', '1px solid #E0E0E0');
        
        if ($('#comu_nome').val() == '') {
            errors = true;
            mostraErrorInterna($('#comu_nome'), 'Digite seu nome');
        }
        
        if ($('#comu_email').val() == '' || !validaEmail($('#comu_email').val())) {
            errors = true;
            mostraErrorInterna($('#comu_email'), 'Digite um e-mail válido');
        }
        
        
        if ($('#comu_area').val() == '') {
            errors = true;
            mostraErrorInterna($('#comu_area'), 'Selecione uma área');
        }
        
        if ($('#comu_mensagem').val() == '') {
            errors = true;
            mostraErrorInterna($('#comu_mensagem'), 'Digite sua mensagem');
        }
        
        if (errors == false) {
            $('#bt-enviar-comu').hide();
            $('.botao-enviar', '.form-interna').append('<img src="/theme/img/carregando.gif" alt="carregando" class="carregando-form" onclick="javascript:return false;" style="float:right;margin:5px 5px 0 0" />');
            
            $.get('/ajax.php', $(this).parents('form').serialize(), function(resp, evento, httpRequest){
            
                if (resp.retorno == true) {
                
                    $('.form-interna fieldset').hide().after('<div class="msg-sucesso"><p>Sua mensagem foi enviada com sucesso! Agradecemos a colaboração.</p><a class="bt-mostrar-formulario-interna" href="#">Mostrar formulário</a> </div>');
                    
                    $('#comu_nome, #comu_email, #comu_mensagem').val('');
                    
                }
                else {
                    alert('Não foi possivel enviar a sua mensagem por favor tente novamente mais tarde ou entre com contato. Obrigado');
                }
                
            }, 'json');
        }
        
        
        event.preventDefault(event);
        return false;
    });
    
    
    // Botão Enviar Contato
    $('#bt-enviar-con').click(function(event){
    
        errors = false;
        
        // remover os erros 
        $('.error-form').remove();
        $('#con_nome, #con_email, #con_assunto, #con_telefone, #con_mensagem').css('border', '1px solid #E0E0E0');
        
        if ($('#con_nome').val() == '') {
            errors = true;
            mostraErrorInterna($('#con_nome'), 'Digite seu nome');
        }
        
        if ($('#con_email').val() == '' || !validaEmail($('#con_email').val())) {
            errors = true;
            mostraErrorInterna($('#con_email'), 'Digite um e-mail válido');
        }
        
        if ($('#con_assunto').val() == '') {
            errors = true;
            mostraErrorInterna($('#con_assunto'), 'Digite o assunto');
        }
        
        if ($('#con_telefone').val() == '') {
            errors = true;
            mostraErrorInterna($('#con_telefone'), 'Digite seu telefone');
        }
        
        if ($('#con_mensagem').val() == '') {
            errors = true;
            mostraErrorInterna($('#con_mensagem'), 'Digite sua mensagem');
        }
        
        if (errors == false) {
            $('#bt-enviar-con').hide();
            $('.botao-enviar', '.form-interna').append('<img src="/theme/img/carregando.gif" alt="carregando" class="carregando-form" onclick="javascript:return false;" style="float:right;margin:5px 5px 0 0" />');
            
            $.get('/ajax.php', $(this).parents('form').serialize(), function(resp, evento, httpRequest){
            
                if (resp.retorno == true) {
                
                    $('.form-interna fieldset').hide().after('<div class="msg-sucesso"><p>Sua mensagem foi enviada com sucesso! Agradecemos a colaboração.</p><a class="bt-mostrar-formulario-interna" href="#">Mostrar formulário</a> </div>');
                    
                    $('#con_nome, #con_email, #con_assunto, #con_telefone, #con_mensagem').val('');
                    
                }
                else {
                    alert('Não foi possivel enviar a sua mensagem por favor tente novamente mais tarde ou entre com contato. Obrigado');
                }
                
            }, 'json');
        }
        
        event.preventDefault(event);
        return false;
    });
    
    // Colorbox
    $('a[rel="popup"]').colorbox({
        slideshow: true
    });
    
    $('.bt-defini-inicial').click(function(event){
        setHomepage();
        event.preventDefault(event);
        return false;
    });
    
    $('.add-favorito').click(function(event){
        addFav();
        event.preventDefault(event);
        return false;
    });
    
    // Links 
    $('.externo').attr('target', '_blank');
    
    // Previsão do tempo 
    if ($('#tempo').size() > 0) {
		
		cidade = $('#cidade-principal-dado').text();
		estado = $('#estado-principal-dado').text();
    
        $('#tempo').hide();
        $('.coluna-1-sem-overflow').append('<div id="carregando-tempo"><img src="/theme/img/carregando.gif" alt="carregando" /></div>');
        $.get('/ajax.php', {
            'acao': 'tempo',
            'cidade': cidade,
            'estado': estado
        }, function(data, status, xhttp){
        
            $('#tempo img').attr('src', data.img);
            $('#tempo .topo .max strong').text(data.max);
            $('#tempo .topo .min strong').text(data.min);
            $('#tempo .topo .cidade').html(estado);
            $('#tempo .previsao').text(data.previsao);
            
            $('#carregando-tempo').remove();
            $('#tempo').show();
            $('#cidades').hide();
        }, 'json');
		
        // Esconde a lista de cidades
        $('#tempo').mouseover(function(event){
            event.preventDefault(event);
            return false;
        });
		
        $('body').mouseover(function(event){
            $('#cidades').slideUp();
        });
        
        
        // Lista de cidades
        $('#cidades li').mouseover(function(){
            $(this).css('text-decoration', 'underline');
        }).mouseout(function(){
            $(this).css('text-decoration', 'none');
        }).click(function(event){
            $('.coluna-1-sem-overflow').append('<div id="carregando-tempo"><img src="/theme/img/carregando.gif" alt="carregando" /></div>');
            $('#tempo').hide();
            $('#cidades').slideUp();
            
            cidade = $('.id-cidade', this).text();
            estado = $('.id-estado', this).text();
            
            $.get('/ajax.php', {
                'acao': 'tempo',
                'cidade': cidade,
                'estado': estado
            }, function(data, status, xhttp){
            
                $('#tempo img').attr('src', data.img);
                $('#tempo .topo .max strong').text(data.max);
                $('#tempo .topo .min strong').text(data.min);
                $('#tempo .topo .cidade').text(cidade);
                $('#tempo .previsao').text(data.previsao);
                
                $('#carregando-tempo').remove();
                $('#tempo').show();
                $('#cidades').hide();
            }, 'json');
        });
        
        // Ações botão Cidade
        $('#tempo .op-cidades').mouseover(function(){
            //$(this).css('text-decoration', 'underline');
        }).mouseout(function(){
           // $(this).css('text-decoration', 'none');
        }).click(function(event){
            position = $('#tempo .op-cidades').position();
            $('#cidades').slideToggle().css('left', position.left);
            
        });
        
    }
    
    
    // Aba Mais Lidas / Mais comentadas 
    $('.abas-op li').click(function(event){
    
    
        aba = $(this).text();
        
        if (aba == 'Mais comentadas') {
        
            $(this).parents('.abas-op').children('li').removeClass('ativa');
            
            $(this).parents('.container-abas').children('.conteudo-abas').children('div').removeClass('ativa');
            
            $(this).addClass('ativa');
            $('#aba-comentadas').addClass('ativa');
        }
        else 
            if (aba == 'Notícias mais lidas') {
                $(this).parents('.abas-op').children('li').removeClass('ativa');
                
                $(this).parents('.container-abas').children('.conteudo-abas').children('div').removeClass('ativa');
                
                $(this).addClass('ativa');
                $('#aba-lidas').addClass('ativa');
            }
        
        event.preventDefault(event);
        return false;
    });
    
    
    // Botão Enviar comentario
    $('#com_enviar').click(function(event){
    
        errors = false;
        
        // remover os erros 
        $('.error-form').remove();
        $('#com_nome, #com_email, #com_mensagem').css('border-color', '#ABABAB');
        
        if ($('#com_nome').val() == '' || $('#com_nome').val() == 'Nome') {
            errors = true;
            mostraError($('#com_nome'), 'Digite seu nome');
        }
        
        
        if ($('#com_email').val() == '' || !validaEmail($('#com_email').val())) {
            errors = true;
            mostraError($('#com_email'), 'Digite um e-mail válido');
        }
        
        if ($('#com_comentario').val() == '' || $('#com_comentario').val() == 'Comentário') {
            errors = true;
            mostraError($('#com_comentario'), 'Digite seu comentário');
        }
        
        if (errors == false) {
            $('#com_enviar').hide();
            $('.com_enviar', '.form').append('<img src="/theme/img/carregando.gif" alt="carregando" class="carregando-form" onclick="javascript:return false;" style="float:right;margin:5px 5px 0 0" />');
            
            $.get('/ajax.php', $(this).parents('form').serialize(), function(resp, evento, httpRequest){
            
                if (resp.retorno == true) {
                
                    $('#box-comentarios .form').hide().after('<div class="msg-sucesso"><p>Seu comentário foi enviado com sucesso! Agradecemos a colaboração.</p><a class="bt-mostrar-formulario" href="#">Mostrar formulário</a> </div>');
                    
                    $('#com_nome').val('Nome');
                    $('#com_email').val('E-mail');
                    $('#com_comentario').val('Comentário');
                }
                else {
                    alert('Não foi possivel enviar a sua correção por favor tente novamente mais tarde ou entre com contato. Obrigado');
                }
                
            }, 'json');
        }
        
        
        event.preventDefault(event);
        return false;
    });
    
    // Mostra o Formulario
    $('.bt-mostrar-formulario').live('click', function(event){
    
        $('#cor_enviar,#rec_enviar,#com_enviar').show();
        
        $(this).parents('.box-comentario').children('.form').show();
        $('.carregando-form, .msg-sucesso').remove();
        
        event.preventDefault(event);
        return false;
        
    });
    
    
    // Mostra o Formulario
    $('.bt-mostrar-formulario-interna').live('click', function(event){
    
        $('#bt-enviar-con, #bt-enviar-comu, #bt-enviar-ind').show();
        
        $(this).parents('form').children('fieldset').show();
        $('.carregando-form, .msg-sucesso').remove();
        
        event.preventDefault(event);
        return false;
    });
    
    
    
    ////////////////////////////////////////////////////////////////
    // Botão Imprimir	
    $('.print').click(function(event){
        window.print();
        event.preventDefault(event);
    });
    
    ////////////////////////////////////////////////////////////////
    // diminui a Aumentar
    $('.texto-aumentar').click(function(event){
        $('.noticia-conteudo .texto').each(function(index){
        
            fontAtual = parseInt($(this).css('font-size'));
            lineHeightAtual = parseInt($(this).css('line-height'));
            
            if (fontAtual <= 28) {
            
                $(this).css({
                    'font-size': (fontAtual + 2) + 'px',
                    'line-height': (lineHeightAtual + 2) + 'px'
                });
            }
        });
        event.preventDefault(event);
        return false;
    });
    
    ////////////////////////////////////////////////////////////////
    // diminui a fonte
    $('.texto-diminuir').click(function(event){
        $('.noticia-conteudo .texto').each(function(index){
        
            fontAtual = parseInt($(this).css('font-size'));
            lineHeightAtual = parseInt($(this).css('line-height'));
            
            if (fontAtual >= 10) {
            
                $(this).css({
                    'font-size': (fontAtual - 2) + 'px',
                    'line-height': (lineHeightAtual - 2) + 'px'
                });
            }
        });
        event.preventDefault(event);
        return false;
    });
    
    
    
    // REDES SOCIAS
    if ($('#redes-sociais').length > 0) {
    
        link = $('#link-social').text();
        titulo = $('#titulo-social').text() + '- GI Notícias ';
        
        //$('#g1').html('');
        
        
        
        // Botão 1+
        $.getScript('http://apis.google.com/js/plusone.js', function(){
            gapi.plusone.go();
        });
        
        
        curtir = '<iframe src="http://www.facebook.com/plugins/like.php?href=' + link + '&layout=standard&show_faces=false&width=100&action=like&colorscheme=light&height=25&locale=pt_BR" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:200px; height:32px;" allowTransparency="true"></iframe>';
        
        //  botão cutir
        $('#like').html(curtir);
        
        // Botão Tweet
        $('#tweet').html('<a href="http://twitter.com/share" class="twitter-share-button" data-url="' + link + '" data-text="' + titulo + '" data-count="horizontal" data-via="GINoticias">&nbsp;</a>');
        $.getScript('http://platform.twitter.com/widgets.js', function(){
            $('#tweet').each(function(i){
                //var loadedTweetButton =  twttr.TweetButton(i);
                //loadedTweetButton.render();
            });
        });
    }
    
});


function mostraError(campo, msg){
    campo.parents('.campo-form').prepend('<span class="error-form" style="position:absolute;top:-17px;left:6px;color:#ba0000;">' + msg + '</span>');
    campo.css('border-color', '#ba0000');
}

function mostraErrorInterna(campo, msg){
    campo.parents('.campo-form').prepend('<span class="error-form" style="position:absolute;top:0px;right:6px;color:#ba0000;">' + msg + '</span>');
    campo.css('border-color', '#ba0000');
}

function mostraErrorNewsletter(campo, msg, ok){	
	if (ok == 'ok') {
		campo.parents('.campo-form').prepend('<span class="error-form" style="position:absolute;top:-17px;left:0px;color:green;">' + msg + '</span>');	
	}
	else {
		campo.parents('.campo-form').prepend('<span class="error-form" style="position:absolute;top:-17px;left:0px;color:#ba0000;">' + msg + '</span>');
		campo.css('border-color', '#ba0000');
	}
}

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;
}


///////////////////////////////////////////////////////////////////////////////
// Enquete
$(function(){
    var loader = $('#loader');
    var pollcontainer = $('#pollcontainer');
    loader.fadeIn();
    idEnquete = $('#enquete-id').text();
    
    
    if (idEnquete != "") {
        //Load the poll form
        $.get('http://www.popnoticias.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.popnoticias.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.popnoticias.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);
            });
        });
    }
});

function getPageScroll() {
    
	var xScroll, yScroll;
    
	if (self.pageYOffset) {
        yScroll = self.pageYOffset;
        xScroll = self.pageXOffset;
    }
    else 
        if (document.documentElement && document.documentElement.scrollTop) {
            yScroll = document.documentElement.scrollTop;
            xScroll = document.documentElement.scrollLeft;
        }
        else 
            if (document.body) {
                yScroll = document.body.scrollTop;
                xScroll = document.body.scrollLeft;
            }
    arrayPageScroll = new Array(xScroll, yScroll);
    return arrayPageScroll;
};



function addFav(){
    var url = "http://www.popnoticias.com.br";
    var title = "POP Notícias - O melhor portal de notícias do Oeste Paulista";
    if (window.sidebar) 
        window.sidebar.addPanel(title, url, "");
    else 
        if (window.opera && window.print) {
            var mbm = document.createElement('a');
            mbm.setAttribute('rel', 'sidebar');
            mbm.setAttribute('href', url);
            mbm.setAttribute('title', title);
            mbm.click();
        }
        else 
            if (document.all) {
                window.external.AddFavorite(url, title);
            }
}



function setHomepage(){
    if (document.all) {
        document.body.style.behavior = 'url(#default#homepage)';
        document.body.setHomePage('http://www.popnoticias.com.br');
        
    }
    else 
        if (window.sidebar) {
            if (window.netscape) {
                try {
                    netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesRead UniversalFileRead");
                } 
                catch (e) {
                    alert("O Firefox vem com está opção bloqueada, vá na opção FERRAMENTAS / OPÇÔES / GERAL e cole a URL deste site em 'Página inicial'. Em seguida clique em 'OK'");
                }
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage', 'http://www.popnoticias.com.br');
        }
}



// Rotação banner topo 
function bannerTopo600x100(){

    total = $('.b1').size() + 1;
    
    
    if (total > 1) {
		
        atual = $('.b1-hover').attr('id');
        atual = atual.replace('b1-', '');
        
        if (atual != total) {
            $('#b1-' + atual).attr('class', 'b1').next().attr('class', 'b1-hover');
        }
        else {
            $('#b1-' + atual).attr('class', 'b1');
            $('#b1-1').attr('class', 'b1-hover');
        }
        
        tempoBannerTopoMaior = setTimeout('bannerTopo600x100 ();', 8000);
    }
}

function bannerTopo180x100(){

    total = $('.b2').size() + 1;
    
    if (total > 1) {
    
        atual = $('.b2-hover').attr('id');
        atual = atual.replace('b2-', '');
        
        if (atual != total) {
            $('#b2-' + atual).attr('class', 'b2').next().attr('class', 'b2-hover');
        }
        else {
            $('#b2-' + atual).attr('class', 'b2');
            $('#b2-1').attr('class', 'b2-hover');
        }
        
        tempoBannerTopoMaior = setTimeout('bannerLateral300x50 ();', 8000);
    }
}


function bannerLateral300x50(){

    total = $('.b3').size() + 1;
    
    
    if (total > 1) {
    
        atual = $('.b3-hover').attr('id');
        atual = atual.replace('b3-', '');
        
        
        if (atual != total) {
            $('#b3-' + atual).attr('class', 'b3').next().attr('class', 'b3-hover');
        }
        else {
            $('#b3-' + atual).attr('class', 'b3');
            $('#b3-1').attr('class', 'b3-hover');
        }
        
        tempoBannerTopoMaior = setTimeout('bannerTopo180x100 ();', 8000);
    }
}


function bannerCentro315x180Coluna1(){

    total = $('.b4-1').size() + 1;
    
    if (total > 1) {
    
        atual = $('.b4-1-hover').attr('id');
        atual = atual.replace('b4-1-', '');
        
        if (atual != total) {
            $('#b4-1-' + atual).attr('class', 'b4-1').next().attr('class', 'b4-1-hover');
        }
        else {
            $('#b4-1-' + atual).attr('class', 'b4-1');
            $('#b4-1-1').attr('class', 'b4-1-hover');
        }
        
        
        tempoBannerTopoMaior = setTimeout('bannerCentro315x180Coluna1 ();', 8000);
    }
}


function bannerCentro315x180Coluna2(){

    total = $('.b4-2').size() + 1;
    
    if (total > 1) {
    
        atual = $('.b4-2-hover').attr('id');
        atual = atual.replace('b4-2-', '');
        
        if (atual != total) {
            $('#b4-2-' + atual).attr('class', 'b4-2').next().attr('class', 'b4-2-hover');
        }
        else {
            $('#b4-2-' + atual).attr('class', 'b4-2');
            $('#b4-2-1').attr('class', 'b4-2-hover');
        }
        
        
        tempoBannerTopoMaior = setTimeout('bannerCentro315x180Coluna2 ();', 8000);
    }
}


function bannerCentro315x180Coluna3(){

    total = $('.b4-3').size() + 1;
    
    if (total > 1) {
    
        atual = $('.b4-3-hover').attr('id');
        atual = atual.replace('b4-3-', '');
        
        if (atual != total) {
            $('#b4-3-' + atual).attr('class', 'b4-3').next().attr('class', 'b4-3-hover');
        }
        else {
            $('#b4-3-' + atual).attr('class', 'b4-3');
            $('#b4-3-1').attr('class', 'b4-3-hover');
        }
        
        
        tempoBannerTopoMaior = setTimeout('bannerCentro315x180Coluna3 ();', 8000);
    }
}




function bannerCentro315x195Coluna1(){

    total = $('.b5-1').size() + 1;
    
    if (total > 1) {
    
        atual = $('.b5-1-hover').attr('id');
        atual = atual.replace('b5-1-', '');
        
        if (atual != total) {
            $('#b5-1-' + atual).attr('class', 'b5-1').next().attr('class', 'b5-1-hover');
        }
        else {
            $('#b5-1-' + atual).attr('class', 'b5-1');
            $('#b5-1-1').attr('class', 'b5-1-hover');
        }
        
        
        tempoBannerTopoMaior = setTimeout('bannerCentro315x195Coluna1 ();', 8000);
    }
}


function bannerCentro315x195Coluna2(){

    total = $('.b5-2').size() + 1;
    
    if (total > 1) {
    
        atual = $('.b5-2-hover').attr('id');
        atual = atual.replace('b5-2-', '');
        
        if (atual != total) {
            $('#b5-2-' + atual).attr('class', 'b5-2').next().attr('class', 'b5-2-hover');
        }
        else {
            $('#b5-2-' + atual).attr('class', 'b5-2');
            $('#b5-2-1').attr('class', 'b5-2-hover');
        }
        
        
        tempoBannerTopoMaior = setTimeout('bannerCentro315x195Coluna2 ();', 8000);
    }
}


function validaExtensaoCurriculo(arquivo){
    extensoes_permitidas = new Array(".doc",".docx", ".pdf");
    meuerro = "";
    if (!arquivo) {
        //Se não tenho arquivo, é porque não se selecionou um arquivo no formulário.
        meuerro = "Não foi selecionado nenhum arquivo";
    }
    else {
        //recupero a extensão deste nome de arquivo
        extensao = (arquivo.substring(arquivo.lastIndexOf("."))).toLowerCase();
        //alert (extensao);
        //comprovo se a extensão está entre as permitidas
        permitida = false;
        for (var i = 0; i < extensoes_permitidas.length; i++) {
            if (extensoes_permitidas[i] == extensao) {
                permitida = true;
                break;
            }
        }
        if (!permitida) {
            meuerro = "Extensão inválida. \nSó se podem ser enviados arquivos com extensões: " + extensoes_permitidas.join();
        }
        else {
            return 1;
        }
    }    
    return 0;
}

function validaExtensao(arquivo){
	
    extensoes_permitidas = new Array(".bmp",".jpg",".jpeg",".gif",".png",".3g2",".3gp",".3gp2",".3gpp",".asf",".avi",".divx",".dv",".dvx",".f4v",".flv",".h263",".m4e",".m4v",".wmv",".mov",".movie",".mp4",".mpg",".mpeg",".qt",".rm");
    
	meuerro = "";
	
    if (!arquivo) {
        //Se não tenho arquivo, é porque não se selecionou um arquivo no formulário.
        meuerro = "Não foi selecionado nenhum arquivo";
    }
    else {
        
		//recupero a extensão deste nome de arquivo
		extensao = (arquivo.substring(arquivo.lastIndexOf("."))).toLowerCase();
		
        //comprovo se a extensão está entre as permitidas
        permitida = false;
        for (var i = 0; i < extensoes_permitidas.length; i++) {
            if (extensoes_permitidas[i] == extensao) {
                permitida = true;
                break;
            }
        }
        if (!permitida) {
            meuerro = "Extensão inválida. \n Só se podem ser enviados arquivos com extensões: " + extensoes_permitidas.join();
        }
        else {
            return 1;
        }
    }    
    return 0;
}
