$(document).ready(function(){
   if($.browser.msie){
	 $("body").addClass("ies");
	 if($.browser.version < 7){
		$("body").addClass("ie");
		$('.fix').ifixpng();
	 }
   }
   
   $pathTheme = $("body").attr("rel");
   $pathDomain = $("body").attr("rel").split("wp-content/themes/shareLGv")[0];
   
   
   $("#formEnquete").validate({ errorContainer: $('#formEnquete .msgError'), errorLabelContainer: $("#formEnquete .msgError"),
		highlight: function(element, errorClass) {
			$name = $(element).attr("name");
			$("input[name='"+ $name +"']").next().addClass("error");
		},
		unhighlight: function(element, errorClass) {
			$name = $(element).attr("name");
			$("input[name='"+ $name +"']").next().removeClass("error");
		},
		submitHandler: function() {
			  $.ajax({
				type: "POST",
				data: $("#formEnquete").serialize(),
				dataType: "json",
				url: $("#formEnquete").attr('action'),
				success: function(json){
				   if(json.msg == "ok"){
						mascaraForm = '<div class="mascaraForm">&nbsp;</div>'
						$('#formEnquete').before(mascaraForm)
						$(".mascaraForm").css("height", $('.content').height()).css("opacity", "0.8")
						$('.alerta-sucesso').fadeIn(300);
					}else{
						$('.alerta-erro').fadeIn(300);
					}
				}
			});
		}
	});
   
   $(".wp-polls-ans label").attr("for", "");
   
   $('h2.titleAmbientada').each(function(){
	 $('body').addClass('ambientada');
   });

   $('#searchform, .boxTagsRss').find('.mask').remove();
   $autocomplete = false;
   $('#searchform #s, #inputRss').keypress(function(){
	 if(!$autocomplete){
	    $this = $(this);
	    $autocomplete = true;
	    $this.parent().find('.contAjaxTagsLoading').fadeIn('fast');
	    $.ajax({
		  url: $pathTheme + '/function-getTags.php',
		  dataType: 'json',
		  success: function($data){
			$tags = new Array();
			$slugs = new Array();
			$tags = $data.tags;
			$slugs = $data.slugs;
			$this.parent().find('.contAjaxTagsLoading').hide();
			autocomplete();
		  }
	    });
	 }
   });

   $('.jcarousel').each(function(){
	 if(!($(this).parents('.boxContent').hasClass('hide'))){
	    $(this).removeClass('hide').jcarousel({ scroll: 1, wrap: 'circular' });
	 }
   });
   
   embedYoutube();
   $('#boxLgYoutube .jcarousel-prev, #boxLgYoutube .jcarousel-next').click(function(){
	 $('#boxLgYoutube ul li .playerYoutube').html('');
	 embedYoutube();
   });
   
   $('ul#listBlogsLg li a').hover(function(){
	 $(this).addClass('hover');
   }, function(){
	 $(this).removeClass('hover');	 
   });
   
   $('ul#listLgIndica li:odd').addClass('odd');
   
   $('.itemSidebar h3').click(function(){
	 $index = $('.itemSidebar h3').index($(this));
	 $cookie = $.cookie('cookieSidebar').split(',');
	 
	 $(this).toggleClass('close');
	 $(this).parent().find('.boxContent').slideToggle();
	 
	 $(this).parent().find('.boxContent.hide').each(function(){
	    $(this).find('.jcarousel').not('.jcarousel-list').removeClass('hide').jcarousel({ scroll: 1, wrap: 'circular' });
	 });
	 
	 if($(this).hasClass('close')){
	    $cookie[$index] = '0';
	 } else {
	    $cookie[$index] = '1';
	 }
	 $.cookie('cookieSidebar', $cookie, { path: '/', expires: 30 });
   });
   
   $verificaClickSelect = false;
   $('#contato a.selectAssunto').click(function(){
	 $(this).toggleClass('open');
	 $('ul.listAssunto').slideToggle('fast');
	 return false;
   });
   $('#contato ul.listAssunto li').hover(function(){
	 $(this).addClass('hover');
   }, function(){
	 $(this).removeClass('hover');
   });
   $('#contato ul.listAssunto li').click(function(){
	 $verificaClickSelect = true;
	 $this = $(this);
	 $('#contato a.selectAssunto').removeClass('open');
	 $('#contato a.selectAssunto span').text($(this).text());
	 $('#contato #assunto').val($(this).attr('rel'));
	 $('a.selectAssunto span').removeClass('error');
	 $('input#assunto').next('label.error').hide();
	 $('#contato ul.listAssunto').slideUp('fast', function(){
	    $verificaClickSelect = false;
	 });
   });
   $('body').click(function(){
	 if(!($verificaClickSelect)){
	    $('#contato a.selectAssunto').removeClass('open');
	    $('#contato ul.listAssunto').slideUp('fast', function(){
		  $verificaClickSelect = false;
	    });
	 }
   });
   
   $('#resultBusca .boxOrdenar a').click(function(){
	 $(this).toggleClass('open');
	 $('ul.listSelect').slideToggle('fast');
	 return false;
   });
   $('ul.listSelect li').hover(function(){
	 $(this).addClass('hover');
   }, function(){
	 $(this).removeClass('hover');
   });
   $('ul.listSelect li').click(function(){
	 $this = $(this);
	 $('#resultBusca .boxOrdenar a').removeClass('open');
	 $('#resultBusca .boxOrdenar a span').text($(this).text());
	 $('ul.listSelect').slideUp('fast', function(){
	    if($(document).getUrlParam('s')){
		  window.location = '?s=' + $(document).getUrlParam('s') + '&order=' + $this.attr('rel');
	    } else {
		  window.location = "?order=" + $this.attr('rel');
	    }
	 });
   });   
   
   $('a.btnSelecioneTag').click(function(){
	 if($(this).attr('href') == '#'){
	    return false;
	 }
   });
   
   validaFormComment('.commentform');
   
   $('.form').live("focus", function(){
	    $(this).addClass('formFont'); 
   });
   $('.form').live("blur", function(){
	 $(this).removeClass('formFont');
   });
   
   
   $('ul.tags').each(function(){
	 $(this).find('li:last').addClass('last');
   });
    
   $('.post .content img.alignleft').attr('align', 'left');
   $('.post .content img.alignright').attr('align', 'right');
    
   $('a').click(function(){
	 $(this).blur();
   });
   
   $('a.btnPreencha').live('click', function(){
	 $(this).toggleClass('hover');
	 $('.boxPreencha').slideToggle();
	 return false;
   });
   
   $('.boxLogin input.form').live('keypress', function(e){
	 $code =  e.keyCode ? e.keyCode : e.which;
	 if($code == '13'){
	    $(this).parent().find('a.btnLogar').click();
	    return false;
	 }
   });   
   
   $('ul#listDiretoPonto li').each(function(){
	 $width = eval($(this).find('.title .left').width() + $(this).find('.title .right').outerWidth() + 2);
	 $marginLeft = parseInt($width / 2);
	 $(this).find('.title').width($width).css({ 'margin-left': -$marginLeft });
	 $(this).find('.title').addClass('show').hide();
   });
  
   $('ul#listDiretoPonto li a').hoverIntent(function(){
	 $('ul#listDiretoPonto li span.title').hide();
	 $(this).parent().find('span.title').css({ 'display': 'block'}).hide().fadeIn('slow');
   }, function(){
	 $('ul#listDiretoPonto li span.title').fadeOut('fast');
   });
   if(!($('body').hasClass('ie'))){
	 $('ul#listFontSize li a.click').fadeTo(1, 0.4);
   }
   
   $('ul#listFontSize li a').click(function(){
	 if($(this).hasClass('click')){
	    return false;
	 } else {
	    if($(this).hasClass('btnFontMin')){
		  $size = $('a.btnFontDefault').hasClass('click') ? -2 : -4;
	    } else if($(this).hasClass('btnFontDefault')) {
		  $size = $('a.btnFontMin').hasClass('click') ? 2 : -2;
	    } else {
		  $size = $('a.btnFontDefault').hasClass('click') ? 2 : 4;
	    }
	    if(!($('body').hasClass('ie'))){
		  $('ul#listFontSize li a').fadeTo(1, 1.0).removeClass('click');
		  $(this).fadeTo(800, 0.4).addClass('click');
	    } else {
		  $('ul#listFontSize li a').removeClass('click');
		  $(this).addClass('click');
	    }
	    
	    $('p, h2, h3, h4, span, strong, a').each(function(){
		  $(this).css({ 'font-size': parseInt($(this).css('font-size')) + $size + 'px' });
	    });
	    return false;
	 }
   });
   
   spanTotalPosition();
   
   $('a.btnEnviarFormContato').click(function(){
	 if($('#contato #assunto').val() == '' || $('#contato #assunto').val() == 'Escolha'){
	    $('a.selectAssunto span').addClass('error');
	 }
   });
   
   $('a.btnSubmitForm, a.btnEnviarFormContato').click(function(){
	 $(this).parents('form').submit();
	 return false;
   });
   
   $('a.btnEnviarFormColab').click(function(){
	 if(!($('.rowAutorizacao input.check').attr('checked'))){
	    $('.rowAutorizacao label.check').addClass('errorAut');
	 }
	 
	 if($('.rowTxtFluid > textarea.txtVideo').val() == $('.rowTxtFluid > textarea.txtVideo').attr('title')){
	    $('.rowTxtFluid > textarea.txtVideo').val('');
	 }

	 $(this).parents('form').submit();
	 return false;
   });
   
   $('.rowAutorizacao label').click(function(){
	 $('.rowAutorizacao label.error').remove();
   });
   
   $verify = false;
   $('#colaboracao .txtItemOnly, #colaboracao .txtDescOnly').bind('blur', function(){
	    $thisLength = $(this).val().length;
	    if($(this).hasClass('txtItemOnly')){
		  $otherLength = $(this).parent().parent().find('.txtDescOnly').val().length;
		  $thisValid = !($(this).hasClass('error')) && !($(this).parent().parent().find('.txtDescOnly').hasClass('error')) && $thisLength && $otherLength;
	    } else if($(this).hasClass('txtDescOnly')){
		  $otherLength = $(this).parent().parent().find('.txtItemOnly').val().length;		  
		  $thisValid = !($(this).hasClass('error')) && !($(this).parent().parent().find('.txtItemOnly').hasClass('error')) && $thisLength && $otherLength;
	    }
	    if($thisValid){
		  $('.txtItemOnly, .txtDescOnly').removeClass('required error').addClass('valid');
		  $('.video label.error, .imagem label.error, .texto label.error').remove();
	    } else {
		  $('.video, .imagem, .texto').each(function(){
			if(!($(this).find('.txtItemOnly').hasClass('error')) && !($(this).find('.txtDescOnly').hasClass('error'))){
			   $verify = true;
			}
		  });
		  if(!$verify){
			$('.txtItemOnly, .txtDescOnly').addClass('required');
		  }
	    }
   });
   
   $('#formEmail').validate({
	 messages: {
	    nome: 'Preencha seu nome',
	    email: 'Preencha seu e-mail',
	    nomeAmigo: 'Preencha o nome do destinatário',
	    emailAmigo: 'Preencha o e-mai do destinatário'
	 },
	 submitHandler: function() {
	    $url = $('#formEmail').attr('action');
	    $nomeAmigo = $('#inputNomeAmigo').val();
	    $('#formEmail').find('.contentForm').hide();
	    $('#formEmail').find('.innerEnviando').fadeIn('fast');
	    $waitTime = setTimeout(function(){
		  $.ajax({
			data: $('#formEmail').serialize(),
			type: "POST",
			dataType: "json",
			url: $url,
			success: function(json) {
			   if(json.msg == "ok"){
				  $('#formEmail').find('.innerEnviando').hide();
				  $('#formEmail form, #formEmail textarea').val('');
				  $('#formEmail').find('.innerEnviado p span').text($nomeAmigo);
				  $('#formEmail').find('.innerEnviado').fadeIn();
			   } else {
				  $('#formEmail').find('.innerEnviando').hide();
				  $('#formEmail').find('.innerErro').fadeIn();
			   }
			}
		  });
	    }, 1000);	  
	 }
   });
   
   $("#formContato").validate({
	    messages:{
		    nome: "* Por favor, verifique se seus dados estão preenchidos corretamente.",
		    email: "* Por favor, informe um e-mail válido.",
		    assunto: "* Informe o assunto da mensagem aqui.",
		    mensagem: "* Escreva sua mensagem aqui."
	    },
	    submitHandler: function() {
		  tb_show('', '#TB_inline?height=200&width=406&inlineId=tbEnviando&modal=false', false);
		  $wait = setTimeout(function(){
			$.ajax({
			   type: "POST",
			   data: $("#formContato").serialize(),
			   dataType: "json",
			   url: $pathTheme + "/contatoform.php",
			   success: function(json){
				   if(json.msg == "true"){
					  $('.ajaxEnviando .inner').hide();
					  $('.ajaxEnviando .innerEnviado').fadeIn();
					  $('form').each(function(){
						this.reset();
					  });
					  $('a.selectAssunto span').text('Escolha');
				    } else {
					  $('.ajaxEnviando .inner').hide();
					  $('.ajaxEnviando .innerErro').fadeIn();
				    }
			    }
			});
		  }, 1000);
	 }
    });
   
   $("#formColaboracao").validate({
	    messages:{
		    nome: "* Por favor, verifique se seus dados estão preenchidos corretamente.",
		    email: "* Por favor informe um e-mail válido.",
		    url: "* Informe o endereço correto.",
		    "video[0]": "Verifique se voc&ecirc; inseriu a URL corretamente.",
		    descricaovideo: "* Escreva sua mensagem aqui.",
		    "img[0]": "* Insira o link das imagens aqui.",
		    descricaoimg: "* Escreva sua mensagem aqui.",
		    assuntoMatEscrita: "* Preencha aqui.",
		    mensagemMatEscrita: "* Escreva sua mensagem aqui.",
		    autorizacao: ""
	    },
	    submitHandler: function() {
		  tb_show('', '#TB_inline?height=200&width=406&inlineId=tbEnviando&modal=false', false);
		  $waitColab = setTimeout(function(){
			$.ajax({
			   type: "POST",
			   data: $("#formColaboracao").serialize(),
			   dataType: "json",
			   url: $pathTheme + "/contatoform.php",
			   success: function(json){
				   if(json.msg == "true"){
					  $('.ajaxEnviando .inner').hide();
					  $('.ajaxEnviando .innerEnviado').fadeIn();
					  $('form').each(function(){
						this.reset();
					  });
					  $('a.selectAssunto span').text('Escolha');
				    } else {
					  $('.ajaxEnviando .inner').hide();
					  $('.ajaxEnviando .innerErro').fadeIn();
				    }
			    }
			});
		  }, 1000);
	    }
    });
   
   $('#boxLgYoutube ul.listBoxYoutube li a').hover(function(){
	 $(this).find('h4, p').css({ 'text-decoration': 'underline' });
   }, function(){
	 $(this).find('h4, p').css({ 'text-decoration': 'none' });
   });
   
   $('ul#listMais li a').click(function(){
	$('ul#listMais li a').removeClass('hover');
	$(this).addClass('hover');
	$('#itensMais .boxItem').hide();
	$('#itensMais ' + $(this).attr('href')).show();
	spanTotalPosition();
	return false;
   });

   $('#boxArquivo ul li a.disable').attr('href', '#').parent().fadeTo(1, 0.4).end().click(function(){
	 return false;
   });
    
   $('#boxArquivo ul').each(function(){
	 $(this).find('li:last').addClass('last');
   })

   $('a.btnMaisTags').click(function(){
	 $(this).toggleClass('btnMaisTagsOpen');
	 $('#boxTodasTags').slideToggle('normal');
	 return false;
   });
   
   $(".termosDeUtilizacaoDeMateriais").click(function(){
	 tb_show('', '/wp-content/themes/shareLGv2/tb/termosDeUtilizacaoDeMateriais.php?keepThis=true&TB_iframe=true&width=420&height=218', false);
	 return false;
   });
   
   $timerBanner = setInterval(timerBanner, 8000);
   
   $clickDestaque = false;
   $('ul#listExp li a').click(function(){
	if(!($(this).hasClass('hover'))){
	    $exibir = $(this).attr('href').split('#')[1];
	    if(!($(this).hasClass('animate'))){
		  clearInterval($timerBanner);
		  $clickDestaque = true;
	    }
	    $('ul#listExp li a').removeClass('hover');
	    $(this).addClass('hover');
	    $('#postDestaque .postDestaque').hide();
	    $('#postDestaque .' + $exibir).fadeIn('slow');
	}
	return false;
   });
   
   $('#postDestaque').mouseenter(function(){
	 clearInterval($timerBanner);
   }).mouseleave(function(){
	 if(!$clickDestaque){
	    clearInterval($timerBanner);
	    $timerBanner = setInterval(timerBanner, 8000);
	 }	 
   });
   
   $('span.btnQuestion').hoverIntent(function(){
	 $('.boxQuestion').fadeIn('slow');
   }, function(){
	 $('.boxQuestion').fadeOut('fast');
   });
   
   $('.boxQuestion').mouseover(function(){
	 $(this).stop().fadeTo(1, '1.0');
   });
   $('.boxQuestion').mouseout(function(){
	 $(this).fadeOut('fast');
   });
      
   $('.wp-polls-ul li input[type="radio"]').addClass('radio');
   $('.wp-polls-ul li input[type="checkbox"]').addClass('check');
   $('.formulario-enquete input[type="radio"]').next().addClass('radio');
   $('.formulario-enquete input[type="checkbox"]').next().addClass('check');
   $('.formulario-enquete input[type="text"]').addClass('text');
   $('.formulario-enquete input[type="submit"]').addClass('submit');
   $(".formulario-enquete .botao").css("width", $(".formulario-enquete .botao").width() + 36 + "px")
   
   $('.txtComment').live("keypress", function(){
	 limitChars($(this), 1000, $(this).parent().find('.cont'));
   });
   
   $('#txtComentario').live("keypress", function(){
	 limitChars($(this), 1000, $(this).parent().find('.cont'));
   });
   
   $('a.icoEmail').live("click", function(){
	 $('#formEmail .innerEnviando, #formEmail .innerEnviado, #formEmail .innerErro').hide('');
	 $('#formEmail .contentForm').show();
	 $('#formEmail .form').val('').removeClass('error');
	 $('#formEmail label.error').remove();
	 $('#formEmail .cont').html('1000');
	  
	 $postId = $(this).attr('href').split('#')[1];
	 $btnGmail = $(this).parents('.contentBot').find('a.icoGmail').clone();
	 $btnYahoo = $(this).parents('.contentBot').find('a.icoYahoo').clone();;
	 $btnWindowsLive = $(this).parents('.contentBot').find('a.icoWindowsLive').clone();;
	 $btnTwitter = $(this).parents('.contentBot').find('a.icoTwitter').clone();
	 
	 tb_show('', '#TB_inline?height=508&width=340&inlineId=tbEmail&modal=false', false);
	 $('.boxEmail #postId').val($postId);
	 $('.listBookEmail').html($btnGmail).append($btnYahoo).append($btnWindowsLive).append($btnTwitter);
	 $('.boxEmail .form:first').focus();
	   
	 return false;
   });
   
   $('a.btnFecharLoadingCaptcha').click(function(){
	 $('input#captcha_code.error').focus();
   });
   
   $('input#captcha_code').live('keyup', function(){
	 $('input#captcha_code').val($('input#captcha_code').val().toLowerCase());
   });
   
   $('a.btnFecharTb, a#btnCancelar, a.btnFecharLoading').click(function(){
	 return false;
   });
   
   /* Checkbox e radio personalizados 
   $('div:not(.formulario-enquete) input[type="checkbox"], div:not(.formulario-enquete) input[type="radio"]').each(function(){
	   $(this).hasClass('check') ? $(this).next().addClass('check') : $(this).next().addClass('radio');
	   if($(this).attr('checked')){
		   $(this).next().addClass('selected');
	   }
   });*/
   
   $('label.check, label.radio').live("mouseover", function(){
	 $('label').removeClass('hover');
	 $(this).addClass('hover');
   });
   $('label.check, label.radio').live("mouseout", function(){
	 $('label').removeClass('hover');
   });
   /*$('label.check, label.radio').live("click", function(){
	 if($(this).hasClass('radio')){
	    $(this).parents('form').find('label.radio').removeClass('selected');
	 }
	 if($(this).prev().attr('checked') && !($(this).hasClass('radio'))){
	    $(this).removeClass('selected').prev().click();
	 }
	 else{
	    $(this).addClass('selected').removeClass('error').prev().click();
	 }
	 return false;
   });*/
   
   $('a.btnInfoContato').click(function(){
	 $(this).next().fadeIn();
	 return false;
   });
   
   $('a.btnFecharInfo').click(function(){
	 $(this).parent().fadeOut('fast');
	 return false;
   });
   
   $('.radioContato').click(function(){
	 $('#colaboracao').hide();
	 $('#contato').fadeIn();
   });
   
   $('.radioColab').click(function(){
	 $('#contato').hide();
	 $('#colaboracao').fadeIn();
   });
   
   $('.radioIdadeSim').click(function(){
	 $('#pageContato p.preenchaDados').removeClass('errorIdade');
	 $('#colaboracao .form, #colaboracao .input').each(function(){
	    $(this).attr('disabled', false);
	 });
	 $('.boxContentColab').fadeTo('normal', 1.0, function(){
	    $('.boxContentColab').addClass('show');
	 });
   });
   
   $('.radioIdadeNao').click(function(){
	 $('#pageContato p.preenchaDados').addClass('errorIdade');
	 $('#colaboracao .form, #colaboracao .input').each(function(){
	    $(this).attr('disabled', true);
	    $(this).removeClass('error');
	    $('#colaboracao label.error').hide();
	 });
	 $('.boxContentColab').fadeTo('normal', 0.5, function(){
	    $('.boxContentColab').removeClass('show');
	 });
   });
   
   $('#colaboracao').each(function(){
	 if($('.radioIdadeSim').hasClass('selected')){
	    $('.boxContentColab').addClass('show');
	 }
   });
   
   $('.txtVideo').live('focus', function(){
	 if($(this).text() == $(this).attr('title')){
	    $(this).text('');
	 }
   }).live('blur', function(){
	 if($.trim($(this).text()) == ''){
	    $(this).text($(this).attr('title'));
	 }
   });
   
   $('a.addItem').click(function(){
	 $obj = $(this).parent().find('.itemClone .inputClone').clone();
	 $(this).before($obj).prev().hide().fadeIn();
	 $(this).before('<br />');
	 $name = $obj.attr('id').split('[')[0];
	 $index = $obj.attr('id').split('[')[1].split(']')[0];
	 if($index >= 4){
	    $(this).hide();
	    return false;
	 }
	 $index++;
	 $(this).parent().find('.itemClone .inputClone').attr('id', $name + '[' + $index + ']').attr('name', $name + '[' + $index + ']');
	 return false;
   });
   
   $('a.icoFavoritos').click(function(){
	 $param = $(this).attr('rel').split('|');
	 addFavoritos($param[0], $param[1]);
	 return false;
   });
   
   $('.boxDeixeComentarioOrigin .hideCommentCaptcha').each(function(){
	 $logado = $('.userLogado').val();	 
	 if(!$logado){
	    $imgCaptcha = $(this).find('#si_image_com').clone();
	    $changeImgCaptcha = $(this).find('img[alt="Reapresentar imagem"]').parent().clone();
	    $inputCaptcha = $(this).find('#captcha_code').clone();
	    $(this).html('<div class="boxImgCaptcha"></div><div class="boxInputCaptcha"><label for="captcha_code">Código de segurança (obrigatório)</div>');
	    $(this).find('.boxImgCaptcha').append($imgCaptcha);
	    $(this).find('.boxImgCaptcha').append($changeImgCaptcha);
	    $(this).find('.boxInputCaptcha').prepend($inputCaptcha);
	    $(this).find('.boxInputCaptcha input').addClass('required {maxlength: 4, minlength: 4}').attr('maxlength', 4);
	    $(this).show();    
	 }	 
   });
   
   $('a.comentarComment').click(function(){
	 $this = $(this);
	 $logado = $('.userLogado').val();

	 if($this.hasClass('open')){
	    $this.parents('.comment').find('.boxDeixeComentario').slideUp('normal', function(){
		  //$this.parents('.comment').find('.boxDeixeComentario').remove();
		  $this.parents('.content').find('.bot').removeClass('openBot');
	    });
	 } else {	    
	    if(!$logado){
		  $cloneCaptcha = $('.captchaOpen .bot').find('.hideCommentCaptcha').clone();
		  $('.captchaOpen .bot').find('.hideCommentCaptcha').remove();
		  $('.captchaOpen .bot').prepend($('#boxCaptchaOpt').html());
		  $('.captchaOpen').removeClass('captchaOpen');
		  
		  $('.boxDeixeComentarioOrigin').removeClass('captchaOpen');
		  
		  $verificaCaptcha = false;
		  $('.boxDeixeComentario').each(function(){
			if($(this).hasClass('.captchaOpen')){
			   $verificaCaptcha = true;
			}
		  });
		  
		  if(!$verificaCaptcha){
			$this.parents('.comment').find('.cloneComentario').addClass('captchaOpen');
		  }
	    }	    
	    if(!($this.hasClass('hasForm'))){
		  $formComment = $('#cloneComentario .cloneComentario').clone();
		  $commentParent = $this.parents('li.comment').attr('id').split('-')[2];
		  $($formComment).find('.comment_parent').val($commentParent);
		  $($formComment).find('form').attr('id', $($formComment).find('form').attr('id') + $commentParent);
		  $($formComment).find('label').each(function(){
			$(this).attr('for', $(this).attr('for') + $commentParent);
		  });
		  $($formComment).find('.form').each(function(){
			$(this).attr('id', $(this).attr('id') + $commentParent);
		  });
		  $(this).parents('.content').find('.bot').addClass('openBot');
		  $(this).parents('.comment').append($formComment);
		  $(this).parents('.comment').find('.cloneComentario').hide().slideDown(1000);
		  $(this).parents('.comment').find('.cloneComentario .bot .hideCommentCaptcha').remove();
		  if(!$logado){
			$(this).parents('.comment').find('.cloneComentario .bot').prepend($cloneCaptcha);
		  }
		  $(this).parents('.comment').find('.cloneComentario').addClass('captchaOpen');
   
		  validaFormComment('#commentformResp' + $commentParent);
		  $('.hint').hint();
	    } else {
		  $(this).parents('.comment').find('.cloneComentario').hide().slideDown(1000);
		  validaFormComment('#commentformResp' + $commentParent);
		  $('.hint').hint();
	    }
	 }
	 $(this).toggleClass('open').addClass('hasForm');

	 return false;
   });
   
   $('.boxDeixeComentario').live('mouseenter', function(){
	if(!($(this).hasClass('captchaOpen'))){
	    $logado = $('.userLogado').val();
	    if(!$logado){
		  $cloneCaptcha = $('.captchaOpen .bot').find('.hideCommentCaptcha').clone();
		  $('.captchaOpen .bot').find('.hideCommentCaptcha').remove();
		  $('.captchaOpen .bot').prepend($('#boxCaptchaOpt').html());
		  $('.captchaOpen').removeClass('captchaOpen');
		  $(this).addClass('captchaOpen');
		  $(this).find('.bot .hideCommentCaptcha').remove();
		  $(this).find('.bot').prepend($cloneCaptcha);
	    }
	 }
   });
   
   $('.navigation a, .navigation span.current').each(function(){
	 if($(this).text() >= 1 && $(this).text() <= 9){
	    $(this).text('0' + $(this).text());
	 }   
   });
   $('.navigation').css({ 'display': 'block' });   
   
   $('.rpx_comment_hint').css({ 'visibility': 'visible' });
   if($.cookie('cookieLGlogin')){
	 $validaForm = $('#validaForm').val();
	 validaFormComment($validaForm);
	 $.cookie('cookieLGlogin', null);
   }
   
   $('.cloneComentario a.rpxnow').live('click', function(){
	 $localId = $(this).parents('form').attr('id').split('commentformResp')[1];
	 $.cookie('cookieLGlogin', $localId);
	 $index = $(this).parent().find('a').index($(this));
	 $('.boxDeixeComentarioOrigin .rpx_comment_hint a:eq(' + $index + ')').click();
	 return false;
   });
   $('a.rpxnow').click(function(){
	 $defaultService = $(this).attr('rel');
	 RPXNOW.default_provider = $defaultService;
   });
   
   
  $(".ddd").mask("999");
  $(".telefone").mask("9999-9999");
  $('.hint').hint();

  // Page Enquete
	$("label.error").live("click", function(){
            $(this).closest("ul").find("label").removeClass("error");
        });
        
        
	$(".restricao4").click(function(){
		$(this).closest("ul").find("label").removeClass("selected");
		$(this).closest("li").find("label").addClass("selected");
		$('.formulario-enquete > li').find("input.requiredField").addClass("required");
		if($(this).closest("li").find(":radio").val() == "sim") {
			$(".mascaraCampo").remove()
			$($('.formulario-enquete > li')[12-1]).append(mascaraCampo).find("input.requiredField").removeClass("required").next().removeClass("error");
			$($('.formulario-enquete > li')[13-1]).append(mascaraCampo).find("input.requiredField").removeClass("required").next().removeClass("error");
	
		} else if ($(this).closest("li").find(":radio").val() == "nao") {
			$(".mascaraCampo").remove()
			//desabilita as perguntas 5, 6, 7, 8, 9, e 10
			$($('.formulario-enquete > li')[5-1]).append(mascaraCampo).find("input.requiredField").removeClass("required").next().removeClass("error");
			$($('.formulario-enquete > li')[6-1]).append(mascaraCampo).find("input.requiredField").removeClass("required").next().removeClass("error");
			$($('.formulario-enquete > li')[7-1]).append(mascaraCampo).find("input.requiredField").removeClass("required").next().removeClass("error");
			$($('.formulario-enquete > li')[8-1]).append(mascaraCampo).find("input.requiredField").removeClass("required").next().removeClass("error");
			$($('.formulario-enquete > li')[9-1]).append(mascaraCampo).find("input.requiredField").removeClass("required").next().removeClass("error");
			$($('.formulario-enquete > li')[10-1]).append(mascaraCampo).find("input.requiredField").removeClass("required").next().removeClass("error");
		}
	});
	
	$("input[name='gostariaSerBlogueiro'], input[name='gostariaSerBlogueiro'] + label").click(function(){
		$val = ($(this).attr("name") != undefined) ? $(this).val() : $(this).prev().val();
		if($val == 'Sim'){
			$("input[name='gostariaSerBlogueiroOutra']").attr("disabled", "").focus();
		}else{
			$("input[name='gostariaSerBlogueiroOutra']").attr("disabled", "disabled");
		}
	});

         $("input.outra").click(function(){
            $(this).prev().prev().attr("checked","checked");
         });

         $("input + label").click(function() {
            if ($(this).prev().attr("type") == 'checkbox') {
               ($(this).prev().is(":checked")) ? $(this).removeClass("selected").prev().attr("checked", false) : $(this).addClass("selected").prev().attr("checked", true);
            } else {
               $(this).addClass("selected").prev().attr("checked", true);
            }
         });

});

var mascaraCampo = '<div class="mascaraCampo">&nbsp;</div>';

function ativaLabel(el) {
	$(el).find("label").addClass("ativo")
}
function desativaLabel(el) {
	$(el).find("label").removeClass("ativo")
}

function autocomplete(){
   // Busca com autocomplete
   $string = '';
   $contTop = 0;
   $contDown = 0;
   $('#searchform').submit(function(){
	 return false;
   });
   
   $('#searchform #s, #inputRss').each(function(){
	 carregaResults($(this));
   });
   
   $('#searchform #s, #inputRss').keyup(function(e){
	$this = $(this);
	$code =  e.keyCode ? e.keyCode : e.which;
	if($code != 13 && ($code < '37' || $code > '40')){
	    carregaResults($this);
	} else if($code == '40' && $this.parent().find('.contAjaxTags').is(':visible')){
	    if($this.parent().find('.ajaxTags li').hasClass('hover')){
		$contTop = 0;
		if(!($this.parent().find('.ajaxTags li:last').hasClass('hover'))){
		    $this.parent().find('.ajaxTags li.hover').removeClass('hover').next().addClass('hover');
		    if(++$contDown > 4){
			   $this.parent().find('.ajaxTags')[0].scrollBy(24);
		    }
		}
	    } else {
		  $this.parent().find('.ajaxTags li:first').addClass('hover');
	    }
	} else if($code == '38' && $this.parent().find('.contAjaxTags').is(':visible')){
	    if($this.parent().find('.ajaxTags li').hasClass('hover')){
		  $contDown = 0;
		  if(!($this.parent().find('.ajaxTags li:first').hasClass('hover'))){
			 $this.parent().find('.ajaxTags li.hover').removeClass('hover').prev().addClass('hover');
			 if(++$contTop > 4){
				$this.parent().find('.ajaxTags')[0].scrollBy(-24);
			 }
		  }
	    }
	} else if($code == '13'){
	    if($this.parent().find('.contAjaxTags').is(':visible') && $this.parent().find('.contAjaxTags li').hasClass('hover')){
		  $this.val($this.parent().find('.ajaxTags li.hover').text());
		  $this.parent().find('ul.ajaxTags').html('').parents('.contAjaxTags').fadeOut();
		  if($this.parent().hasClass('boxTagsRss')){
		    modificaLinkRss();
		  }
	    } else {
		$this.parent().find('.submitSearch').click();
	    }
	}
   });
   
    $('ul.ajaxTags li').live('mouseover', function(){
	 $(this).parents('.contAjaxTags').find('ul.ajaxTags li').removeClass('hover');
	 $(this).addClass('hover');
    });
    $('ul.ajaxTags li').live('click', function(){
	 $(this).parents('.contAjaxTags').parent().find('input.form').val($(this).text());
	 if($(this).parents('.contAjaxTags').parent().hasClass('boxTagsRss')){
	    modificaLinkRss();
	 }
	 $(this).parents('ul.ajaxTags').html('').parents('.contAjaxTags').fadeOut();
    });
   
    $('.submitSearch').click(function(){
	 $slug = false;
	 $string = $.trim($(this).parent().find('.form').val().toLowerCase());
	 $string = convertString($string);
	 $($slugs).each(function($index){
		if($string == $slugs[$index]){
		  $slug = $slugs[$index];
		}
	 });
	 if($(this).parent().attr('id') == 'searchform'){
		if($slug){
		    window.location = "/tag/" + $slug + "/";
		} else {
		    window.location = "/?s=" + $('#searchform #s').val();
		}
	 }
   });
    $verificaClick = true;
    $('body').click(function(){
	$hide = setTimeout(function(){
	    $verificaClick = true;
	}, 400)
	if($verificaClick){
	    $('ul.ajaxTags').html('').parents('.contAjaxTags').fadeOut();
	}
    });
    
    $('.contAjaxTags').click(function(){
	$verificaClick = false;
    });
   // Busca com autocomplete
}

function carregaResults($this){
   $results = '';
   $string = $.trim($this.val().toLowerCase());
   if($this.parent().hasClass('boxTagsRss')){
	 modificaLinkRss();
   };
   if($string != ''){
	 $string = convertString($string);
	 $stringLenght = $string.length;		
	 for($index in $slugs){
		if($string == $slugs[$index].substring(0, $stringLenght)){
		 $item = '<li><strong>' + $tags[$index].substring(0, $stringLenght) + '</strong>' + $tags[$index].substring($stringLenght) + '</li>';
		 $results +=  $item;
		}
	 }
	 if($results == ''){
		  $this.parent().find('.ajaxTags').html('').parents('.contAjaxTags').fadeOut('fast');
	 } else {
		 $this.parent().find('.ajaxTags').html($results).parents('.contAjaxTags').fadeIn('fast');
		 $numItem = $this.parent().find('.ajaxTags li').size();
		 if($numItem == 1){
		    $this.parent().find('.contAjaxTags').height('32px');
		    $this.parent().find('.ajaxTags').jScrollPaneRemove();
		 } else if($numItem == 2){
		    $this.parent().find('.contAjaxTags').height('60px');
		    $this.parent().find('.ajaxTags').jScrollPaneRemove();
		 } else if($numItem == 3){
		    $this.parent().find('.contAjaxTags').height('82px');
		    $this.parent().find('.ajaxTags').jScrollPaneRemove();
		 } else if($numItem == 4){
		    $this.parent().find('.contAjaxTags').height('116px');
		    $this.parent().find('.ajaxTags').jScrollPaneRemove();
		 } else if($numItem == 5){
		    $this.parent().find('.contAjaxTags').height('130px');
		    $this.parent().find('.ajaxTags').jScrollPaneRemove();
		 } else {
		    $this.parent().find('.contAjaxTags').height('154px');
		    $this.parent().find('.ajaxTags').jScrollPane({ scrollbarWidth: 12, scrollbarMargin: 0, animateTo: true, showArrows: true });
		 }
	 }
   } else {
    $this.parent().find('.ajaxTags').html('').parents('.contAjaxTags').fadeOut('fast');
   }
}

function modificaLinkRss(){
   $slug = false;
   $string = $.trim($('#inputRss').val().toLowerCase());
   $string = convertString($string);
   $($slugs).each(function($index){
	 if($string == $slugs[$index]){
	   $slug = $slugs[$index];
	 }
   });
   if($slug){
	 $('a.btnSelecioneTag').attr('href', '/tag/' + $slug + '/feed/');
   } else {
	 $('a.btnSelecioneTag').attr('href', '#');
   }
}

function convertString($string){
    $string = $string.replace(/[!\/:-?[-_]/g, '');
    $string = $string.replace(/^-/, '');
    $string = $string.replace(/-$/, '');
    $string = $string.replace(/\s{1,}/g, '-');
    $string = $string.replace(/[@à-æ]/g, 'a');
    $string = $string.replace(/[è-ë]/g, 'e');
    $string = $string.replace(/[ì-ï]/g, 'i');
    $string = $string.replace(/[ò-ö]/g, 'o');
    $string = $string.replace(/[ù-ü]/g, 'u');
    $string = $string.replace('ç', 'c');
    $string = $string.replace('#', '');
    return $string;
}

function spanTotalPosition(){
   
   $('#itensMais .itens').each(function(){
	 $index = $('#itensMais .itens').index($(this));
	$right = parseInt($(this).find('.total').width() / 2);
	if($index == 4 || $index == 9 || $index == 14){
	    $right = eval($right + 6);
	}
	$(this).find('.total').css({ 'right': -$right + 'px' });
   });
}

function embedYoutube(){
   $('#boxLgYoutube ul li').each(function(){
	 $srcVideo = 'http://www.youtube.com/v/' + $(this).find('.playerYoutube').attr('rel') + '&hl=pt_BR&fs=1&rel=0';
	 $(this).find('.playerYoutube').flash({ width: 271, height: 186, wmode: 'transparent', allowFullScreen: 'true', allowscriptaccess: 'always' }, { version: 9 },
	    function(htmlOptions){
		  $this = $(this);
		  htmlOptions.src = $srcVideo;
            $this.html($.fn.flash.transform(htmlOptions));
      });
   });
}

function addFavoritos($url, $title){
   if (window.sidebar){
	   window.sidebar.addPanel($title, $url, "");
   }
   else if(window.opera && window.print){
	   var elem = document.createElement('a');
	   elem.setAttribute('href',$url);
	   elem.setAttribute('title',$title);
	   elem.setAttribute('rel','sidebar');
	   elem.click();
   } 
   else if(document.all){// ie
	   window.external.AddFavorite($url,$title);
   } else {
	 alert('Por favor, pressione CTRL-D para adicionar o post aos seus favoritos.');
   };
}

function limitChars(textid, limit, infodiv) {
    var text = $(textid).val();
    var textlength = text.length;
    $(textid).removeClass("error");
    if (textlength > limit) {
        infodiv.html('0');
        $(textid).val(text.substr(0, limit));
        return false;
    } else {
        infodiv.html((limit - textlength));
        return true;
    }
}

function validaFormComment($form){
   $($form).each(function(){
	 $this = $(this);
	 $(this).validate({
	    messages: {
		  inputNome: '* Preencha seu nome',
		  inputEmail: '* Preencha seu e-mail',
		  comment: '* Escreva seu comentário'
	    },
	    submitHandler: function() {
		  $url = $this.attr('action');
		  $('.ajaxEnviando .innerEnviado, .ajaxEnviando .innerErro, .ajaxEnviando .innerErroCaptcha').hide();
		  $('.ajaxEnviando .inner').show();
		  tb_show('', '#TB_inline?height=200&width=406&inlineId=tbEnviando&modal=false', false);
		  $waitTime = setTimeout(function(){
			json = '';
			$.ajax({
			   data: $this.serialize(),
			   type: "POST",
			   dataType: "json",
			   url: $url,
			   success: function(json) {
				 if(json.msg == "ok"){
				     $('.ajaxEnviando .inner, .ajaxEnviando .innerErro, .ajaxEnviando .innerErroCaptcha').hide();
					$('.ajaxEnviando .innerEnviado').fadeIn();
					$('.boxImgCaptcha a').click();
					$('.boxInputCaptcha input').val('').removeClass('error');
					$('textarea.txtComment').val('');
				 } else if(json.msg == "erroCaptcha"){
				    $('.ajaxEnviando .inner, .ajaxEnviando .innerErro, .ajaxEnviando .innerEnviado').hide();
				    $('.ajaxEnviando .innerErroCaptcha').fadeIn();
				    $this.find('.boxImgCaptcha a').click();
				    $this.find('.boxInputCaptcha input').val('').removeClass('valid').addClass('error');
				 } else if(json.msg == "erroLogin"){
					 alert("Erro no login, por favor tente novamente.");
				 } else {
				     $('.ajaxEnviando .inner, .ajaxEnviando .innerEnviado, .ajaxEnviando .innerErroCaptcha').hide();
					$('.ajaxEnviando .innerErro').fadeIn();
					$this.find('.boxImgCaptcha a').click();
					$this.find('.boxInputCaptcha input').val('').removeClass('error');
				 }
			   }
			});
		  }, 1000);
	    }
	 });
   });
}

function timerBanner(){
   $('ul#listExp li a').removeClass('animate');
   if($('ul#listExp li a.hover').parent().hasClass('last')){
	 $('ul#listExp li:first a').addClass('animate').click();
   } else {
	 $('ul#listExp li a.hover').parent().next().find('a').addClass('animate').click();
   }
}

/* HINT */
/**
* @author Remy Sharp
* @url http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/
*/
(function($) {

	$.fn.hint = function(blurClass) {
		if (!blurClass) {
			blurClass = 'blur';
		}

		return this.each(function() {
			// get jQuery version of 'this'
			var $input = $(this),

			// capture the rest of the variable to allow for reuse
      title = $input.attr('title'),
      $form = $(this.form),
      $win = $(window);

			function remove() {
				if ($input.val() === title && $input.hasClass(blurClass)) {
					$input.val('').removeClass(blurClass);
				}
			}

			// only apply logic if the element has the attribute
			if (title) {
				// on blur, set value to title attr if text is blank
				$input.blur(function() {
					if (this.value === '') {
						$input.val(title).addClass(blurClass);
					}
				}).focus(remove).blur(); // now change all inputs to title

				// clear the pre-defined text when form is submitted
				$form.submit(remove);
				$win.unload(remove); // handles Firefox's autocomplete
			}
		});
	};

})(jQuery);
/* HINT */


