$(document).ready(function() {

    // Подсвечиваем текстовые ссылки, когда курсор на фотке с такой же ссылкой
    $(".wrap-href a").hover(
            function() {
                $(this).parents(".wrap-href").addClass("hover");
            },
            function() {
                $(this).parents(".wrap-href").removeClass("hover");
            }
            );


    // Поднимаем фотки в воздух и показываем доп. параграф, на индексных страницах услуг
    if ($(".content-row").hasClass("services-sfx")) {
        $(".services-item-block-wrap").hover(
                function() {
					if (!$(this).parents(".services-item-block").hasClass(".disabled-services-item-block")) {
                        $(this).find("img").stop().animate({"top": "-20px"}, 100);
                        $(this).children(".note").stop().animate({"color": "#000"}, 200);
                    }
                },
                function() {
                    if (!$(this).parents(".services-item-block").hasClass(".disabled-services-item-block")) {
                        $(this).find("img").stop().animate({"top": "0px"}, 100);
                        $(this).children(".note").stop().animate({"color": "#fff"}, 200);
                    }
                }
			);
	    }


    // Растягиваем ленту цветов до правого предела
//    if ($(".content-row").hasClass("serpantin-services-text")) {
//        function flex_lenta() {
//            var body_width = $("body").width();
//            var min_max_width = $(".min-max").width();
//            var lenta_left = $(".lenta").offset().left;
//            if (body_width < min_max_width) {
//                var lenta_width = min_max_width - lenta_left + 40;
//            } else {
//                var lenta_width = body_width - lenta_left + 40;
//            }
//            $(".lenta").css("width", lenta_width);
//        }
//
//        flex_lenta();
//
//        $(window).resize(function() {
//            flex_lenta();
//        });
//    }

    // Рисуем линии (сетки) на всю ширину экрана для исторических блоков. Скрываем блоки «до мультимедийной эры»
    if ($(".content-row").hasClass("about-history")) {
        function history_lines() {
            var history_block = $(".history-block");
            var history_container = $(".history-container");
            for (i = 0; i < history_block.length; i++) {
                if (history_block.eq(i).position().left == 0) {
                    var line_top = history_container.position().top + history_block.eq(i).position().top + 80;
                        $(".history-one-column").before("<div class='history-line' style='top: " + line_top + "px;'></div>");
                }
            }
        }

        history_lines();

        $(window).resize(function() {
            $(".history-line").remove();
            history_lines();
        });

        $("#before-multimedia").click(function() {
            if ($(this).hasClass("bm-buble")) {
                $(this).removeClass("bm-buble");
                $(".history-container").addClass("bm-history-container");
                $(".history-line").remove();
                history_lines();
            } else {
                $(this).addClass("bm-buble");
                $(".history-container").removeClass("bm-history-container");
                $(".history-line").remove();
                history_lines();
            }
        });
    }

    // Показываем баблы в тайм-лайне в портфолио и отодвигаем от края крайний правый флаг
    if ($(".content-row").hasClass("portfolio")) {
        $(".multimedia-point").mouseover(function(){
            if ($(this).hasClass("mega-multimedia-point")) {
				$(this).css({"z-index": "100"});
			}
			$(this)
                    .addClass("focus")
                    //.children(".buble").fadeIn("fast")
					//.children(".bull").animate({fontSize: "30px", left: "-2px", top: "-10px"}, 50);
            $(".multimedia-point").not(this)
                    .removeClass("focus")
                    //.children(".buble").fadeOut("fast");
					//.children(".bull").animate({fontSize: "24px", left: "-1px", top: "-7px"}, 50);
			
        });
		function moveFlag () {
			var timelineWidth = $(".portfolio-timeline").width();
			var flag = $(".megaflag:last p");
			var flagT = $(".megaflag:last .text")
			var flagLeft = flag.parents(".multimedia-point").position().left - 30;
			var flagWidth = flag.children("a").width();
			var overflow = flagLeft + flagWidth - timelineWidth + 20;
			if (overflow > 0) {
				flagT.css({"margin-left": - overflow + "px"});
			} else {
				flagT.css({"margin-left": "0"});
			}
		}
		moveFlag();
		$(window).resize(function(){
			moveFlag();
		});
    }

	if ($(".right-bottom").height()) {
		function moveColumn () {
			var rightColumn = $(".right-column");
			var rightBottom = $(".right-bottom");
			var rightColumnHeight = rightColumn.height();
			var rightBottomTop = rightBottom.position().top;
			var rightBottomHeight = rightBottom.height();
			var picstripHeight = $(".picstrip").height();
			rightColumn.css({"padding-bottom": rightBottomHeight + 30 + "px"});
		}
		moveColumn();
		$(window).resize(function(){
			moveColumn();
		});
		
	}
	
	if ($(".ps-pic").width()) {
		function resizeStop() {
			if( $(".two-columns").width()*.693 < $(".ps-pic").width() ) {
				$(".left-column").css({"width": $(".ps-pic").width()});
			} else {
				$(".left-column").removeAttr("style");
			}
		}
		resizeStop();
		$(window).resize(function(){
			resizeStop();
		});
	}
  

});
