var options = { path: '/', expires: 50 }; // cookie options = path and expires in 50 days

jQuery(document).ready(function(){
	jQuery('a.fancybox').fancybox({'overlayShow': true, 'zoomOpacity': true }); 
});


//jQuery(function(){
jQuery(document).ready(function(){

// left category menu code	
	jQuery('.tree_menu_subchild li').addClass('show');
	jQuery('.tree_menu_subchild li:nth-child(3)').nextAll().removeClass('show').addClass('hide_show').hide();
	
	jQuery('.tree_menu_subchild').append('<li class="toggle toggle_to_show"><span class="js">всі розділи</span></li>');
	jQuery('.toggle').prev('.show').next().remove();

	
	jQuery('.toggle').click(function() {
		if(jQuery(this).hasClass('toggle_to_show')){
			var curId = jQuery(this).parent().attr('id');
			jQuery.cookie(curId, '1', options);
			
			jQuery(this)
			.removeClass('toggle_to_show').addClass('toggle_to_hide')
			.children().empty().prepend('приховати')
			.parent().prevAll('.hide_show').slideDown('normal');
			
		}else{
			var curId = jQuery(this).parent().attr('id');
			jQuery.cookie(curId, '0', options);
			
			jQuery(this)
			.removeClass('toggle_to_hide').addClass('toggle_to_show')
			.children().empty().prepend('всі розділи')
			.parent().prevAll('.hide_show').slideUp('normal');

		};
	});
	
	
	jQuery.cookie('test_cookie', 1, options);
	
	if(jQuery.cookie('test_cookie')==1){
		jQuery('.tree_menu_subchild').each(function(index){
			var curId = jQuery(this).attr('id');
			if(jQuery.cookie(curId)=='1'){
				jQuery(this).children('.hide_show').show();
				jQuery(this).children('.toggle').removeClass('toggle_to_show').addClass('toggle_to_hide')
				.children().empty().prepend('приховати');
			}else{
				
			};
		});
	};
// left category menu code end
	
// tab_menu code
	// reclick tab spans
	jQuery('.tab_menu span').click(function() {
		jQuery(this).parent().siblings().removeClass('active');
		jQuery(this).parent().addClass('active');
	});
	// category - brands
	jQuery('.cat_brand span:first').click(function() {
		jQuery.cookie('cat_brand', '1', options);
		
		jQuery(this).parent().parent().next().next().next().slideUp('normal');
		jQuery(this).parent().parent().next().next().slideDown('normal');
		
	});
		
	jQuery('.cat_brand span:last').click(function() {
		jQuery.cookie('cat_brand', '2', options);
		
		jQuery(this).parent().parent().next().next().slideUp('normal');
		jQuery(this).parent().parent().next().next().next().slideDown('normal');
		
	});
	
	if(jQuery.cookie('test_cookie')=='1'){
		if(jQuery.cookie('cat_brand')=='2'){
			jQuery('.cat_brand').next().next().hide();
			jQuery('.cat_brand').next().next().next().show();
			jQuery('.cat_brand').children().last().addClass('active');
			jQuery('.cat_brand').children().first().removeClass('active');
		}else{
			jQuery('.cat_brand').next().next().next().hide();
		};
	};
	
	
	// contacts
	jQuery('.contacts span:first').click(function() {
		if (jQuery('.contacts').next().next().is(':visible') ) {
			//jQuery(this).parent().parent().next().next().slideDown('normal');
			jQuery.cookie('contacts', '0', options);
			jQuery('.contacts').next().next().slideUp('normal');
		}else{
			jQuery.cookie('contacts', '1', options);
			jQuery('.contacts').next().next().slideDown('normal');
		}
	});

	
	if(jQuery.cookie('test_cookie')=='1'){
		if(jQuery.cookie('contacts')=='0'){
			jQuery('.contacts').next().next().hide();
		}else{
			//jQuery.cookie('contacts', '1', options);
			jQuery('.contacts').next().next().show();
		};
	};
	
	// details
	jQuery('.details span:first').click(function() {
		if (jQuery('.details').next().next().is(':visible') ) {
			//jQuery(this).parent().parent().next().next().slideDown('normal');
			jQuery.cookie('details', '0', options);
			jQuery('.details').next().next().slideUp('normal');
		}else{
			jQuery.cookie('details', '1', options);
			jQuery('.details').next().next().slideDown('normal');
		}
	});

	
	if(jQuery.cookie('test_cookie')=='1'){
		if(jQuery.cookie('details')=='0'){
			jQuery('.details').next().next().hide();
		}else{
			//jQuery.cookie('details', '1', options);
			jQuery('.details').next().next().show();
		};
	};
	
	
	
	//catalog_additional
	jQuery('.catalog_additional span:first').click(function() {
		jQuery.cookie('catalog_additional', '1', options);
		
		jQuery(this).parent().parent().next().next().next().slideUp('normal');
		jQuery(this).parent().parent().next().next().slideDown('normal');
		
	});
		
	jQuery('.catalog_additional span:last').click(function() {
		jQuery.cookie('catalog_additional', '2', options);
		jQuery(this).parent().parent().next().next().slideUp('normal');
		jQuery(this).parent().parent().next().next().next().slideDown('normal');
		
	});
	
	if(jQuery.cookie('test_cookie')=='1'){
		if(jQuery.cookie('catalog_additional')=='2'){
			jQuery('.catalog_additional').next().next().hide();
			jQuery('.catalog_additional').next().next().next().show();
			jQuery('.catalog_additional').children().last().addClass('active');
			jQuery('.catalog_additional').children().first().removeClass('active');
		}else{
			jQuery.cookie('catalog_additional', '1', options);
			jQuery('.catalog_additional').next().next().next().hide();
		};
	};

// tab_menu code end
	
});
