  var url = location.href;                                
   url = url.split("/");                               
    var ROOT = (url[2]);

$(document).ready(function(){
	$('#calendario_agenda').load('agendaajax.php');	
// Formulario de Comentario
$('#form_coment').submit(function(e){ e.preventDefault(); });	
	$('#salvar_coment').click(function(){
		var codigo = $("#codigo").val();
		var title_pg = $("#title_pg").val();
		var link_pagina = $("#link_pagina").val();
		var nome_user = $("#nome_user").val();
		var email_user = $("#email_user").val();
		var text_coment = $("#text_coment").val();
if (nome_user!='' && email_user!='' && text_coment!='')
		{		
$('#form_coment')[0].reset();
					$.post('http://'+ROOT+'/enviar/index.php', {codigo:codigo, nome_user: nome_user, email_user:email_user, text_coment:text_coment, title_pg:title_pg, link_pagina:link_pagina}, function(newitems){
					$('#tudo').append(newitems);
					alert('Enviado com sucesso! \n\n Seu comentário só será postado após a avaliação.  ');
					updatestatus();
					
		}); 
		}else{
					alert("Por favor preencher todos os campos.");
		}
		return false;
	});	
		
	//biblia online
$('#frm_pesq_biblia').submit(function(e){ e.preventDefault(); });
$('#frm_pesq_biblia').submit(function(e){ e.preventDefault();return false; });
$(function(){
	$('#formbusca').click(function(){
		$('#carregando').show();
		var lvBiblia = $("#lvBiblia").val();
		var capitulo = $("#capitulo").val();
		var versiculo = $("#versiculos").val();
		var maxpag = $("#maxpag").val();
		var palavra = $("#palavra").val();
		var formbusca = "OK";
			$.post("inic.php",{lvBiblia: lvBiblia, capitulo: capitulo, versiculo: versiculo, maxpag: maxpag, palavra:palavra, formbusca:formbusca}, function(retorno){
					$('#corpo_biblia').html(retorno);
					$('#carregando').hide();
			}) 

	})
});	
	
$('#lvBiblia').change(function(){
	$('#carregando').show();
	var lvBiblia = $("#lvBiblia").val();
					$.post('http://'+ROOT+'/biblia_online/lv_capitulo.php', { lvBiblia: lvBiblia}, function(newitems){
					$('#capitulo').html(newitems);
					$('#livrohidden').attr("value", lvBiblia);
					$('#versiculos').html('<option value="">---</option>');
					$('#carregando').hide();
					});
	});	
$('#capitulo').change(function(){
	$('#carregando').show();
	var lvCapitulo = $("#capitulo").val();
	var livroHidden = $("#livrohidden").val();
					$.post('http://'+ROOT+'/biblia_online/lv_versiculo.php', { lvCapitulo: lvCapitulo, livroHidden: livroHidden}, function(newitems){
					$('#versiculos').html(newitems);
					$('#carregando').hide();
					});

	});	
	
	
	$('#searchBox').focus(function(){
	if(this.value=='Pesquisar'){
	$(this).attr("value", "");
	$(this).css("color", "black");
	$(".requer").hide();
	$(".erro").remove();
	}else{
	if(this.value!='Pesquisar'){
	$(this).css("color", "black");
	} }
	});
$('#searchBox').blur(function(){
	if(this.value==''){
	$(this).attr('value', 'Pesquisar');
	$(this).css({'color': '#ccc'});
	$(".requer").hide();
	$(".erro").remove();
	}
	});	
$("#mostra_form").click(function(){
	$('#deixar_recado').slideToggle("normal");
	$('#deixar_recado').load("http://"+ROOT+"/estrutura/deixar_recado.php");
	});	
		var theInt = null;
		var $crosslink, $navthumb;
		var curclicked = 0;
		
		theInterval = function(cur){
			clearInterval(theInt);
			
			if( typeof cur != 'undefined' )
				curclicked = cur;
			
			$crosslink.removeClass("active-thumb");
			$navthumb.eq(curclicked).parent().addClass("active-thumb");
				$(".stripNav ul li a").eq(curclicked).trigger('click');
			
			theInt = setInterval(function(){
				$crosslink.removeClass("active-thumb");
				$navthumb.eq(curclicked).parent().addClass("active-thumb");
				$(".stripNav ul li a").eq(curclicked).trigger('click');
				curclicked++;
				if( 6 == curclicked )
					curclicked = 0;
				
			}, 5000);
		};
		
		$(function(){
			
			$("#main-photo-slider").codaSlider();
			
			$navthumb = $(".nav-thumb");
			$crosslink = $(".cross-link");
			
			$navthumb
			.click(function() {
				var $this = $(this);
				theInterval($this.parent().attr('href').slice(1) - 1);
				return false;
			});
			
			theInterval();
		});
		
			$(".cx_content_dest2").easySlider({
				auto: true, 
				continuous: true,
				pause:	5000,
				speed:  3000
			});
// Formulario Enquete
$('#form_enquete').submit(function(e){ e.preventDefault(); });	
	$('#votar_enquete').click(function(){
		$('#carregando').show();
		var atual = $("#atual").val();
		var resposta = $('input:radio[name=resposta]:checked').val();
if (resposta!='')
		{		
$('#form_enquete')[0].reset();
					$.post('http://'+ROOT+'/enviar/salvar_enquete.php', {atual: atual, resposta:resposta}, function(newitems){
						alert('Voto realizado com sucesso!');
						$('#resultado_e').slideDown("normal", function(){$('#resultado_e').html(newitems);});
						$('#carregando').hide();
					updatestatus();
					
		}); 
		}else{
					alert("Por favor preencher todos os campos.");
		}
		return false;
	});
	
$('#result_enquete').click(function(){
	$('#carregando').show();
		var atual = $("#atual").val();		
$('#form_enquete')[0].reset();
					$.post('http://'+ROOT+'/enviar/salvar_enquete.php', {atual: atual}, function(newitems){
						$('#resultado_e').slideDown("normal", function(){$('#resultado_e').html(newitems);});
						$('#carregando').hide();
					updatestatus();
					
		}); 
		});
//fim
// Formulario de Pedido de Oração
$('#form_pedido').submit(function(e){ e.preventDefault(); });	
	$('#salvar_pedido').click(function(){
		var nome_user = $("#nome_user").val();
		var email_user = $("#email_user").val();
		var pedido = $("#pedido").val();
		var cidade = $("#cidade_user").val();
		var estado = $("#estado_user").val();
if (nome_user!='' && email_user!='' && pedido!=''){		
$('#form_pedido')[0].reset();
					$.post('http://'+ROOT+'/enviar/pedido.php', {nome_user: nome_user, email_user:email_user, pedido:pedido, cidade:cidade,estado:estado }, function(newitems){
					$('#tudo').append(newitems);
					alert('Enviado com sucesso!');
					updatestatus();
					
		}); 
		}else{
					alert("Por favor preencher os campos. \n Nome, e-mail, e pedido");
		}
		return false;
	});		

});

$('document').ready(function(){
	updatestatus();
	scrollalert();
});
function updatestatus(){
// Mostrar o número de itens carregados
	var totalItems=$('#content .m_re_ipr').length;
	$('#status').text('');
}
function scrollalert(){
	var scrolltop=$('#mural_de_recado').attr('scrollTop');
	var scrollheight=$('#mural_de_recado').attr('scrollHeight');
	var windowheight=$('#mural_de_recado').attr('clientHeight');
	var scrolloffset=20;
	if(scrolltop>=(scrollheight-(windowheight+scrolloffset)))
	{
	// buscar novos itens
	var totalItems=$('#content .m_re_ipr').length;
	$('#status').text('Carregados '+totalItems+' Itens');
		$('#status').text('Carregando...');
		$.get('http://'+ROOT+'/enviar/mais_recado.php?id='+totalItems+'', function(newitems){
			if(totalItems > 5){
			$('#content').append(newitems);
			}
			updatestatus();
		});
	}
	setTimeout('scrollalert();', 1500);
}
function navegaMes(data){
					$('#carregando').show();
					$.post('agendaajax.php', {data: data}, function(newitems){
					$('#calendario_agenda').html(newitems);
					$('#carregando').hide();
					});
	}
function voltarEvento(data){
					$('#carregando').show();
					$('#mostra_evento').load('eventos_index.php');
					$('#carregando').hide();
	}
function mostraEventos(d){
					$('#carregando').show();
					$.post('eventos.php', {d: d}, function(newitems){
					$('#mostra_evento').html(newitems);
					$('#carregando').hide();
					});
	}
function verVideo(d, id){
					$('#carregando').show();
					$("#lista_video li").addClass("transp_video");
					$("#lista_video li").removeClass("opac_video");
					$.post('ver_video.php', {codigo: d}, function(newitems){
					$('#id_'+id).removeClass("transp_video");
					$('#id_'+id).addClass("opac_video");
					$('#ver_video').html(newitems);
					$('#carregando').hide();
					});
	}
function paginarBiblia(formbusca,lvBiblia,capitulo,versiculo, pagina) {
	$('#carregando').show();
	if(capitulo==""){
		$.post("inic.php",{lvBiblia: lvBiblia, formbusca:formbusca, pagina:pagina}, function(retorno){
					$('#corpo_biblia').html(retorno);
					$('#carregando').hide();
			});
		}
		else if(versiculo==""){
			$.post("inic.php",{lvBiblia: lvBiblia, formbusca:formbusca, pagina:pagina, capitulo:capitulo}, function(retorno){
					$('#corpo_biblia').html(retorno);
					$('#carregando').hide();
			});
			}
			else{
				$.post("inic.php",{lvBiblia: lvBiblia, formbusca:formbusca, pagina:pagina, capitulo:capitulo, versiculo:versiculo}, function(retorno){
					$('#corpo_biblia').html(retorno);
					$('#carregando').hide();
			});
				} 
				$('html, body').animate({ scrollTop: 0 }, 3000);
				}	
function closeResult(){
					$('#resultado_e').slideToggle("normal");
	}
function PgVideo(pg){
	$('#carregando').show();
	$('html, body').animate({ scrollTop: 0 }, 1000);
		$.post('http://'+ROOT+'/videos/mais_videos.php',{pg: pg}, function(retorno){
					$('#videos').html(retorno);
					$('#carregando').hide();
			});	
	}
function PgFotos(pg){
	$('#carregando').show();
	$('html, body').animate({ scrollTop: 0 }, 1000);
		$.post('http://'+ROOT+'/album_fotos/mais_fotos.php',{pg: pg}, function(retorno){
					$('#album_fotos').html(retorno);
					$('#carregando').hide();
			});	
	}
function PgNoticias(pg){
	$('#carregando').show();
	$('html, body').animate({ scrollTop: 0 }, 1000);
		$.post('http://'+ROOT+'/noticias/mais_noticias.php',{pg: pg}, function(retorno){
					$('#pgnoticia').html(retorno);
					$('#carregando').hide();
			});	
	}
function PgDestaques(pg){
	$('#carregando').show();
	$('html, body').animate({ scrollTop: 0 }, 1000);
		$.post('http://'+ROOT+'/destaques/mais_destaques.php',{pg: pg}, function(retorno){
					$('#pgdestaque').html(retorno);
					$('#carregando').hide();
			});	
	}
// Janela Radio
var win=null;
function NewWindow(myname,w,h,scroll,pos,root){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=0}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open("http://"+ROOT+"/radio/",myname,settings);
}

// Fim Janela Radio
