$(document).ready(function(){
	//headline rotate
	headline_count = $("div.headline").size();
	$("div.headline:eq("+current_headline+")").css('top', '4px');
	headline_interval = setInterval(headline_rotate,5000);
	$('#noticias').hover(function() {
		clearInterval(headline_interval);
	}, function() {
		headline_interval = setInterval(headline_rotate,5000);
		headline_rotate();
	});
	
	$(".list-feed span").bind("mouseenter", function(){
		$(this).addClass('rate-on');
		$(".rate-on").live("click", function setClass(){
			//var msg = 'Ok';		
			//$("div.title_nota span").html(msg).hide().fadeIn(1300);
			//$("ul.star-rating").fadeOut(100);		
			if ($(this).html() == 0) {
				$(".rate-on").toggleClass("negativo-on");
				$("div.title_nota .img_star").attr("src","images/star_1.gif").hide().fadeIn(1000);
				return false;
			}
			if ($(this).html() == 1){
				$(".rate-on").toggleClass("positivo-on");
				$("div.title_nota .img_star").attr("src","images/star_2.gif").hide().fadeIn(1000);
				return false;
			}
		});
	});
	
	$(".list-feed span").bind("mouseleave", function(){
		$(this).removeClass('rate-on');
	});
	
	//clientes btn
	$("a.cliente-link").css("opacity", "0");
	$("a.cliente-link").css("display", "block");	
	$("#lista-clientes").bind("mouseenter", function(){
		$(".clientes-span").fadeTo("slow", 0.4);
		$("a.cliente-link").fadeTo("slow", 1);
    });
	$("#lista-clientes").bind("mouseleave", function(){
		$(".clientes-span").fadeTo("slow", 1);
		$("a.cliente-link").fadeTo("slow", 0);
    });
	
	//section-nav
	$("ul.sec-nav-1 li:last, ul.sec-nav-2 li:last, ul.sec-nav-3 li:last").css("border","none");
	
	//link externo
	$('a.link-ext').click(function(){
		window.open(this.href); 
		return false;
	});
	
	//Abas
	$(function(){
		// oculta todas as abas
		//$("div.contaba").hide();
		// mostra somente  a primeira aba
		$("div.contaba:first").show();
		// seta a primeira aba como selecionada (na lista de abas)
		$(".abas a:first").addClass("selected");
		// quando clicar no link de uma aba
		$(".abas a").click(function(){
			// oculta todas as abas
			$("div.contaba").hide();
			// tira a seleção da aba atual
			$(".abas a").removeClass("selected");
			// adiciona a classe selected na selecionada atualmente
			$(this).addClass("selected");
			// mostra a aba clicada
			$($(this).attr("href")).hide().fadeIn(400);
			// pra nao ir para o link
			return false;
		});
	});
	
	$(".abas-adesao img").css("opacity", "0.3");	
	
	
	

	$(function(){
		$("div.contaba:first").show();
		$(".parcerias-abas a:first").addClass("selected");
		$(".parcerias-abas a").click(function(){
			$("div.contaba").hide();
			$(".parcerias-abas a").removeClass("selected");
			$(this).addClass("selected");
			$($(this).attr("href")).hide().fadeIn(400);
			return false;
		});
	});
	
	
	
	$(".parcerias-abas a:first").addClass("sel-parc");
	$(".p-1").click(function(){
		$(this).addClass("sel-parc");
		$(".p-2, .p-3, .p-4, .p-5, .p-6, .p-7, .p-8").removeClass("sel-parc");
		return false;
	});
	$(".p-2").click(function(){
		$(this).addClass("sel-parc");
		$(".p-1, .p-3, .p-4, .p-5, .p-6, .p-7, .p-8").removeClass("sel-parc");
		return false;
	});
	$(".p-3").click(function(){
		$(this).addClass("sel-parc");
		$(".p-1, .p-2, .p-4, .p-5, .p-6, .p-7, .p-8").removeClass("sel-parc");
		return false;
	});
	$(".p-4").click(function(){
		$(this).addClass("sel-parc");
		$(".p-1, .p-2, .p-3, .p-5, .p-6, .p-7, .p-8").removeClass("sel-parc");
		return false;
	});
	$(".p-5").click(function(){
		$(this).addClass("sel-parc");
		$(".p-1, .p-2, .p-3, .p-4, .p-6, .p-7, .p-8").removeClass("sel-parc");
		return false;
	});
	$(".p-6").click(function(){
		$(this).addClass("sel-parc");
		$(".p-1, .p-2, .p-3, .p-4, .p-5, .p-7, .p-8").removeClass("sel-parc");
		return false;
	});
	$(".p-7").click(function(){
		$(this).addClass("sel-parc");
		$(".p-1, .p-2, .p-3, .p-4, .p-5, .p-6, .p-8").removeClass("sel-parc");
		return false;
	});	
	$(".p-8").click(function(){
		$(this).addClass("sel-parc");
		$(".p-1, .p-2, .p-3, .p-4, .p-5, .p-6, .p-7").removeClass("sel-parc");
		return false;
	});	
	
	//form
	$('#nome').focus(function(){
		if($(this).val() == 'Nome *') {
			$(this).val('');
		}
	});
	$('#nome').blur(function(){
		if($(this).val() == '') {
			$(this).val('Nome *');
		}
	});
	$('#cargo').focus(function(){
		if($(this).val() == 'Cargo') {
			$(this).val('');
		}
	});
	$('#cargo').blur(function(){
		if($(this).val() == '') {
			$(this).val('Cargo');
		}
	});
	$('#empresa').focus(function(){
		if($(this).val() == 'Nome do escritório/empresa *') {
			$(this).val('');
		}
	});
	$('#empresa').blur(function(){
		if($(this).val() == '') {
			$(this).val('Nome do escritório/empresa *');
		}
	});
	$('#telefone').focus(function(){
		if($(this).val() == 'Telefone *') {
			$(this).val('');
		}
	});
	$('#telefone').blur(function(){
		if($(this).val() == '') {
			$(this).val('Telefone *');
		}
	});
	$('#e-mail').focus(function(){
		if($(this).val() == 'E-mail *') {
			$(this).val('');
		}
	});
	$('#e-mail').blur(function(){
		if($(this).val() == '') {
			$(this).val('E-mail *');
		}
	});
	
	//
	$('ul.contato-form input').focus(function(){
		$(this).addClass('select');
	});
	$('ul.contato-form input').blur(function(){
		$(this).removeClass('select');
	});
	
	//form login
	$('#oab').focus(function(){
		if($(this).val() == 'Usuário') {
			$(this).val('');
		}
	});
	$('#oab').blur(function(){
		if($(this).val() == '') {
			$(this).val('Usuário');
		}
	});
	$('#senha').focus(function(){
		if($('form#frm-login label.senha').html() == 'Senha') {
			$('form#frm-login label.senha').hide();

		}
	});
	$('#senha').blur(function(){
		if($(this).val() == '') {
			$('form#frm-login label.senha').show();
		}
	});
	$('#email').focus(function(){
		if($(this).val() == 'Digite seu e-mail') {
			$(this).val('');
		}
	});
	$('#email').blur(function(){
		if($(this).val() == '') {
			$(this).val('Digite seu e-mail');
		}
	});
	$('#l-empresa').focus(function(){
		if($(this).val() == 'Empresa') {
			$(this).val('');
		}
	});
	$('#l-empresa').blur(function(){
		if($(this).val() == '') {
			$(this).val('Empresa');
		}
	});
	
	//esqueceu senha
	$('#lnk-senha').click (function(){
		if ($('.li-hidden').is(':hidden')) {
			$('.li-hidden').slideDown('500');
		}else {
			$('.li-hidden').slideUp('500');
		}
	});
	
	$('.btn-notificador').click ( function(){
	 $('#mensagem-Obrigado').show("slow");
	}	
	);
});
//headline
//noticias
var headline_count;
var headline_interval;
var old_headline = 0;
var current_headline = 0;

function headline_rotate() {
	current_headline = (old_headline + 1) % headline_count;
	$("div.headline:eq(" + old_headline + ")")
	.animate({top: -25},"slow", function() {
	$(this).css('top', '30px');
	});	
	if($.browser.msie){
		$("div.headline:eq("+current_headline+")").animate({top: 3},"slow");
	}else {
	$("div.headline:eq("+current_headline+")").animate({top: 4},"slow");
	}
	old_headline = current_headline;
}

//tooltip
$(function () {
	// options
	var distance = 20;
	var time = 250;
	var hideDelay = 500;
	var hideDelayTimer = null;
	var beingShown = false;
	var shown = false;
	var trigger = $('.trigger', this);
	var popup = $('.popup', this).css('opacity', 0);
	
	$('.trigger, .popup').live('mouseover', function () {	
		if (hideDelayTimer) clearTimeout(hideDelayTimer);
		if (beingShown || shown) {
			return;
		} else {
			beingShown = true;
			$('.popup').css({
				top: -65,
				left: -82,
				display: 'block'
			})
			
			// (we're using chaining on the popup) now animate it's opacity and position
			.animate({
				top: '-=' + distance + 'px',
				opacity: 1
			}, time, 'swing', function() {
				// once the animation is complete, set the tracker variables
				beingShown = false;
				shown = true;
			});
		}
	}).live('mouseout', function () {
		// reset the timer if we get fired again - avoids double animations
		if (hideDelayTimer) clearTimeout(hideDelayTimer);
			// store the timer so that it can be cleared in the mouseover if required
			hideDelayTimer = setTimeout(function () {
				hideDelayTimer = null;
				$('.popup').animate({
					top: '-=' + distance + 'px',
					opacity: 0
				}, time, 'swing', function () {
				// once the animate is complete, set the tracker variables
				shown = false;
				// hide the popup entirely after the effect (opacity alone doesn't do the job)
				$('.popup').css('display', 'none');
			});
		}, hideDelay);
	})
});

function obriga(form)
	 {
      document.getElementById('mensagemErro').style.display = 'none';
	  var elementos = form.elements;
	  var conter = 0;
      for (var i=0;i<elementos.length;i++)
          {
           if (elementos[i].getAttribute("obrigatorio")=="s")
              {
               if (elementos[i].value=="")
                  {
                    elementos[i].style.background = "#f8e9e1";
                    elementos[i].style.border = "1px dashed #FF6A6A";
                    conter++;
                   }
               else
                  {
                    elementos[i].style.border = "1px solid #7f9db9";
                    elementos[i].style.background = "#FFFFFF";
                  }
              }           
          }
	 if(conter == 0)
      {
       return true;
      }
	document.getElementById('mensagemErro').style.display = 'block';	  
    return false;    
    }

function execAjax(loading,programa,formulario,retorno,metodo,botao)
    {
      $(retorno).html("");
	  $(botao).attr('disabled',true);	
      $forms = $(formulario);
      var self = this;
      $.ajax({
              //USA O METODO POST
              type: metodo,
              //URL CARREGADA
              url: programa,
              //TIMEOUT DO PROCESSO
              timeout: 11000,
              //SERIALIZA OS DADOS O FORMULARIO PARA ENVIAR COM AJAX
              data: $forms.serialize(),
              //PROPRIEDADE QUE RECEBE UMA FUNÇÃO PARA SER EXECUTADA APÓS NO MOMENTO DO ENVIO
              beforeSend: function()
			  {
               // EXIBE A MENSAGEM NO MOMENTO DO CARREGAMENTO
               $(loading).show();               
             },
              //PROPRIEDADE QUE RECEBE UMA FUNÇÃO PARA SER EXECUTADA SE O AJAX FOR EXECUTADO COM SUCESSO
             success: function(txt)
			 {
			  $(retorno).html("");
		      $(botao).attr('disabled',false);
              $(loading).hide("slow");	
              $(retorno).html(txt);              
             },
             // PROPRIEDADE QUE RECEBE UMA FUNÇÃO PARA SER EXECUTADA SE O AJAX RETORNAR ERRO
            error: function(txt)
			{
             $(botao).attr('disabled',false);
             $(loading).hide(); 	
             $(retorno).html('erro na solicitação');
            }
         })     
     return true;
    }	
//funcao para validar e-mail

function Mail(str){
  	var valido;
    var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
    if(filter.test(str.value))
      {
      str.value = str.value.toLowerCase();
      valido = true;
    }
 else{      
      str.value = '';
      str.focus();
	  alert("O E-mail informado está incorreto!");  
      valido = false;
    }
    return valido;
  }

//funcao que abre o pop-up
function abrirCaixa(largura,altura,url,nomeJanela) {

//pega a resolução do visitante
w = screen.width;
h = screen.height;

//divide a resolução por 2, obtendo o centro do monitor
meio_w = w/2;
meio_h = h/2;

//diminui o valor da metade da resolução pelo tamanho da janela, fazendo com q ela fique centralizada
altura2 = altura/2;
largura2 = largura/2;
meio1 = meio_h-altura2;
meio2 = meio_w-largura2;
//abre a nova janela, já com a sua devida posição
window.open(url,nomeJanela,'width='+ largura +', height=' + altura + ', top='+meio1+', left='+meio2+'', 'resizable=no', 'location=no');
}

//funcao que abre o pop-up
function abrirAtendimento(largura,altura) {

//pega a resolução do visitante
w = screen.width;
h = screen.height;

//divide a resolução por 2, obtendo o centro do monitor
meio_w = w/2;
meio_h = h/2;

//diminui o valor da metade da resolução pelo tamanho da janela, fazendo com q ela fique centralizada
altura2 = altura/2;
largura2 = largura/2;
meio1 = meio_h-altura2;
meio2 = meio_w-largura2;

//abre a nova janela, já com a sua devida posição
lpButtonCTTUrl = 'http://server.iad.liveperson.net/hc/54666990/?cmd=file&file=visitorWantsToChat&site=54666990&imageUrl=https://liveperson1.locaweb.com.br/teste/imagens&referrer='+escape(document.location); 
lpButtonCTTUrl = (typeof(lpAppendVisitorCookies) != 'undefined' ? lpAppendVisitorCookies(lpButtonCTTUrl) : lpButtonCTTUrl); lpButtonCTTUrl = ((typeof(lpMTag)!='undefined' && typeof(lpMTag.addFirstPartyCookies)!='undefined')?lpMTag.addFirstPartyCookies(lpButtonCTTUrl):lpButtonCTTUrl);
window.open(lpButtonCTTUrl,'','width='+ largura +', height=' + altura + ', top='+meio1+', left='+meio2+'', 'resizable=no', 'location=no');
}
