jQuery(document).ready(function() {
	$(".right_box").each(function() {
		$(this).hide();
	});
	$("#sermon_summary").hide();
	$("#tabs a").each(function() {
		if($(this).attr("class") == "active") {
			var theTab = $(this).attr("rel");
			
			$("#"+theTab).fadeIn("slow", function() {
				
			});
		}
	});
	
	$("#tabs a").click(function() {
		$("#tabs a.active").each(function() {
			$(this).removeClass("active");
			var theTab = $(this).attr("rel");
			$(".right_box").fadeOut("slow", function(){
			});
		});
		$("#loading_anim").fadeIn("slow");
		$(this).animate({borderWidth: "0px"}, 1000);
		$(this).addClass("active");
		var theTab = $(this).attr("rel");
		$("#loading_anim").fadeOut("slow", function() {
			$(".right_box").hide();
			$("#"+theTab).fadeIn("slow");
			
		});
	});

	$("#sermon_summary").load("/includes/ajax/content.php", {}, function(response){
		setTimeout(refreshContent, 4000);
		$.ajax({
			url: "/includes/ajax/content.php",
			cache: false,
			data: "which=slideid",
			success: function(html){
				$("#sermon_summary").attr("rel",html);
			}
		});
		$("#sermon_summary").fadeIn("slow");
	});
});
var interval;
function refreshContent() {
	clearTimeout(interval);
	var loader_height = $("#sermon_summary").height();
	$.ajax({
		url: "/includes/ajax/content.php",
		cache: false,
		data: "which=slideid",
		success: function(html){
			if(html == $("#sermon_summary").attr("rel")) {
				interval = setTimeout(refreshContent, 4000);
			} else {
				$("#sermon_summary").fadeOut("slow", function() {
					$("#loading_anim2").height(loader_height-16);
					$("#loading_anim2").fadeIn("slow", function() {
						$("#sermon_summary").load("/includes/ajax/content.php", {}, function(response){
							interval = setTimeout(refreshContent, 4000);
							$.ajax({
								url: "/includes/ajax/content.php",
								cache: false,
								data: "which=slideid",
								success: function(html){
									$("#sermon_summary").attr("rel",html);
								}
							});
							$("#loading_anim2").fadeOut("slow", function() {
								$("#sermon_summary").fadeIn("slow");
							});
						});
					});
				});
			}
		}
	});
}

function refreshContentManual() {
	clearTimeout(interval);
	var loader_height = $("#sermon_summary").height();
	$("#sermon_summary").fadeOut("slow", function() {
		$("#loading_anim2").height(loader_height-16);
		$("#loading_anim2").fadeIn("slow", function() {
			$("#sermon_summary").load("/includes/ajax/content.php", {}, function(response){			
				interval = setTimeout(refreshContent, 4000);
				$("#loading_anim2").fadeOut("slow", function() {
					$("#sermon_summary").fadeIn("slow");
				});
			});
		});
	});
}

function tb_popup(url) {
	tb_show(null, url+"?KeepThis=true&TB_iframe=true&height=480&width=640", false)
}


function fbs_click() {u=location.href;t=document.title;window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),'sharer','toolbar=0,status=0,width=626,height=436');return false;}
