﻿$(document).ready(function(){

	// Прижимаем футер книзу	
	
	setInterval( "checkPageHeight()", 50 );
	
	// Делаем колонки со списками моделей в каталоге одинаковой высоты

	//setTimeout('$(".models div").each(function(){ $(this).height($(this).parent().height()); });', 1000 );

	// делаем ссылки на статьи и их фотографии одним целым
	
	$(".article-photo").hover(function(){
		$(this).siblings("div").find("a").addClass("hover");
	}, function(){
		$(this).siblings("div").find("a").removeClass("hover");
	});
	
	// делаем ссылки в блоках-предложениях одним целым
	
	$(".offer h3 a, .offer-photo img, .offer-link a").hover(function(){
		$(this).parentsUntil(".offer").parent().eq(0).addClass("offer-hover");
	}, function(){
		$(this).parentsUntil(".offer").parent().eq(0).removeClass("offer-hover");
	});
	
	// оживляем карусель превьюшек в галерее

	if ( $(".preview").length )
		$(".preview").jCarouselLite({
			speed: 300,
			visible: 2,
			circular: false,
			easing: "jswing",
			btnPrev: ".left-arrow", 			
			btnNext: ".right-arrow",
			afterEnd: function(a) {
				if ( $(".preview li").index(a.eq(0)) == 0 )
					$(".left-arrow").addClass("dead-arrow");
				else
					$(".left-arrow").removeClass("dead-arrow");
				
				if ( $(".preview li").index(a.last()) == $(".preview li").length - 1 )
					$(".right-arrow").addClass("dead-arrow");
				else
					$(".right-arrow").removeClass("dead-arrow");
			} 
		});
	
	// обрабатываем клики по превьюшкам
	
	$(".preview img").click(function(){
		$(".preview img.selected").removeClass("selected");
		$(this).addClass("selected");
		$(".big-photo").attr("src", $(this).attr("src").replace("small", "big"));
		sel_img = $(this).attr("alt");
		
	});

	// делаем ссылки в тизере товара единым целым
	
	$(".small-item a img").hover(function(){
		$(this).parent().parent().addClass("small-item-hover");
	}, function(){
		$(this).parent().parent().removeClass("small-item-hover");
	});
	
});


function checkPageHeight()
{// прижимает футер книзу
	
	var wnd = document.documentElement.clientHeight;
	var site = $(".layout").height();

	if ( site < wnd )
		$("#page-height-regulator").height( $("#page-height-regulator").height() + wnd - site );
	else
		if ( site > wnd )
			$("#page-height-regulator").height(0);
}

