document.documentElement.className = "js";

function initScrollPane() {
	$('a.jScrollArrowUp, a.jScrollArrowDown').remove();
	$('div.jScrollPaneContainer').css('height', '265px');
	$('#extra_container').jScrollPane({showArrows: true, scrollbarWidth: 15, scrollbarMargin: 0});
}

var dc = new Array();
	
dc['А'] = 'A';
dc['Б'] = 'B';
dc['В'] = 'V';
dc['Г'] = 'G';
dc['Д'] = 'D';
dc['Е'] = 'E';
dc['Ж'] = 'ZH';
dc['З'] = 'Z';
dc['И'] = 'I';
dc['К'] = 'K';
dc['Л'] = 'L';
dc['М'] = 'M';
dc['Н'] = 'N';
dc['О'] = 'O';
dc['П'] = 'P';
dc['Р'] = 'R';
dc['С'] = 'S';
dc['Т'] = 'T';
dc['У'] = 'U';
dc['Ф'] = 'F';
dc['Х'] = 'H';
dc['Ц'] = 'TS';
dc['Ч'] = 'CH';
dc['Ш'] = 'SH';
dc['Щ'] = 'SHCH';
dc['Э'] = 'EE';
dc['Ю'] = 'YU';
dc['Я'] = 'YA';

$(document).ready(function(){
	// меню
	$('#main_menu dt').not('.active').next('dd').hide();
	
	$('#main_menu dt').click(function(){
		$(this).next('dd').slideToggle('fast');
	});
	
	$('a.inactive').click(function(e){
		e.preventDefault();
	});
	
	// поучения
	$('#extra').css('padding-right','18px');
	initScrollPane();
	
	$('#lection_next').click(function(e){
		e.preventDefault();
		var cur_id = $(this).attr('rel');

		$.getJSON('/lection/next/'+cur_id, function(data){
			$('#extra_container').css('top', '0').html(data.content + '<p class="author">' + data.author + '</p>');
			$('#lection_next').attr('rel', data.id);
			initScrollPane();
		});
	});
	
	// поиск
	var s = $('#search');
	var s_txt = 'поиск по сайту';
	if (s.val() == '') s.val(s_txt);
	
	s.focus(function(){
		if (s.val() == s_txt) s.val('');
	});
	
	s.blur(function(){
		if (s.val() == '') s.val(s_txt);
	});
	
	$('#search_form').submit(function(){
		if (s.val() == '') return false;
	});
	
	// буквица
	$('span.drop').each(function(){
		$(this).attr('class', 'dc letter_' + dc[$(this).text()]);
	});
	
	// пожертвования
	$('a.show_donation').fancybox({
		'scrolling'		: 'no',
		'titleShow'		: false,
		'href'			: '/donation/show/'
	});
	
	// fancybox
	$('.zoom').fancybox({
		//'overlayShow' : false,
		'overlayOpacity' : 0,
		'overlayColor': '#ffffff',
		'titlePosition' : 'inside',
		'hideOnContentClick' : true,
		'showCloseButton' : false
	});
});
