/* Background fix */

$(function(){
	var bgImage = $('div.background:first img:first');
	
function resizeBg() {
	
	bgImage.css({
	height: $(window).height()-$('#bottom').height() + 'px',
	width: 'auto',
	top: 0+'px',
	});
		
	if (bgImage.width() < $(window).width()) {
	bgImage.css({
	height: 'auto',
	width: $(window).width() + 0 + 'px',
	});
	}


	if (bgImage.height() > $(window).height()-$('#bottom').height()) {
	bgImage.css({
	top: ((($(window).height()-$('#bottom').height()) - bgImage.height())/2) + 'px',
	height: 'auto',
	});
	}
	
	}
	
	
	
	$(window).resize(function(){
		resizeBg();
	});
	bgImage.load(function(){
		resizeBg();
	});
	resizeBg();
});






//Выставляем высоты заглушкам

jQuery(document).ready(function(){

});



//Высоты окон и позиционирование объектов при изменении размеров окна и прокрутке


function resizeViewport() {

if($('#menu_bar_major').height()<$(document).height()-$('#bottom').outerHeight()){
$('#zaglushka_major_right').height($(document).height()-$('#menu_bar_major').height()-$('#bottom').outerHeight());
};



$('.zaglushki').css({
	'left': (0 - $(window).scrollLeft())+'px',
	'top': (0 - $(window).scrollTop())+'px',
	'width': ($(document).width()) + 'px',
});


$('.zaglushka_left').css({
	'height': 10000+'px',
});


$('#bottom').css({
	'left': (0 - $(window).scrollLeft())+'px',
	'width': ($(document).width()) + 'px',
});


if($(window).width() > 1064) {
$('#bottom').css({
	'width': ($(window).width()+22) + 'px',
});
};

}





$(window).load(function() {
resizeViewport();
});


$(window).scroll(function() {
resizeViewport();
});


$(window).resize(function() {
resizeViewport();
});






//Меню с журналами - всплывающие картинки

jQuery(document).ready(function(){
	$('#journals_projects h3').hover(function(){$(this).next().fadeIn(250)},
	function(){$(this).next().fadeOut(250)
	}).next().hide();
});

/*
$(window).click(function(){
	var sel_tab_var3 = $.cookie("sel_tab");
	alert(sel_tab_var3);
});
*/

//Табы - главное меню, появление объектов

$(document).ready(function() {

var sel_tab_var_core = $.cookie("sel_tab");

	
$("#menu_bar_major").tabs({
	
	cookie: { expires: 1 },

	selected: sel_tab_var_core,

	show: function(event, ui) {
		
	//МОИ ДОБАВКИ - управление цветом заглушки и запоминание в куке выбранного таба
	$('#zaglushka_major_right').css({
		'background-color': '#fff',
	});

	var sel_tab_var = $( "#menu_bar_major" ).tabs( "option", "selected" );
    $.cookie("sel_tab", sel_tab_var);
	//МОИ ДОБАВКИ - конец управления цветом заглушки



	var lastOpenedPanel = $(this).data("lastOpenedPanel");

	if (!$(this).data("topPositionTab")) {
		$(this).data("topPositionTab", $(ui.panel).position().top)
		}         

	//Dont use the builtin fx effects. This will fade in/out both tabs, we dont want that
	//Fadein the new tab yourself            
	
	$(ui.panel).hide().fadeIn(250);

	if (lastOpenedPanel) {

	// 1. Show the previous opened tab by removing the jQuery UI class
	// 2. Make the tab temporary position:absolute so the two tabs will overlap
	// 3. Set topposition so they will overlap if you go from tab 1 to tab 0
	// 4. Remove position:absolute after animation
	lastOpenedPanel
    .toggleClass("ui-tabs-hide")
    .css("position", "absolute")
    .css("top", $(this).data("topPositionTab") + "px")
    .fadeOut(250, function() {
    	$(this)
       	.css("position", "");
	
	//МОИ ДОБАВКИ - управление заглушкой 
	resizeViewport();
	//МОИ ДОБАВКИ закончились
	
    });

            }

            //Saving the last tab has been opened
            $(this).data("lastOpenedPanel", $(ui.panel));

        }

    });

});








//Закладки-табы в основном содержании

$(document).ready(function() {



$(".small_tabs").tabs({
	
	cookie: { expires: 1 },
	
	show: function(event, ui) {
	resizeViewport();
	}
	
    });
});





//Выезжающие вниз содержания новостей

jQuery(document).ready(function(){
	$('.expandable_head_article').click(function() {
	$(this).next().slideToggle(250);
	
	$(this).find("th.sign").toggleClass('plus_sign_smaller').toggleClass('minus_sign_smaller');

	return false;
	}).next().hide();
});



//Выезжающие вниз описания журналов для рекламодателей

jQuery(document).ready(function(){
	$('.journal_header').click(function() {
	$(this).next().slideToggle(250);

	return false;
	}).next().hide();
});



