$(document).ready(function () {

//Главная

    //Делаем миниатюы полупрозрачными
	$('.opacityhover').animate({
		"opacity": "0.5"
	});
    $('.opacityhover').hover(
        function () {
            $(this).stop(true).animate({
                "opacity": "1"
            });
        },
        function () {
            $(this).stop(true).animate({
                "opacity": "0.5"
            });
        }
    );
	
	
    //Делаем большую стрелку кликабельной
	$('#bg_apartments').after("<div class='miniatures-click'> </div>");
    $('#apartments .miniatures-click').click(
        function () {
            var apartments_url = $('#apartments h2 a').attr("href");
            window.open(apartments_url, "_self");
        }
    );

    //Делаем карточки объектов кликабельными
//    $('.item_card').click(
//        function () {
//            var imgresized_url = $(this + '.h3_wrap .h3_wrap2 h3 a').attr("href");
//            window.open(imgresized_url, "_self");
//        }
//    );
	
	
    //Настраиваем ссылку автора
    $('div#studio').click(
        function () {
            var studio_url = $(this + 'p a').attr("href");
            window.open(studio_url);
        }
    );
	$('#studio p').animate({
		"opacity": "0"
	});
    $('#studio').hover(
        function () {
            $('#studio, #studio p').stop(true).animate({
                "opacity": "1"
            }, 700);
        },
        function () {
            $('#studio, #studio p').stop(true).animate({
                "opacity": "0.5"
            }, 3000);
        }
    );
	
	
//Каталог 

	//Настраиваем чередование строк для каталога
	$('.item_container:first-child').addClass('item_container-first');
	$('.item_container:nth-child(odd)').addClass('item_container-odd');
	$('.item_container:nth-child(even)').addClass('item_container-even');
	
	//Ширина p.item_card_info	
	$('.item_card').each(function(){
	  var $itemcard=$(this);
	  var cardwidth = $itemcard.outerWidth()
	  var cardheight = $itemcard.outerHeight()
	  $itemcard.children('.item_card_info').css('width', cardwidth);
	  $itemcard.next('.item_info').css('left', cardwidth+130);
	  $itemcard.parent('.item_container').css('height', cardheight);
	  $('.item_bg').css('left', cardwidth+90);
	});
	
	//Устанавливаем положение .item_info в зависимости от ширины картинок карточки
	
	
	//Рамка
	var framecontainer = '<div class="frame-container"><div class="frame-a frame-corner"></div><div class="frame-b frame-sidehor"></div><div class="frame-c frame-corner"></div><div class="frame-d frame-sidevert"></div><div class="frame-e frame-corner"></div><div class="frame-f frame-sidehor"></div><div class="frame-g frame-corner"></div><div class="frame-h frame-sidevert"></div><div class="frame-inside"></div></div>';
	$('.tobeframed').after(framecontainer);
	
	$('.tobeframed').each(function(){
	  var $this=$(this);
	  var frameposition = $this.offset()
	  $this.next('.frame-container').offset(frameposition, frameposition).css('margin', '-20px');
	  var framezindex = $this.css('z-index')
	  $this.next('.frame-container').css({
		  zIndex: framezindex - 1
	  });
	  var framewidth = $this.outerWidth() + 40
	  var frameheight = $this.outerHeight() + 40
	  $this.next('.frame-container').css('width', framewidth);
	  $this.next('.frame-container').css('height', frameheight);
	});
	
	$('.frame-inside').each(function(){
	  var $this2=$(this);
	  var framesidehor = $this2.width()
	  $this2.siblings('.frame-sidehor').css('width', framesidehor);
	  var framesidevert = $this2.height()
	  $this2.siblings('.frame-sidevert').css('height', framesidevert);
	});
	
	
// text
	
	//Настраиваем положение ссылок на разделы страницы. Через CSS пришлось бы таблицы мучить, так как h2 у нас может быть с разрывом строки.
	$('#antalia_text .h3_links').each(function(){
	  var $h3links=$(this);
	  var $h3linksa=$('.h3_links a').first();
	  var h3linksheight = $h3linksa.height() + 1
	  var $h2=$('h2');
	  var h2height = $h2.height()
	  var h3linkstop = h2height - h3linksheight
	  $h3links.css('top', h3linkstop);
	});
	
	$('#antalia_text .h3_links a:last').addClass('noborder');
	
	$('#antalia_text #text').each(function(){
	  var $text=$(this);
	  var $heads=$('#heads h2');
	  var headsheight=$heads.height()
	  $text.css('top', headsheight + 71);
	});
	
	$('#antalia_text #copyrights').each(function(){
	  var $copyrights=$(this);
	  var $heads=$('#heads h2');
	  var headsheight=$heads.height()
	  $copyrights.css('marginTop', headsheight + 161);
	});


// item

	//Отодвигаем ссылки на подразделы страницы об объекте от названия объекта
	$('#antalia_item_a, #antalia_item_b, #antalia_item_c').addClass('antalia_item_page');
	$('.antalia_item_page .head-info').each(function(){
	  var $this=$(this);
	  var h2allheight=$('.antalia_item_page #heads h2').height();
	  var h2allwidth=$('.antalia_item_page #heads h2').width();
	  var thisheight=$this.height();
	  $this.css({
	  	'left': 20,
	  	'top': h2allheight - thisheight + 4
	  });
	  $('.antalia_item_page .head-info p.item_numbers').css({
		'position': 'absolute',
	  	'left': h2allwidth
	  });
	  $('.antalia_item_page .head-info p.item_numbers_pre').animate({
		'top': -24
	  }, 0);
	  $('.antalia_item_page .head-info p.item_numbers_next').animate({
		'top': +24
	  }, 0);
	});
	
	//Располагаем болк комнат относительно верха страницы
	var h2asecondtheight=$('.antalia_item_page .h2a_second').height();
	$('.antalia_item_page #rooms').css({
	  'marginTop': 156 + h2asecondtheight
	});
	$('.antalia_item_page #leftRight').css({
	  'top': 236 + h2asecondtheight
	});
	
	
// item_b
	
	 $('#leftRight .jcarousel-prev').hide();
	 $('#leftRight .jcarousel-next').click(function (){
		$('#leftRight .jcarousel-prev').show(700);
	 });

	//Настраиваем чередование ячеек
	$('#rooms li:nth-child(odd)').addClass('roomscarousel-odd');
	
});
