$(document).ready(function() {	//------------------------------------------------------------	//		//	CATEGORY SELECTION	//		//------------------------------------------------------------$('.category').click(function(e){		$('.option-list').stop(true, true).fadeOut(200);				if($('.option-list', this).children().length > 1){			$('.option-list', this).stop(true, true).fadeIn(200);		}		else{			var url= $('.option-list li:first-child a', this).attr('href');						$.ajax({			  type: 'POST',			  url: url,			  success: refresh_categories,			  dataType: 'json'			});						 $('.box-sub-categories').show();			 		}		});	/*		$('.category').mouseleave(function(){			$('.option-list', this).stop(true, true).fadeOut(300);		});	 */		$('.option-list').click(function(){return false});			$('.option-list li a').click(function(e){		e.stopPropagation();		e.preventDefault();				var url= $(this).attr('href');				$.ajax({		  type: 'POST',		  url: url,		  success: refresh_categories,		  dataType: 'json'		});				$('.box-sub-categories').show();				$(this).parents('.option-list').stop(true, true).fadeOut(200);	});			$('.sub-categories li a').click(function(e){		e.preventDefault();	});			function refresh_categories(data)	{			 $('#sub-categories').html('');		 				 		 for(i in data){			 $('#sub-categories').append('<li><a href="index.php?c=sommelier3&m=get_wines&id_cat='+data[i].id_cat+'&id_dish='+data[i].id+'">'+data[i].name+'</a></li>');		 }		 $.scrollTo('.box-sub-categories', 1200, {queue:true, axis: 'y'});	}			//------------------------------------------------------------	//		//	VIEW WINE DETAILS	//		//------------------------------------------------------------		$('.results .button').click(function(e){		e.preventDefault();		$(this).find('span').toggleClass('see-more').toggleClass('see-less');		$(this).parent().next().toggle();	});		$('.btn-more').click(function(e){		e.preventDefault();		$(this).parent().find('.more').toggle();	});
	
	/////////////////////////////////////////////////////////////////////////////////////////////
	// sommelier
	/////////////////////////////////////////////////////////////////////////////////////////////		
                                     
	$('.triggerMealTypeSommelier').change(function(){
		var mealType = $(this).val();
		
		if(mealType == "")
		{
			$('#meal').html('<option value="">-- Wybierz --</option>');
			$('.divMeal').hide();
			$('#typWina').html('<option value="">-- Wybierz --</option>');
			$('.divTypWina').hide();
			$('#tag').html('<option value="">-- Wybierz --</option>');
			$('.divTag').hide();
			$('#pokaz').attr('disabled', 'disabled'); 
			//$('#tag').html('<option value="">-- Wybierz --</option>');
			//$('.divTag').hide();
			//$('#kraj').html('<option value="">-- Wybierz --</option>');
			//$('.divKraj').hide();
			//$('#apelacja').html('<option value="">-- Wybierz --</option>');
			//$('.divApelacja').hide();
			//$('#szczep').html('<option value="">-- Wybierz --</option>');
			//$('.divSzczep').hide();
			//$('#typ').html('<option value="">-- Wybierz --</option>');
			//$('.divTyp').hide();
		}
		else
		{
			$.ajax({
				type: "GET",
				url: 'includes/ajaxCommon.php?m=pobierzSommelierMeal&p=' + mealType,
				cache: true,
				success: function(msg)
				{
					if(msg != "")
					{
			              	$('#meal').html(msg);
	                         $('.divMeal').show();
                         }
                         else
					{
						$('#meal').html('<option value="">-- Wybierz --</option>');
						$('.divMeal').hide();
					}
				}
			});

		}
		$('#pokaz').attr('disabled', 'disabled'); 
		$('#typWina').html('<option value="">-- Wybierz --</option>');
		$('.divTypWina').hide();
		$('#tag').html('<option value="">-- Wybierz --</option>');
		$('.divTag').hide();
		//$('#kraj').html('<option value="">-- Wybierz --</option>');
		//$('.divKraj').hide();
		//$('#apelacja').html('<option value="">-- Wybierz --</option>');
		//$('.divApelacja').hide();
		//$('#szczep').html('<option value="">-- Wybierz --</option>');
		//$('.divSzczep').hide();
		//$('#typ').html('<option value="">-- Wybierz --</option>');
		//$('.divTyp').hide();
	});
	
	$('.triggerMealSommelier').change(function(){
		var meal = $(this).val();
		
		if(meal == "")
		{
			$('#typWina').html('<option value="">-- Wybierz --</option>');
			$('.divTypWina').hide();
			$('#tag').html('<option value="">-- Wybierz --</option>');
			$('.divTag').hide();
			$('#pokaz').attr('disabled', 'disabled'); 
		}
		else
		{
			$('#pokaz').attr('disabled', ''); 
			return true;
			$.ajax({
				type: "GET",
				url: 'includes/ajaxCommon.php?m=pobierzSommelierTypWina&p=' + meal,
				cache: true,
				async: false,
				success: function(msg)
				{
					if(msg != "")
					{
						$('#pokaz').attr('disabled', '');    
			              	$('#typWina').html(msg);
	                         $('.divTypWina').show();
                         }
                         else
					{
						$('#typWina').html();
						$('.divTypWina').hide();
					}
				}
			});
			
			$.ajax({
				type: "GET",
				url: 'includes/ajaxCommon.php?m=pobierzSommelierTag&p=' + meal,
				cache: true,
				async: false,
				success: function(msg)
				{
					if(msg != "")
					{
						$('#pokaz').attr('disabled', '');     
			              	$('#tag').html(msg);
	                         $('.divTag').show();
                         }
                         else
					{
						$('#tag').html();
						$('.divTag').hide();
					}
				}
			});
		}
	});

	/////////////////////////////////////////////////////////////////////////////////////////////
	// toggleWino
	/////////////////////////////////////////////////////////////////////////////////////////////
	
	$('.toggleWino').click(function(){
		var id = $(this).attr('rel');  
		if($('#winoFull' + id).css('display') == "none")
		{
			$('#winoFull' + id).slideDown();
			$('#w' + id).html('zwiń wino');
			//$('#winoMini' + id).slideUp();
		}
		else
		{
		     $('#winoFull' + id).slideUp();
		     $('#w' + id).html('więcej');
		     //$('#winoMini' + id).slideDown();
		}
		return false;
	});
});
