$(document).ready(function() {
	
	var $activeMenuItem = $(".b-submenu").children("ul").children("li.active");
	var $activeMenuSubItem = $activeMenuItem.children("ul").children("li.active");
	if ($activeMenuSubItem.length > 0) {
		$activeMenuItem.removeClass("active");
	}
	
	/**
	 * Remove top header margins at the very begining of content area <
	 */
	
	$(".b-body-content > h2:nth-child(1), .b-body-content > h3:nth-child(1)").addClass("first-header");
	
	/**
	 * Remove top header margins at the very begining of content area >
	 */
	
	/**
	 * Add Fancybox plugin to image-to-image links <
	 */
	 
	$("a.img-to-img, .b-carousel-container a, .b-photoalbum-item, .b-portfolio-item a").fancybox({
		'padding'		: 20,
		'overlayOpacity': 0.7,
		'overlayColor'	: '#000'
	});
	
	/**
	 * Add Fancybox plugin to image-to-image links >
	 */
	
	/**
	 * Carousel <
	 */
	 
	larr = $(".b-carousel-larr"); // Left arrow
	rarr = $(".b-carousel-rarr"); // Right arrow
	
	carouselContainer = $(".b-carousel-container"); // Carousel wrapper with overflow property
	carouselPane = $(".b-carousel-pane"); // Carousel pane to move
	
	carouselItemWidth = 83; // Item width
	carouselStepNumber = 10; // Item number for a view
	carouselPaneNumber = carouselPane.find(".b-carousel-item").length; //Item number at page 
	
	carouselPaneWidth = carouselItemWidth * carouselPaneNumber; // Carousel pane width
	carouselStepWidth = carouselItemWidth * carouselStepNumber; // Step width

	carouselPane.css('width', carouselPaneWidth + 'px');
	
	rarr.click(function () {
 		carouselPaneLeft = carouselPane.css('left').slice(0, -2);
		
		carouselPaneLeft -= carouselStepWidth;
		if ((0 - carouselPaneLeft) == carouselPaneWidth) {
			carouselPane.animate({"left": "0px"}, 500);		
			return false;
		}
		if ((0 - carouselPaneLeft + carouselStepWidth) > carouselPaneWidth) carouselPaneLeft = (0 - carouselPaneWidth + carouselStepWidth);
		carouselPaneLeft += "px";
		carouselPane.animate({"left": carouselPaneLeft}, 500); 
		return false;
	});
	
	larr.click(function () {
		carouselPaneLeft = parseInt(carouselPane.css('left').slice(0, -2));
		if (carouselPaneLeft == 0) {
			carouselPaneLeft = 0 - carouselPaneWidth + carouselStepWidth;
			carouselPaneLeft += "px";
			carouselPane.animate({"left": carouselPaneLeft}, 500);		
			return false;
		}
		
		carouselPaneLeft += carouselStepWidth;
		if ((carouselPaneLeft) > 0) carouselPaneLeft = 0;
		carouselPane.animate({"left": carouselPaneLeft}, 500);
		return false;
	});
	 
	 
	/**
	 * Carousel >
	 */ 
	 
	/**
	 * Switcher <
	 */ 

	$(".b-switcher-primary a").click(function () {
		destination = $(this).attr('href').slice(1);
		$(".b-switcher-primary a").removeClass("active");
		$(this).addClass("active");
		
		$(".b-switcher-content .b-switcher-secondary-content").animate({"opacity": 0}, 200, function () {
			$(".b-switcher-content .b-switcher-secondary-content").hide();
			
			destination2 = $(".b-switcher-" + destination + " .b-switcher-secondary a.active").attr('href').slice(1);
			$(".b-switcher-secondary-" + destination2).show();
			
			
			$(".b-switcher-content .b-switcher-" + destination).show().animate({"opacity": 1}, 200);
		});
		return false;
	});
	
	$(".b-switcher-secondary a").click(function () {
		destination = $(this).attr('href').slice(1);
		$(this).parent().parent().find("a").removeClass("active");
		$(this).addClass("active");
		
    
    isIE='\v'=='v';
    
    
    if (isIE) {
      $(this).parent().parent().parent().find(".b-switcher-item").hide();
      $(".b-switcher-secondary-content .b-switcher-secondary-" + destination).show();    
    } else {
      $(this).parent().parent().parent().find(".b-switcher-item").animate({"opacity": 0}, 200, function () {
        $(this).parent().parent().parent().find(".b-switcher-item").hide();
        $(".b-switcher-secondary-content .b-switcher-secondary-" + destination).show().animate({"opacity": 1}, 200);
      }); 
    }

		
		return false;
	});
	 
	/**
	 * Switcher >
	 */ 	 
	 
	/**
	 * Login form <
	 */
/*	
	$(".b-navigation-login a").fancybox({
		'titlePosition'		: 'inside',
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'padding'			: 20,
		'overlayOpacity'	: 0.7,
		'overlayColor'		: '#000',
		'titleShow'			: false
	});*/
	
	/**
	 * Login form >
	 */
	 
	/**
	 * Search form <
	 */
	 
	$("..b-header-search form input").focus(function () {
		if($(this).attr("value") == 'Поиск') $(this).attr("value", "");
		$(this).addClass("focus");
	});
 
	$("..b-header-search form input").blur(function () {
		if($(this).attr("value") == '') $(this).attr("value", "Поиск").removeClass("focus");
	}); 
	 
	/**
	 * Search form >
	 */
	 
	/**
	 * Drop-down <
	 */
	 
	$(".b-navigation-menu > ul > li").hover(function () {
		$(this).find("ul").slideDown("fast");
	}, 
	function () {
		$(this).find("ul").slideUp("fast");
	}); 
	 
	/**
	 * Drop-down >
	 */ 
	 
	/**
	 * FAQ <
	 */ 	 
	
	$("dl.b-faq dd").hide();
	
	$("dl.b-faq dt a").toggle(function () {
		$(this).parent().parent().next("dd").slideDown(100);
		return false;
	}, function () {
		$(this).parent().parent().next("dd").slideUp(150);
		return false;
	});
	
	/**
	 * FAQ >
	 */ 	 
	 
	/**
	 * Zebra <
	 */
	
	$("table.zebra tr:even").addClass("even");
	$("table.zebra th").parent("tr").removeClass("even");
	
	$("table.zebra tr").hover(function () {
		$(this).addClass("zebra-hover");
		$(this).find("th").parent("tr").removeClass("zebra-hover");
	}, function () {
		$(this).removeClass("zebra-hover");
	});
	
	/**
	 * Zebra >
	 */	 
	 
	/**
	 * Catalog <
	 */
	
	$(".b-bottom-sale a").fancybox({
		'width'				: '80%',
		'height'			: '90%',
        'autoScale'     	: false,
        'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe',
		'titleShow'			: false
	});
	 
	/**
	 * Catalog >
	 */ 
	 
	/**
	 * Product photo switcher <
	 */
	 
	$(".b-product-photo-thumb a").click(function () {
		$(".b-product-photo-thumb a").removeClass("active");
		$(this).addClass("active");
		largeImg = $(".b-product-photo-big img");
		dest = $(this).attr('href');
		var image = new Image();
		image.onload = function () {
			largeImg.animate({opacity: 0}, 300, function () {
				largeImg.attr('src', dest);
				largeImg.animate({opacity: 1}, 300);
			});
			
		};
		image.src = dest;
		return false;
	}); 
	 
	/**
	 * Product photo switcher >
	 */ 
	
	$("input:submit").removeAttr("name");
			
});		
