function textCounter() {
  maxlimit = 255
  if (this.value.length > maxlimit)
    this.value = this.value.substring(0, maxlimit)
}
function newsletter () {
  var email = $("#newsletter input#email").val()
  $.post(base_url+"site/newsletter",
    { email: email },
    function(data) {
      alert(data)
    }
  )
  return false
}
$(document).ready(function(){
  
  $("#conteudo input, textarea, select").focus(
    function () {
      $(this).css({ "background-color":"#f0f0f0", "border-color":"#333" })
    }
  )

  $("#conteudo input, textarea, select").blur(
    function () {
      $(this).css({"background-color":"#fff", "border-color":"#999" })
    }
  )

  $(".tel input, .telefone").mask("(99) 9999-9999")
  $("[name=cpf]").mask("999.999.999-**")
  $("[name=cnpj]").mask("99.999.999/9999-**")
  $("[name=rg]").mask("99.999.999-*")
  $(".data input").mask("99/99/9999")
  $(".hora input").mask("99:99")
  $(".cep input, .cep").mask("99999-999")

  $("textarea").keyup(textCounter)
  
  
  $("[name^=indicacao_telefone1]").live('focus', function(){ $(this).mask("(99) 9999-9999"); })
  $("[name^=indicacao_telefone2]").live('focus', function(){ $(this).mask("(99) 9999-9999"); })
  $("[name^=indicacao_celular]").live('focus', function(){ $(this).mask("(99) 9999-9999"); })
  $("[name^=indicacao_data]").live('focus', function(){ $(this).mask("99/99/9999"); })
  
  $("[name^=indicacao_data]").mask("99/99/9999")
  $("[name^=indicacao_telefone1]").mask("(99) 9999-9999")
  $("[name^=indicacao_telefone2]").mask("(99) 9999-9999")
  $("[name^=indicacao_celular]").mask("(99) 9999-9999")
  


  
  



  if($('[name=estado]').get(0)){
    new dgCidadesEstados({
      estado: $('[name=estado]').get(0),
      cidade: $('[name=cidade]').get(0)
    })
  }
  
  $("#newsletter form").submit(newsletter)
  
  $('#noticias, #oracoes').accordion({
    header: '.titulo', 
    active: false,
    alwaysOpen: false,
    autoheight: false
  });
  $("#oracoes a.enviar").colorbox({
    width:"50%", 
    height:"80%", 
    iframe:true,
    onClosed:function(){ alert('Mensagem enviada com sucesso'); }
  });
  $("#noticias > li").hover(
      function () {
      $(this).css({ "background-color":"#eee" });
      },function () {
      $(this).css({"background-color":"#fff"});
  });
  
  $("a.addsalmo").click(function() {
    $(this).next().clone().appendTo(".mailto")
    $(".mailto label:last input").val("")
    return false
  })

  $('#imagens-topo').cycle({ 
    fx: 'fade',
    speed: 3000,
    timeout: 8000
  });


$('.add_multiplo a').click(function(){
    var table = $(this).parents('fieldset').find('table')
    var tr = table.find('tr:last').html()
    table.append('<tr>'+tr+'</tr>')
    table.find('tr:last input').val('')
    return false
})

$("#fotos_cemiterio li").hover(function() {
$(this).css({'z-index' : '10'});
$(this).find('img').addClass("hover").stop()
 .animate({
  marginTop: '-60px',
  marginLeft: '-110px',
  top: '50%',
  left: '50%',
  width: '220px',
  height: '170px',
  padding: '20px'
 }, 200);

} , function() {
$(this).css({'z-index' : '0'});
$(this).find('img').removeClass("hover").stop()
 .animate({
  marginTop: '0',
  marginLeft: '0',
  top: '0',
  left: '0',
  width: '150px',
  height: '100px',
  padding: '5px'
 }, 400);
});


//Swap Image on Click
$("#fotos_cemiterio li a").click(function() {
 return false; 
});


})

