brota_l = 0
brota_r = 0

/**
 * num - показать элемент
 * pos - какую крутилку вертеть? (0 - левая, 1 - правая)
 */
function show_brota(num, pos)
{
	str = '.brota.left';
	if (pos == 1) {
		str = '.brota.right';
	}
	total_items = $(str + ' .elements-info>div').length;
	
	if (num > total_items - 1) {
		num = 0;
	}
	if (num < 0) num = total_items - 1;
	
	/*Достаем текст*/
	$(str + '>.title').html($(str + ' .elements-info>div').find('.title').eq(num).html())
	$(str + '>.button').html($(str + ' .elements-info>div').find('.button').eq(num).html())
	
	/*Обновляем информацию о текущем элементе*/
	if (pos == 0) {
		brota_l = num
	} else if (pos == 1) {
		brota_r = num
	}
	
	$(".mainpage .brota a.fb").fancybox({
		overlayOpacity: 0.5,
		overlayColor : '#000'
	})
	$(".mainpage .brota .button img").hover(function () {
		$(this).attr("src", $(this).attr("src").replace("-0", "-1"))
	}, function() {
		$(this).attr("src", $(this).attr("src").replace("-1", "-0"))
	})
}

$(function () {
	$(".mainpage .brota .arr-right").click(function() {
		if ($(this).parent().hasClass('left')) {
			show_brota((brota_l+1), 0)
		} else {
			show_brota((brota_r+1), 1)
		}
		return false
	})
	$(".mainpage .brota .arr-left").click(function() {
		if ($(this).parent().hasClass('left')) {
			show_brota((brota_l-1), 0)
		} else {
			show_brota((brota_r-1), 1)
		}
		return false
	})

	$("#catalog-right").click(function() {
		$("#catalog").animate({scrollLeft: $("#catalog").scrollLeft() + 145}, 'slow');
	})
	$("#catalog-left").click(function() {
		$("#catalog").animate({scrollLeft: $("#catalog").scrollLeft() - 145}, 'slow');
	})
	
	$("#catalog .item1").hover(function() {
		$(".item1-pic", $(this)).hide()
		$(".more", $(this)).show();
	}, function() {
		$(".item1-pic", $(this)).show()
		$(".more", $(this)).hide();
	})
	
	
	$(".item1").click(function() {
		if ($(".show", $(this)).length > 0) {
			$("#mi-bg").fadeTo("slow", 0.5)
			$("#mi-info .info").html($(".show", $(this)).html())
			$("#mi-info").show()
		}
	})
	
	$(".mi .close").click(function () {
		$("#mi-bg").hide()
		$("#mi-info").hide()
	})
	
	$(".mi .close").hover(function () {
		$(this).css("background-image", $(this).css("background-image").replace("-0", "-1"))
	}, function() {
		$(this).css("background-image", $(this).css("background-image").replace("-1", "-0"))
	})
	
	$(".mi .print").hover(function () {
		$(this).css("background-image", $(this).css("background-image").replace("-0", "-1"))
	}, function() {
		$(this).css("background-image", $(this).css("background-image").replace("-1", "-0"))
	})
	
	$(".mainpage .catalog").hover(function () {
		$(this).css("background-image", $(this).css("background-image").replace("-0", "-1"))
	}, function() {
		$(this).css("background-image", $(this).css("background-image").replace("-1", "-0"))
	})
	
	$("#content #catalog-left img").hover(function () {
		$(this).attr("src", $(this).attr("src").replace("-0", "-1"))
	}, function() {
		$(this).attr("src", $(this).attr("src").replace("-1", "-0"))
	})
	
	$("#content #catalog-right img").hover(function () {
		$(this).attr("src", $(this).attr("src").replace("-0", "-1"))
	}, function() {
		$(this).attr("src", $(this).attr("src").replace("-1", "-0"))
	})
	
	$("#content #top_nav img").hover(function () {
		$(this).attr("src", $(this).attr("src").replace("-0", "-1"))
	}, function() {
		$(this).attr("src", $(this).attr("src").replace("-1", "-0"))
	})
	
	$("#content #top_nav .pdf").hover(function () {
		$(this).css("background-image", $(this).css("background-image").replace("-0", "-1"))
	}, function() {
		$(this).css("background-image", $(this).css("background-image").replace("-1", "-0"))
	})
	
	$("#sideRight .slogan img").hover(function () {
		$(this).attr("src", $(this).attr("src").replace("-0", "-1"))
	}, function() {
		$(this).attr("src", $(this).attr("src").replace("-1", "-0"))
	})
	
	$("#mi-bg").click(function () {
		$("#mi-bg").hide()
		$(".mi").hide()
	})
	
	$(".mainpage #header .right").click(function () {
		$(".mainpage #header .carousel .wrapper").animate({scrollLeft: $(".mainpage #header .carousel .wrapper").scrollLeft() + 300}, 'slow');
	})
	$(".mainpage #header .left").click(function () {
		$(".mainpage #header .carousel .wrapper").animate({scrollLeft: $(".mainpage #header .carousel .wrapper").scrollLeft() - 300}, 'slow');
	})
	$(".mainpage #header .right").hover(function () {
		$(this).css("background-image", $(this).css("background-image").replace("-0", "-1"))
	}, function() {
		$(this).css("background-image", $(this).css("background-image").replace("-1", "-0"))
	})
	$(".mainpage #header .left").hover(function () {
		$(this).css("background-image", $(this).css("background-image").replace("-0", "-1"))
	}, function() {
		$(this).css("background-image", $(this).css("background-image").replace("-1", "-0"))
	})
	
	/*Bad...*/
	$(".mainpage .promo .link-1").hover(function() {
		$(".mainpage .promo .hover-1").show()
		$(".mainpage .promo .pic").hide()
	}, function() {
		$(".mainpage .promo .hover-1").hide()
		$(".mainpage .promo .pic").show()
	})
	$(".mainpage .promo .link-2").hover(function() {
		$(".mainpage .promo .hover-2").show()
		$(".mainpage .promo .pic").hide()
	}, function() {
		$(".mainpage .promo .hover-2").hide()
		$(".mainpage .promo .pic").show()
	})
	$(".mainpage .promo .link-3").hover(function() {
		$(".mainpage .promo .hover-3").show()
		$(".mainpage .promo .pic").hide()
	}, function() {
		$(".mainpage .promo .hover-3").hide()
		$(".mainpage .promo .pic").show()
	})
	$(".mainpage .promo .link-4").hover(function() {
		$(".mainpage .promo .hover-4").show()
		$(".mainpage .promo .pic").hide()
	}, function() {
		$(".mainpage .promo .hover-4").hide()
		$(".mainpage .promo .pic").show()
	})
	$(".mainpage .promo .link-5").hover(function() {
		$(".mainpage .promo .hover-5").show()
		$(".mainpage .promo .pic").hide()
	}, function() {
		$(".mainpage .promo .hover-5").hide()
		$(".mainpage .promo .pic").show()
	})
	$(".mainpage .promo .link-6").hover(function() {
		$(".mainpage .promo .hover-6").show()
		$(".mainpage .promo .pic").hide()
	}, function() {
		$(".mainpage .promo .hover-6").hide()
		$(".mainpage .promo .pic").show()
	})
	
	$("a.fb").fancybox({
		overlayOpacity: 0.5,
		overlayColor : '#000'
	});
	
	/*Mainpage brota's*/
	$(".mainpage .brota .arr-left").hover(function () {
		$(this).css("background-image", $(this).css("background-image").replace("-0", "-1"))
	}, function() {
		$(this).css("background-image", $(this).css("background-image").replace("-1", "-0"))
	})
	$(".mainpage .brota .arr-right").hover(function () {
		$(this).css("background-image", $(this).css("background-image").replace("-0", "-1"))
	}, function() {
		$(this).css("background-image", $(this).css("background-image").replace("-1", "-0"))
	})
	$(".mainpage .brota .button img").hover(function () {
		$(this).attr("src", $(this).attr("src").replace("-0", "-1"))
	}, function() {
		$(this).attr("src", $(this).attr("src").replace("-1", "-0"))
	})
})
