function BuildPage(){
//	Убираем фокус с кнопок в IE
	if (($.browser.msie && $.browser.version == 6) || ($.browser.msie && $.browser.version == 7)) {
		$('input:first').focus();
	};
//	Скрипт блока цитат
	if ($('#citation')) {
		var textH=$('#citation > .contents:first > p:first').height();
		if (textH<108) {
			var textP=(108-textH)/2+'px 0px';
			$('#citation > .contents:first > p:first').css('padding',textP)
		}
	};
//	Скрипты блока контента
	if ($('#main-content')) {
//		зебра блоков контента
		$('#main-content > .content:odd').addClass('odd');
//		маргины картинок в тексте
		$("#main-content > .content > img[align='left']").css('margin-left','0px');
		$("#main-content > .content > img[align='right']").css('margin-right','0px');
//		выравнивание высоты блоков популярных серий
		$('#main-content > .content > .popular').each(function(i){
			var	itemH=0;
			$(this).find('.item').each(function(k){if (itemH<$(this).height()) {itemH=$(this).height()}});
			$(this).find('.item').height(itemH)
		});
//		расстановка по местам и выравнивание блоков персонажей
		$('#main-content > .content > .character').each(function(i){
			$(this).find('.item:even').addClass('even');
			$(this).find('.item:odd').addClass('odd');
			$(this).find('.item').each(function(k){
				if ($(this).hasClass('odd')) {
					var	itemL=$('#main-content > .content > .character').eq(i).find('.item').eq(k-1),
							itemR=$(this),
							itemHleft=itemL.height(),
							itemHright=itemR.height(),
							itemW=363,
							difference=60,
							itemH=0;
					if (itemHleft>itemHright) {
						itemL.width(itemW+difference);
						itemR.width(itemW-difference)
					}
					else {
						itemL.width(itemW-difference);
						itemR.width(itemW+difference)
					};
					if (itemH<itemL.height()) {itemH=itemL.height()};
					if (itemH<itemR.height()) {itemH=itemR.height()};
					itemL.height(itemH);
					itemR.height(itemH)
				}
			})
		});
		RebuildFooter();
		contentResize(0);
	};
//	Скрипт галереи
	if (document.getElementById('gallery') || document.getElementById('triggers')) {
		var	itemBor=12,
				scrollH=0;
		$('body').append('<div class="overlay" id="big-photo"></div>');
		$('#big-photo').append('<a class="prev">назад</a>');
		$('#big-photo').append('<a class="next">вперед</a>');
		$('#big-photo').append('<div class="info"></div>');
		$('#big-photo').append('<img class="progress" src="img/loading.gif" />');
		if (document.getElementById('gallery')) {
			$('#gallery img').css('left','50%');
			$('#gallery .item').each(function(i){
				var	Mleft=-Math.floor($(this).find('img:first').width()/2)+'px',
						itemH=$(this).find('img:first').height();
				$(this).find('img:first').css('margin-left',Mleft);
				$(this).height(itemH);
				if (scrollH<itemH+itemBor) {scrollH=itemH+itemBor}
			});
			$('#gallery .scrollable:first').height(scrollH);
			$('#gallery .scrolling:first').height(scrollH);
			contentResize(0);
			$('#gallery .scrollable:first').scrollable({size:4}).find('a').overlay({
				target: '#big-photo',
				expose: '#111',
				closeOnClick: false,
				onClose: function() {clearBigPhoto()}
			}).gallery({
				disabledClass: 'inactive',
				template: '<strong>${title}</strong> <span>Картинка ${index} из ${total}</span>',
				speed: 100 
			})
		};
		if (document.getElementById('triggers')) {
			$('#triggers a').overlay({
				target: '#big-photo',
				expose: '#111',
				closeOnClick: false,
				onClose: function() {clearBigPhoto()}
			}).gallery({
				disabledClass: 'inactive',
				template: '<strong>${title}</strong> <span>Картинка ${index} из ${total}</span>',
				speed: 100 
			})
		}
	};
	RebuildFooter();
};
function RebuildFooter() {
	if (($.browser.msie && $.browser.version == 6) || ($.browser.msie && $.browser.version == 7)) {
		$('#footer').hide(0);
		$('#footer').show(0);
	};
};
function contentResize(Pad) {
	$('#main-content').removeAttr('style');
	var	hLayout=$('#layout').height(),
			hContent=$('#main-content').height(),
			space=270,
			hContentNew=hLayout-space-Pad;
	if (hContent<hContentNew) {$('#main-content').height(hContentNew)}
};
function clearBigPhoto(){
	$('#img').remove();
	$('#big-photo').removeAttr('style');
	$('#big-photo .close').removeAttr('style');
	$('#big-photo .progress').removeAttr('style');
};
$(document).ready(function(){BuildPage();});
$(window).resize(function(){contentResize(0);});


