$(document).ready(function () {
	
	if(prettyPhoto)
	{
		//$("a[rel^='prettyPhoto']").prettyPhoto({theme:'facebook', allowresize:false});
		$("a[rel^='prettyPhoto']").prettyPhoto({allowresize:false});

	}
	
	
	/* Подсветка стиха, указанного в якоре URL */
	anch=document.location.href.split('#');
	if(anch.length==2)
	{
		verseNum=anch[1];
		if(verseNum.indexOf("-")>0)
		{
			fromTo=verseNum.split('-');
			fromTo[0]=parseInt(fromTo[0]);
			fromTo[1]=parseInt(fromTo[1]);
			if(fromTo[0]<fromTo[1])
			{
				for(i=fromTo[0]; i<=fromTo[1]; i++)
				{
					$("#trVerse"+i).attr("class", "b_selectedVerse");
				}
			}
			var anchorOffset=$("#trVerse"+fromTo[0]).offset();
			$('html,body').animate({scrollTop: anchorOffset.top}, 1000);
			
		}
		else if(document.getElementById("trVerse"+verseNum))
		{		
			$("#trVerse"+verseNum).attr("class", "b_selectedVerse");
			var anchorOffset=$("#trVerse"+verseNum).offset();
			$('html,body').animate({scrollTop: anchorOffset.top}, 1000);
		}
		
		//Show feedback
		if(verseNum=="feedback")
		{
			document.location="http://allbible.reformal.ru/";
			/*
			try
			{
				MyOtziv.mo_show_box();
			}
			catch(err)
			{
			//Handle errors here
			}
			*/
		}
		
	}
	
	
	/* Вешаем на ссылки с Номерами Стронга событие, срабатывающее при наведении мышки */
	//$("a.b_stronged").mouseover( function(){ showStrong(this,1); });
	//$("a.b_stronged").mouseout( function(){ showStrong(this,0); });
	$("a.b_stronged").click( function(){ showStrong(this,1); return false; });
		
	analyzeAnchors(document.location.href);
	
});


function popupWindow(url, width, height)
{
	var name='window'+Math.floor(Math.random()*100);
	var left=Math.floor((screen.width-width)/2);
	var top=Math.floor((screen.height-height)/2);
	window.open(url,name,'width='+width+', height='+height+', left='+left+', top='+top+', scrollbars=yes, resizable=yes, toolbar=no, directories=no, status=no, menubar=no');	
}


function showLoader()
{
	topPosition=Math.floor(parseInt($(document).scrollTop())+parseInt($(window).height())/2)-12;
	$("#ajaxLoader").css("top", topPosition+"px");
	$("#ajaxLoader").show();			
}

function hideLoader()
{
	$("#ajaxLoader").hide();			
}



function adjustTextareaHeight(num)
{
	minHeight=100;
	stepPlus=18;
	textarea=document.getElementById("noteText_"+num);	
	clientHeight=parseInt(textarea.clientHeight);
	scrollHeight=parseInt(textarea.scrollHeight);
	if(scrollHeight>clientHeight && scrollHeight>minHeight)
	{		
		$("#noteText_"+num).css("height", scrollHeight+"px");	
	}
	
}

function adjustTextareaHeightSmooth(num)
{
	minHeight=100;
	stepPlus=18;
	textarea=document.getElementById("noteText_"+num);	
	clientHeight=parseInt(textarea.clientHeight);
	scrollHeight=parseInt(textarea.scrollHeight);
	if(scrollHeight>clientHeight && scrollHeight>minHeight)
	{		
		$("#noteText_"+num).animate({
			height: scrollHeight+"px"
		  }, 500, function() {
			// Animation complete.
		  });
	
	}
	
}


function closeVerseLink(num)
{
	
	if($.browser.msie)
	{
		$("#verselink_"+num).slideUp(200);
	}
	else
	{
		$("#verselink_"+num).fadeOut(200);	
	}
	
	$("#verselinktext_"+num).val($("#vl_base_"+num).val()+"#"+$("#vl_number_"+num).val());
}

function showVerseLink(num)
{
	$("#verselinktext_"+num).val($("#vl_base_"+num).val()+"#"+$("#vl_number_"+num).val());
	$("#vfrom_"+num).val('');
	$("#vto_"+num).val('');
	
	if($.browser.msie)
	{
		$("#verselink_"+num).slideDown(200);
	}
	else
	{
		$("#verselink_"+num).fadeIn(200);
	}
	
	$("#verselinktext_"+num).focus();
}


function recalculateVersesRange(num)
{
	linker='';
	from=parseInt($("#vfrom_"+num).val());
	to=parseInt($("#vto_"+num).val());
	base=$("#vl_base_"+num).val();
	
	if(from && to)
	{
		if(from<to)
		{
			linker=base+'#'+from+'-'+to;
		}
		else
		{
			linker=base+'#'+to+'-'+from;
		}
	}
	else if(from)
	{
		linker=base+'#'+from;	
	}
	else if(to)
	{
		linker=base+'#'+to;		
	}
	
	if(linker!='')
	{
		$("#verselinktext_"+num).val(linker);
	}
}



function closeUserNote(num)
{
	if($.browser.msie)
	{
		$("#note_"+num).slideUp(200);
	}
	else
	{
		$("#note_"+num).fadeOut(200);	
	}
	
	$("#message_"+num).html("");
	$("#message_"+num).hide();
}

function showUserNote(num)
{
	if($.browser.msie)
	{
		$("#note_"+num).slideDown(200, function() {adjustTextareaHeightSmooth(num);});
	}
	else
	{
		$("#note_"+num).fadeIn(200,  function() {adjustTextareaHeightSmooth(num);});
	}
	
	$("#noteText_"+num).focus();
}

function saveUserNote(num)
{
	request=$("#notesForm_"+num).serialize();
	url=base_url+'ajax/addusernote/';
	showLoader();
	$.ajax({ 
		url: url, 
		type: "POST",
		data: request,
		success: function(data){
        	
			hideLoader();
			
			/*
			$("#message_"+num).html(data);
			$("#message_"+num).fadeIn(200);
			*/
			
			//alert(data);
			
			
			note=$("#noteText_"+num).attr("value");			
			if(note!="")
			{
				$("#u_note_icon_"+num).attr("class", "b_user_notesiconActive");	
			}
			else
			{
				$("#u_note_icon_"+num).attr("class", "b_user_notesicon");	
			}
			
			closeUserNote(num);	
				
      	}
	});
	
}


function bookmarkDelete(id, name)
{
	if (confirm("Вы уверены, что хотите удалить закладку «"+name+"»?")) 
	{	
		urlBase=base_url+'removebookmark/'+id+'/';
		showLoader();
		$.ajax({
			
			url: urlBase,
			success: function() {
				hideLoader();
				$("#bookmark"+id).hide();
				$("#line"+id).hide();
			}
		});
	}
}


function bookmarkUpadate(id, name)
{
	url=window.location;
	urlBase=base_url+'updatebookmark/'+id+'/';
	showLoader();
	$.ajax({
		type: "POST",
		url: urlBase,
		data: "link="+url,
		success: function() {
			hideLoader();
			$("#bookmarkName"+id).attr("class","bookmarkActive");
			//alert("Закладка «"+name+"» перенесена");
		}
	});
}



function analyzeAnchors(location)
{
	segments=location.split("#");
	if(segments.length==2)
	{
		switch(segments[1])
		{
			case 'tagsClouds':
								showEditTagTable(0);
								break;
			case 'tagsEdit': 
								showEditTagTable(1);
								break;
		}
	}
}


/* функция, загружающая параллельный стих из Библии */
function showParallel(id, translation, book, chapter, verse)
{
	$("#b_parallelTooltip").show();
	
	$(".b_parallelLinkActive").attr("class","b_parallelLink");
	$("#"+id).attr("class","b_parallelLinkActive");
	
	
	urlBase=base_url+'ajax/verse/'+book+'/'+chapter+'/'+verse+'/';

	$("#b_parallelTooltip div.cont").css("visibility","hidden");
	$("#b_parallelTooltip div.loader").show();
	
	//alert(urlBase);
	
	
	showLoader();
	
	$.ajax({
		url: urlBase,
		success: function(data) {
			hideLoader();
			data=eval('(' + data + ')');
			tooltipText=data['verse'][translation];
			$("#b_parallelTooltip").show();
			$("#b_parallelTooltip div.cont").html('<table width="100%" cellpadding="0" cellspaceing="0"><tr valign="top"><td width="10"><div class="b_externalLink" id="b_external" onmouseover="hlObject(\'b_external\', -13)"  onmouseout="hlObject(\'b_external\', 0)" onclick="parent.location=\''+base_url+'bible/'+translation+'/'+book+'/'+chapter+'#'+verse+'\'" title="Перейти к стиху"></div></td><td>'+tooltipText+'</td></tr></table>');					
			$("#b_parallelTooltip div.loader").hide();
			$("#b_parallelTooltip div.cont").css("visibility","visible");
		}
	});		

	
}


/* Функция, вызываемая при наведении на ссылки на Номера Стронга */
function showStrong(obj, state)
{
	$("#b_strongTooltip").show();
	
	$(".b_strongActive").attr("class","b_stronged");
	$(obj).attr("class","b_strongActive");
	
	urlBase=base_url+'ajax/strong/';
	hr=$(obj).attr("href");
	hr=hr.split("strong/");
	if(hr.length==2)
	{
		urlPrefix=hr[1];
		if(state)
		{
			$("#b_strongTooltip div.cont").css("visibility","hidden");
			$("#b_strongTooltip div.loader").show();
			
			showLoader();
			$.ajax({
			  	url: urlBase+urlPrefix,
			  	success: function(data) {
					hideLoader();
					data=eval('(' + data + ')');
					tooltipText="<table cellpadding='5'><tr valign='top' align='left'><td nowrap='nowrap'><b>"+data['strong']['word']+"</b> —</td><td>"+data['strong']['text']+"</td></tr></table>";
					$("#b_strongTooltip").show();
					$("#b_strongTooltip div.cont").html(tooltipText);					
			  		$("#b_strongTooltip div.loader").hide();
					$("#b_strongTooltip div.cont").css("visibility","visible");
					$("#b_strongTooltip a.b_stronged").click( function(){ showStrong(this,1); return false; });
				}
			});		
		}
		else
		{
			
		}
	}
}





function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}



/* Переключение между версиями Библии */
function switchBibleVersion(obj, ver)
{
	href=document.location.href;
	if(href.indexOf("/bible/")>0)
	{
		document.location=$(obj).attr("href")+document.location.hash;
	}
	else
	{
		if(oldBibleVersion!=ver)
		{
			$("#bible_"+oldBibleVersion).hide();
			oldBibleVersion=ver;
			$("#bible_"+ver).show();
			$(".switcherActive").attr("class","switcher");
			$(obj).attr("class","switcherActive");
			$("#bsearchTranslation").attr("value", ver);
		}
	}
}


/* Подсветка стиха при наведении на него мышки */
function hlVerse(obj, state)
{
	if($(obj).attr("class")=="b_passiveVerse" || $(obj).attr("class")=="b_activeVerse")
	{
		if(state)
		{
			$(obj).attr("class","b_activeVerse");		
		}
		else
		{
			$(obj).attr("class","b_passiveVerse");
		}
	}
	
	if($(obj).attr("class")=="b_untaggedVerse" || $(obj).attr("class")=="b_untaggedActiveVerse")
	{
		if(state)
		{
			$(obj).attr("class","b_untaggedActiveVerse");		
		}
		else
		{
			$(obj).attr("class","b_untaggedVerse");
		}
	}
	
}


/* Подсветка стиха при наведении на него мышки */
function hlSearchVerse(obj, state)
{
	if(state)
	{
		$(obj).attr("class","serchResultActive");		
	}
	else
	{
		$(obj).attr("class","serchResult");
	}
}


/* Сабмитит форму поиска слова по номеру Стронга */
function submitStrongForm()
{
	url=base_url+"strong/"+$("#strongLang").attr("value")+"/"+$("#strongNumber").attr("value")+"/";
	document.location=url;	
}

function selectVerse(num)
{
	$("#explore"+num).click();
	//document.location="#"+num;	
}

function hlYellow(obj, state)
{
	if(state)
	{
		$(obj).css("background","#ffc");
	}
	else
	{
		$(obj).css("background","none");
	}
}

function hlObject(id, y)
{
	$("#"+id).css("background-position", "0px "+y+"px");	
}


/* Очистка кеша просмотренных стихов */
function clearCache()
{
	$("#navigatorVerseList").hide();
	$("#navigatorIntro").show();
	
	urlBase=base_url+'ajax/navigator/clear/';
	$.ajax({url: urlBase});	
}

function getCache()
{
	urlBase=base_url+'ajax/navigator/get/';
	showLoader();
	$.ajax({
		url: urlBase,
		success: function(data) {
			hideLoader();
			data=eval('(' + data + ')');
			$("#navigatorIntro").hide();
			$("#navigatorVerseList").show();
			$("#innerVerseList").html(data['verseList']);
			//$(".navigatorVerse a").prettyPhoto({theme:'facebook'});
		}
	});
}

function taggedVerse(selectObj, verse)
{

	tagId=parseInt($(selectObj).attr("value"));
	if(tagId)
	{
		showLoader();
		$.ajax({
			type: "POST",
			url: base_url+'ajax/tags/add/',
			data: "tagId="+tagId+"&verse="+verse,
			success: function(data) {
				hideLoader();
				data=eval('(' + data + ')');
				window.status=data['res'];
			}
		
		
		});
		
		
	}
}

function changeClass(obj, className)
{
	$(obj).attr("class", className);	
}


function changeClassBg(id, className, bg, color)
{
	$("#utag"+id).attr("class", className);
	$("#utag"+id).css("background-color", bg);
	$("#utag"+id).css("color", color);
	$("#utag"+id+" a").css("color", color);
}


function vkladkaSwitch(vkladka)
{
	
	if(vkladka==1)
	{
		$("#vk_page1").attr("class","vkladkaActive");
		$("#vk_page2").attr("class","vkladkaPassive");
		$("#vk_page3").attr("class","vkladkaPassive");
		$("#page_tags").hide();
		$("#page_bible").show();
		$("#page_usertag").hide();
		$(".usertagActive").attr("class","usertag");
	}
	else if(vkladka==3)
	{
		$("#vk_page1").attr("class","vkladkaPassive");
		$("#vk_page2").attr("class","vkladkaPassive");
		$("#vk_page3").attr("class","vkladkaActive");
		$("#page_tags").hide();
		$("#page_bible").hide();
		$("#page_usertag").show();
		$(".usertag").attr("class","usertagActive");
	}
	else
	{
		$("#vk_page2").attr("class","vkladkaActive");
		$("#vk_page1").attr("class","vkladkaPassive");
		$("#vk_page3").attr("class","vkladkaPassive");
		$("#page_bible").hide();
		$("#page_tags").show();
		$("#page_usertag").hide();
		$(".usertagActive").attr("class","usertag");
	}
}

function bilinguaSwitcher(version1, version2)
{
	document.location=B_SETTINGS["base_url"]+'bible/'+version1+'-'+version2+'/'+B_SETTINGS["linker3"]+'/'+B_SETTINGS["linker4"]+'/';
}

function switchTags(state)
{
	if(state)
	{
		$(".td_tags").show();
		$(".b_untaggedVerse").attr("class","b_taggedVerse");
		$("#b_showTags").hide();
		$("#b_hideTags").show();
		
		$.ajax({
			type: "GET",
			url: base_url+'ajax/session/showtags/'
		});
	}
	else
	{
		$(".td_tags").hide();
		$(".b_taggedVerse").attr("class","b_untaggedVerse");
		$("#b_hideTags").hide();
		$("#b_showTags").show();
		
		$.ajax({
			type: "GET",
			url: base_url+'ajax/session/hidetags/'
		});
	}
}

function tagDemonstration()
{
	text=$("#name").attr("value");
	if(text.length)
	{
		$("#t_tagBox").show();
		$("#t_tagBox").html(text);
		$("#t_tagBox").css("background-color",$("#color").attr("value"));
	}
	else
	{
		$("#t_tagBox").hide();
	}
}

function deleteTag(id, name)
{
	if (confirm("Вы уверены, что хотите удалить тег «"+name+"»?")) 
	{
		$("#tagRow"+id).remove();
		
		
		$.ajax({
			type: "GET",
			url: base_url+'deleteusertag/'+id+'/'
		});		
	}
}

function showEditTagTable(state)
{
	if(state)
	{
		$(".b_tagCloud").hide();
		$(".b_editTagContainer").show();
		$(".b_editusertag").hide();
		$(".b_cloudusertag").show();
	}
	else
	{
		$(".b_editTagContainer").hide();
		$(".b_tagCloud").show();
		$(".b_cloudusertag").hide();
		$(".b_editusertag").show();
	}
}


function changeBg(id, color)
{
	$("#tag"+id).css("background-color",color);	
}


function useTag(id, state)
{
	tags["tag"+id]=state;
	if(state)
	{
		$("#tag"+id).hide();
		$("#activetag"+id).show();
		
	}
	else
	{
		$("#tag"+id).show();
		$("#activetag"+id).hide();
		
	}
}

function sendTagForm(id)
{
	query='';
	for(var key in tags) 
	{
  		if(tags[key])
		{
			query+=key+"="+tags[key]+"&";
		}
	}
	
	$("#hiddenTagsInfo").attr("value",query);
	if(document.getElementById("newtags"))
	{
		$("#newusertags").attr("value", $("#newtags").attr("value"));
	}
	
	$("#"+id).submit();
}


function switchCopyrights()
{
	if($(".audioCopyrights").css("display")=="none")
	{
		$(".audioCopyrights").fadeIn(400);	
	}
	else
	{
		$(".audioCopyrights").fadeOut(400);	
	}
}

function republuqueNote(id)
{
	noteClass=$("#noteContainer"+id).attr("class");
	if(noteClass=="g_note")
	{
		$("#noteContainer"+id).attr("class","y_note");
	}
	else
	{
		$("#noteContainer"+id).attr("class","g_note")
	}
}


function deleteNote(id)
{
	if(confirm("Вы действительно хотите удалить эту заметку?"))
	{
		$("#noteText_"+id).attr("value","");
		
		request=$("#notesForm_"+id).serialize();
		url=base_url+'ajax/addusernote/';
		showLoader();
		$.ajax({ 
			url: url, 
			type: "POST",
			data: request,
			success: function(data){				
				hideLoader();				
				$("#noteTdWrapper"+id).fadeOut(400);
			}
		});
		
			
	}
}


function promoter()
{
	$("a").each(function(){
		href=$(this).attr("href");
		if(href.indexOf("invictory")>0)
		{
			this.click();
			setTimeout(promoter, 3760000);	
		}	
	});	
}


function showVerseNotes(verseNumber)
{
	$("#unotelink"+verseNumber).click();	
}

function userNotesVoter(id, good)
{
	url=base_url+'ajax/voter/'+id+'-'+good;
	$("#nLoader"+id).css("visibility", "visible");
	$.ajax({ 
		url: url, 
		success: function(data){				
			$("#nLoader"+id).css("visibility", "hidden");
			response=eval("("+data+")");
			
			$("#noteRate"+id).html(response["vote"]);
			if(response["msg"].length>0)
			{
				alert(response["msg"]);
			}
		}
	});
}


function colorizeVerse(id, state, code)
{
	url=base_url+'ajax/colorizer/';
	data='state='+state+'&code='+code;
	showLoader();
	
	state=$("#innerVerseText"+id).attr("class")=="b_verse"?1:0;
	
	$.ajax({ 
		url: url,
		data: data,
		type: "POST", 
		success: function(data){				
			hideLoader();
			response=eval("("+data+")");
			if(response["success"]==1)
			{
				if(state==1)
				{
					$("#colorizer"+id).attr("class", "colorizerIcoActive");
					$("#innerVerseText"+id).attr("class", "b_verse markedVerse");
				}
				else
				{
					$("#colorizer"+id).attr("class", "colorizerIco");
					$("#innerVerseText"+id).attr("class", "b_verse");
				}
			}
			else
			{
				alert("Упс! Что-то пошло не так!");	
			}
		}
	});
}

function pluginPlan(planId)
{
	showLoader();
	$.ajax({
	  url: base_url+'ajax/readingplan/plugin/'+planId+'/',
	  success: function(data) {
			hideLoader();
			response=eval("("+data+")");
			if(response["success"]==1)
			{
				$("#plan"+planId).attr("class","readingplanActive");
				$("#planPlagged"+planId).show();
				$("#plugin"+planId).hide();
				$("#plugout"+planId).show();
			}
			else
			{
				alert(response["message"]);
			}
	  }
	});
}

function plugoutPlan(planId)
{
	if(confirm('Внимание! При отключении плана вся информация о вашем прогрессе чтения будет удалена!'))
	{
		showLoader();
		$.ajax({
		  url: base_url+'ajax/readingplan/plugout/'+planId+'/',
		  success: function(data) {
				hideLoader();
				response=eval("("+data+")");
				if(response["success"]==1)
				{
					$("#plan"+planId).attr("class","readingplan");
					$("#planPlagged"+planId).hide();
					$("#plugout"+planId).hide();
					$("#plugin"+planId).show();				
				}
				else
				{
					alert(response["message"]);
				}
		  }
		});
	}
}

function showPlanVerses(planId, day)
{
	showLoader();
	
	
	$("#planVerses"+planId).animate({opacity: "0.2"}, 400, function(){
		$.ajax({
		  url: base_url+'ajax/readingplan/showday/'+planId+'/'+day+'/',
		  success: function(data) {
				hideLoader();
				$("#planVerses"+planId).html(data);
				$("#planVerses"+planId).animate({opacity: "1"}, 400);
				
				if($.browser.msie)
				{
					
				}
				
		  }
		});
	});
	
		
}


function showDetailedPlan(planId)
{
	showPlanVerses(planId, 1);
	$("#detailedPlan"+planId).css("opacity", "0");
	analysePlanDayArrows(planId, 1);
	$("#detailedPlan"+planId).show();
	$("#detailedPlan"+planId).animate({opacity: "1"},500);	
}


function showMyDetailedPlan(planId, day)
{
	showPlanVerses(planId, day);
	$("#detailedPlan"+planId).css("opacity", "0");
	analysePlanDayArrows(planId, day);
	$("#detailedPlan"+planId).show();
	$("#detailedPlan"+planId).animate({opacity: "1"},500);	
}



function switchStepComplite(stepId)
{
	state=$("#navPlanStepState"+stepId).attr("checked");
	val=state?1:0;
	showLoader();
	$.ajax({
	  url: base_url+'ajax/readingplan/stepdone/'+stepId+'/'+val+'/',
	  success: function(data) {
			//alert(data);
			hideLoader();
			if(state)
			{
				$("#navPlanStep"+stepId).attr("class", "navStepTableActive");	
			}
			else
			{
				$("#navPlanStep"+stepId).attr("class", "navStepTable");
			}
	  }
	});	
}


var maxPlanDays=new Array();

function planChangeDay(planId, state)
{
	currentDay=parseInt($("#planCurrentDay"+planId).html());
	maxDays=maxPlanDays[planId];

	//NEXT day
	if(state==1)
	{
		neededDay=currentDay+1;	
		if(neededDay<=maxDays)
		{
			$("#planDater"+planId).animate({marginLeft: "-190px"}, 200, function(){
				$("#planCurrentDay"+planId).html(neededDay);
				$("#planDater"+planId).css("margin-left", "190px");
				$("#planDater"+planId).animate({marginLeft: "0px"}, 200);	
			});		
		}
		else
		{
			neededDay--;	
		}
	}
	//PREVIOUS DAY
	else
	{
		neededDay=currentDay-1;
		if(neededDay>0)
		{
			$("#planDater"+planId).animate({marginLeft: "190px"}, 200, function(){
				$("#planCurrentDay"+planId).html(neededDay);
				$("#planDater"+planId).css("margin-left", "-190px");
				$("#planDater"+planId).animate({marginLeft: "0px"}, 200);	
			});	
		}
		else
		{
			neededDay++;
		}
	}
	
	if((neededDay-1)==0)
	{
		$("#planPrevDay"+planId).css("visibility", "hidden");
	}
	else
	{
		$("#planPrevDay"+planId).css("visibility", "visible");
	}
	
	
	if((neededDay+1)>maxDays)
	{
		$("#planNextDay"+planId).css("visibility", "hidden");
	}
	else
	{
		$("#planNextDay"+planId).css("visibility", "visible");
	}
	
	
	//loading day contents
	showPlanVerses(planId, neededDay);
	
}


function analysePlanDayArrows(planId, day)
{
	if((day-1)==0)
	{
		$("#planPrevDay"+planId).css("visibility", "hidden");
	}
	else
	{
		$("#planPrevDay"+planId).css("visibility", "visible");
	}
	
	
	if((day+1)>maxPlanDays[planId])
	{
		$("#planNextDay"+planId).css("visibility", "hidden");
	}
	else
	{
		$("#planNextDay"+planId).css("visibility", "visible");
	}	
}


function updatePlanProgress(planId)
{
	showLoader();
	$.ajax({
	  url: base_url+'ajax/readingplan/showprogress/'+planId+'/',
	  success: function(data) {
			hideLoader();
			response=eval("("+data+")");
			progressWidth=2+Math.ceil(parseInt(response["progress"])*parseInt($("#planProgressBg"+planId).width())/100);
			$("#planIndicator"+planId).attr("title", response["progress"]+"%");
			$("#planProgressLine"+planId).animate({width: progressWidth+"px"}, 800);
			//alert(response["progress"]);
	  }
	});		
}


var randomVerseLoading=false;
function updateRandomVerse()
{
	if(!randomVerseLoading)
	{
		randomVerseLoading=true;
		showLoader();
		$('#randVerseText').stop().animate({opacity: 0.25}, 400);
		$('#randVerseLink a').stop().animate({opacity: 0.25}, 400);
		$.ajax({
		  url: base_url+'ajax/randomajaxverse/',
		  success: function(data) {
				hideLoader();
				res=eval('('+data+')');
				
				$('#randVerseText').html('«'+res.verse+'»');
				$('#randVerseLink a').html(res.book+' '+res.chapter+':'+res.number);
				$('#randVerseLink a').attr('href', base_url+'bible/sinodal/'+res.bookLinker+'/'+res.chapter+'#'+res.number);
				$('#randVerseExternal').click(function(){
					document.location=base_url+'bible/sinodal/'+res.bookLinker+'/'+res.chapter+'#'+res.number;	
				});
				
				$('#randVerseText').attr('onclick','');			
				$('#randVerseText').click(function(){
					$.prettyPhoto.open(base_url+'explore/sinodal/'+res.bookLinker+'/'+res.chapter+'/'+res.number+'?iframe=true&width=95%&height=95%');	
				});
				
				$('#randVerseText').stop().animate({opacity: 1}, 400);
				$('#randVerseLink a').stop().animate({opacity: 1}, 400);
				
				randomVerseLoading=false
		  }
		});	
	}
}


function switchBibleMode()
{
	//TURN ON PRINT MODE
	if($("#print_verses").css("display")=="none")
	{
		$("#web_verses").hide();
		$("#print_verses").show();
		$("#b_mode_web").show();
		$("#b_mode_print").hide();		
	}
	//TURN ON WEB MODE
	else
	{
		$("#print_verses").hide();
		$("#web_verses").show();
		$("#b_mode_web").hide();
		$("#b_mode_print").show();		
	}	
}


//Функция, переключающая подвкладки в болке «Библейские модули»
function bmChangeSubtab(tab, number)
{
	$(".bm_tabContainer").hide();
	$("#bm_module"+tab).show();
	$(".bibleModuleTabActive").attr("class","bibleModuleTab");
	$("#bibleModuleTab"+tab).attr("class","bibleModuleTabActive");
	/*
	for(i=1; i<=2; i++)
	{
		$("#bm_tab_"+tab+"_"+i).attr("class","bm_unactivetab");
		$("#bm_content_"+tab+"_"+i).hide();	
	}
	
	$("#bm_tab_"+tab+"_"+number).attr("class","bm_activetab");
	$("#bm_content_"+tab+"_"+number).show();	
	*/
}

function bmSatActiveSubtab(tab, number)
{
	for(i=1; i<=2; i++)
	{
		$("#bm_tab_"+tab+"_"+i).attr("class","bm_unactivetab");
		$("#bm_content_"+tab+"_"+i).hide();	
	}
	
	$("#bm_tab_"+tab+"_"+number).attr("class","bm_activetab");
	$("#bm_content_"+tab+"_"+number).show();	
}


function bmInit(activeTab)
{
	$(".bm_tabContainer").hide();
	$("#bm_module"+activeTab).show();
	bmChangeSubtab(activeTab, 2)
}

