$(function() {
	// определяем внешние ссылки
	$("#content a[href^='http://']:not([href^='http://" + location.host + "'])" , "").addClass("external");
	$("#content a[href^='https://']:not([href^='https://" + location.host + "'])").addClass("external");
	// нечётные табличные ряды
	$("tr:odd").addClass("odd");
	// выключка цены вишлиста
	$("#wishlist td:nth-child(2)").css("text-align", "right");
	// чистим лишние границы таблицы
	$("#wishlist th:first-child").css("border-left", "none");
	$("#wishlist td:first-child").css("border-left", "none");
	// определяем нечётные сертефикаты
	$("#bitrix p:odd").css("text-align", "right");
	// сноски
	$("hr ~ *").css("font-size", ".8em");
	// заменяем <hr />
	$("hr").wrap("<div class='hr'></div>").remove();
	// класс для превьюх в галерее
	$(".row").addClass("preview");
	// размеры превьюх
	$(".row img").attr("width", "100px").attr("height", "100px");
	// лайкалка
	$("#like").css("float", "right").append("<span style='position: relative; top: -2px;' class='yashare-auto-init' data-yashareL10n='ru' data-yashareType='none' data-yashareQuickServices='blogger,delicious,facebook,gbuzz,greader,liveinternet,linkedin,lj,moikrug,moimir,myspace,odnoklassniki,twitter,vkontakte,yaru,yazakladki'></span>");
	// тайтлы, которые не задаются в явном виде
	$("h4 a").attr("title", function() {
		return "Метка «" + this.text + "»";
	});
	$(".comment-reply-link").attr("title", "Ответить");
	$("a#cancel-comment-reply-link").attr("title", "Отменить ответ");
	$(".comment-author a").attr("title", "Перейти на сайт автора комментария");
	// ховер для <h1>
	$("h1 a").hover(
		function() {
			$(this).stop().animate({marginLeft: "4em"}, {duration: 400, easing: "easeInOutBack"});
		},
		function() {
			$(this).stop().animate({marginLeft: "0"}, {duration: 400, easing: "easeInOutBack"});
		}
	);
	// обёртка для заголовка секции "оборудования"
	$("#equipment h5").wrapInner("<span></span>");
	// отобразить/скрыть секцию + ховер для заголовка сеции + тайтл
	$("#equipment h5 span").attr("title", "Отобразить/скрыть секцию").hover(
		function() {
			$(this).css("color", "#903");
		},
		function() {
			$(this).css("color", "#069");
		}
	).toggle(
		function() {
			$(this).parent().next().show("slow");
		},
		function() {
			$(this).parent().next().hide("slow");
		}
	);
	// подсветка меню в непредусмотренных случаях
	$(".tag li:contains('Метки')").addClass("current-menu-item");
	// ховер для разделов портфолио
	$(".portfolio-section img").hover(
		function() {
			$(this).stop().animate({"opacity": "0"}, 400);
		},
		function() {
			$(this).stop().animate({"opacity": "1"}, 400);
		}
	);
	// ховер для превьюх
	$(".preview img").hover(
		function() {
			$(this).stop().animate({
				borderTopColor:    "#b8b8b8",
				borderRightColor:  "#b8b8b8",
				borderBottomColor: "#b8b8b8",
				borderLeftColor:   "#b8b8b8"
			}, 450);
		},
		function() {
			$(this).stop().animate({
				borderTopColor:    "#e1e1e1",
				borderRightColor:  "#e1e1e1",
				borderBottomColor: "#e1e1e1",
				borderLeftColor:   "#e1e1e1"
			}, 450);
		}
	);
	// класс для разделов портфолио
	$(".portfolio-section img:even").addClass("fade");
	// нормальное отображение элементов списка
	$("#content li").wrapInner("<div class='normal-li'></div>");
	// валидация формы комментирования
	var errorContainer = $("<div class='mark' style='margin: 0 0 14px'>&mdash;&nbsp;Пожалуйста, проверьте обязательные поля!</div>").appendTo("#commentform").hide();
	$("#commentform").validate({
		rules: {
			author: "required",
			email: {
				required: true,
				email: true
			},
			comment: "required"
		},
		errorContainer: errorContainer,
	});
	$.validator.messages.required = "";
	$.validator.messages.email = "";
	// закруглённые углы
	$(".corner").append("<img class='corner-common corner-tl hide' src='/wp-content/themes/clean_and_simple/images/corner-tl.png' alt='' /><img class='corner-common corner-tr hide' src='/wp-content/themes/clean_and_simple/images/corner-tr.png' alt='' /><img class='corner-common corner-bl hide' src='/wp-content/themes/clean_and_simple/images/corner-bl.png' alt='' /><img class='corner-common corner-br hide' src='/wp-content/themes/clean_and_simple/images/corner-br.png' alt='' />");
	// класс для pdf
	$("a[href*=pdf]").addClass("pdf");
	// fancyBox
	$(".preview a").fancybox({
		"padding"     : 5,
		"fitToView"   : false,
		"fixed"       : false,
		"openEffect"  : "elastic",
		"closeEffect" : "elastic",
		"openSpeed"   : "normal",
		"closeSpeed"  : "normal",
		"nextEffect"  : "fade",
		"prevEffect"  : "fade",
		"nextSpeed"   : "fast",
		"prevSpeen"   : "fast",
		helpers : {
			title : {
				type : "inside"
			},
			overlay : {
				opacity : 0.9
			}
		}
	});
});
