﻿$(function() {
	// Верхнее меню
	$(".top .menu li:has(ul)").hover(
		function() {
			$("ul", this).fadeIn("normal");
		},
		function() {
			$("ul", this).fadeOut("normal");
		}
	);
	
	// Catalog_Item -> Thumb_Images -> Hover
	$(".catalog_item .thumb_images a").hover(
		function() {
			$(this).parent().css("background", "url('/images/thumb_images_li.png') no-repeat");
		},
		function() {
			$(this).parent().removeAttr("style");
		}
	);
	
	// Catalog_Item -> Thumb_Images -> Click
	$(".catalog_item .thumb_images a").click(function() {
		$(".catalog_item .thumb_images li").each(function() {
			$(this).removeAttr("class");
		});
		$(this).parent().attr("class", "active");
		
		var mySrc = $(this).attr("href");
		$(".catalog_item .image img").bind("load", function() {
			$(this).fadeIn("normal");
		});
		$(".catalog_item .image img").fadeOut("normal", function() {
			$(".catalog_item .image img").attr("src", mySrc);
		});
		return false;
	});
	
	// Catalog_Item -> Всплывающее меню
	$(".catalog_item h1 a").click(function() {
		var mySrc = $(".catalog_item h1 img").attr("src");
		if(mySrc == "/images/catalog_item_arrow.png") {
			$(".catalog_item h1 img").attr("src", "/images/catalog_item_arrow_up.png")
		} else {
			$(".catalog_item h1 img").attr("src", "/images/catalog_item_arrow.png")
		}
		
		$(".dropmenu_wrapper .dropmenu").fadeToggle("slow");
		return false;
	});
	
	// Слайдер. Переключение категорий
	$(".top .slider .category a").click(function() {
		$(".top .slider .category li").each(function() {
			$(this).removeAttr("class");
		});
		$(this).parent().parent().parent().attr("class", "active");
		
		var myId = $(this).parent().parent().parent().attr("id");
		$(".top .slider .scroller .wrapper").each(function() {
			$(this).removeClass("active").hide();
		});
		$(".top .slider .scroller #" + myId).addClass("active").fadeIn("slow");
		return false;
	});
		
	// Слайдер. Левая кнопка
	$(".top .slider .left_button").click(function() {
		var leftPos = $(".top .slider .scroller .active").css("margin-left");
		leftPos = leftPos.replace("px", "");
		leftPos = parseInt(leftPos);
		if(leftPos < 80) {
			$(".top .slider .scroller .active").animate({"margin-left": "+=600px"}, 500);
		}
	});
	
	// Слайдер. Правая кнопка
	$(".top .slider .right_button").click(function() {
		var leftPos = $(".top .slider .scroller .active").css("margin-left");
		leftPos = leftPos.replace("px", "");
		leftPos = parseInt(leftPos);
		var wrapperWidth = 0;
		$(".top .slider .scroller .active .item").each(function() {
			wrapperWidth += $(this).width() + 30;
		});
		var scrollerWidth = $(".top .slider .scroller").width();
		if(wrapperWidth + leftPos > scrollerWidth + 80) {
			$(".top .slider .scroller .active").animate({"margin-left": "-=600px"}, 500);
		}		
	});
});





