// JavaScript Document


$(document).ready(function(){
	// FancyBox options ///////////////////////////////////////////////////////////////////////
    $("a.zoom2").fancybox({
        'zoomSpeedIn'		:	500,
        'zoomSpeedOut'		:	500
    });
    ///////////////////////////////////////////////////////////////////////////////////////////
      
    // Nav functions //////////////////////////////////////////////////////////////////////////
	/*$(".top_cat").click( function()
	{
		$("#nav ul").slideUp();
		$("#nav li").removeClass("selected");
		$(this).siblings("ul").slideDown();
		$(this).parent("li").addClass("selected");
	});*/
	
	$(".top_cat").toggle(
	function()
	{
		$open = $(this).siblings("ul").css("display");
		$("#nav ul").slideUp();
		$("#nav li").removeClass("selected");
		
		if($open == "none")
		{
			$(this).siblings("ul").slideDown();
			$(this).parent("li").addClass("selected");
		}
	},
	function()
	{
		$open = $(this).siblings("ul").css("display");
		$("#nav ul").slideUp();
		$("#nav li").removeClass("selected");
		
		if($open == "none")
		{
			$(this).siblings("ul").slideDown();
			$(this).parent("li").addClass("selected");
		}
	});
	$("#nav li.selected").slideDown();
    ///////////////////////////////////////////////////////////////////////////////////////////
	
    // Pagination functions ///////////////////////////////////////////////////////////////////
	$("#item-per-page").change( function()
	{
		$show = $(this).val();
		$cat_id = $("div.cat_id_hidden").attr("id").split("-");
		$cat_id = $cat_id[1];
		if($cat_id)
		{
			$url = "./?p=parts_cat&cat_id=" + $cat_id + "&page=1&show=" + $show;
			window.location.href = $url;
		}
	});
    ///////////////////////////////////////////////////////////////////////////////////////////
	
    // Search functions ///////////////////////////////////////////////////////////////////////
	$(".search_filter").change( function()
	{
		$id = $(this).attr("id").split('_');
		$val = $(this).val();
		if($val != 999 && $val != 9999)
		{
			for($i = parseInt($id[1]) + 1; $i <= 6; $i++)
			{
				$("#search_" + $i).val("999");
			}
			$s_1 = $("#search_1").val();
			$s_2 = $("#search_2").val();
			$s_3 = $("#search_3").val();
			$s_4 = $("#search_4").val();
			$s_5 = $("#search_5").val();
			//confirm($s_1 + "|" + $s_2 + "|" + $s_3 + "|" + $s_4 + "|" + $s_5 + "|");
			$.get(
					'./includes/search_filter.php',
					{
						's_1': $s_1,
						's_2': $s_2,
						's_3': $s_3,
						's_4': $s_4,
						's_5': $s_5
					},
					function(data)
					{
						if(data != "")
						{
							//confirm(data);
							$next = parseInt($id[1]) + 1;
							$("#search_" + $next).html(data);
							$("#s_filter_" + $next).show();
							for($i = $next + 1; $i <= 6; $i++)
							{
								$("#s_filter_" + $i).hide();
								$("#search_" + $i).val("999");
							}
						}
						else
							for($i = parseInt($id[1]) + 1; $i <= 6; $i++)
							{
								$("#s_filter_" + $i).hide();
								$("#search_" + $i).val("999");
							}
					}
				 );
		}
		else
		{
			for($i = parseInt($id[1]) + 1; $i <= 6; $i++)
			{
				$("#s_filter_" + $i).hide();
				$("#search_" + $i).val("999");
			}
		}
	});
	$("#search_1").change( function()
	{
		$val = $(this).val();
		if($val == 9999)
		{
			$("#search_inputs").show();
			for($i = 2; $i <= 6; $i++)
			{
				$("#search_" + $i).val("999");
				$("#s_filter_" + $i).hide();
			}
		}
		else if($val != 999)
		{
			$("#item-number").val("");
			$("#word").val("");
			$("#search_inputs").hide();
		}
	});
	$("#item-number").focus( function()
	{
		$("#item_number_info").show();
		$("#oe_number_frame").hide();
		$("#word_frame").hide();
		$("#s_filter_1").hide();
		$(this).focus();
	});
	$("#oe-number").focus( function()
	{
		$("#oe_number_info").show();
		$("#item_number_frame").hide();
		$("#word_frame").hide();
		$("#s_filter_1").hide();
		$(this).focus();
	});
	$("#word").focus( function()
	{
		$("#word_info").show();
		$("#item_number_frame").hide();
		$("#oe_number_frame").hide();
		$("#s_filter_1").hide();
		$(this).focus();
	});
	$("#item_number_info").click( function()
	{
		$("#item-number").val("");
		$("#item_number_info").hide();
		$("#oe_number_frame").show();
		$("#word_frame").show();
		$("#s_filter_1").show();
	});
	$("#oe_number_info").click( function()
	{
		$("#oe-number").val("");
		$("#oe_number_info").hide();
		$("#item_number_frame").show();
		$("#word_frame").show();
		$("#s_filter_1").show();
	});
	$("#word_info").click( function()
	{
		$("#word").val("");
		$("#word_info").hide();
		$("#item_number_frame").show();
		$("#oe_number_frame").show();
		$("#s_filter_1").show();
	});
    ///////////////////////////////////////////////////////////////////////////////////////////
	
    // Brands Search functions ////////////////////////////////////////////////////////////////
	$(".brands_filter").change( function()
	{
		$id = $(this).attr("id").split('_');
		$val = $(this).val();
		if($val != 999)
		{
			for($i = parseInt($id[1]) + 1; $i <= 4; $i++)
			{
				$("#brands_" + $i).val("999");
			}
			$s_1 = $("#brands_1").val();
			$s_2 = $("#brands_2").val();
			$s_3 = $("#brands_3").val();
			//confirm($s_1 + "|" + $s_2 + "|" + $s_3 + "|");
			$.get(
					'./includes/brands_filter.php',
					{
						's_1': $s_1,
						's_2': $s_2,
						's_3': $s_3
					},
					function(data)
					{
						if(data != "")
						{
							//confirm(data);
							$next = parseInt($id[1]) + 1;
							$("#brands_" + $next).html(data);
							$("#b_filter_" + $next).show();
							for($i = $next + 1; $i <= 6; $i++)
							{
								$("#b_filter_" + $i).hide();
								$("#brands_" + $i).val("999");
							}
						}
						else
							for($i = parseInt($id[1]) + 1; $i <= 4; $i++)
							{
								$("#b_filter_" + $i).hide();
								$("#brands_" + $i).val("999");
							}
					}
				 );
		}
		else
		{
			for($i = parseInt($id[1]) + 1; $i <= 4; $i++)
			{
				$("#b_filter_" + $i).hide();
				$("#brands_" + $i).val("999");
			}
		}
	});
    ///////////////////////////////////////////////////////////////////////////////////////////
	
    // Price Alert ////////////////////////////////////////////////////////////////////////////
		
		
		
                nyitva = 0;
		
		
		$('.submit-btn').click(function(){
			if(nyitva==1){
                            
                            if($("#alert_name").val() != '' && $("#alert_phone").val() != '' && $("#alert_email").val() != '' && $("#alert_email").val() != 'alert_amount' && 
                            $("#alert_name").val() != 'Az Ön neve' && $("#alert_phone").val() != 'Az Ön telefonszáma' && $("#alert_email").val() != 'Az Ön e-mail címe' && $("#alert_email").val() != 'Kérjük írja be a mennyiséget'){
                                
                                if($('#answare2').val()==$('#answare').val()){
                                    $('#figyelo').submit();
                                }else{
                                    alert('Hibás válasz a biztosági kérdésre!');
                                    return false;
                                }
                                
                                
                            }else{
                                alert('Kérem töltse ki az üres mezőket!');
                                return false;
                            }
                        }
			
		});
		
                $('.price-alert-box .active').click(function(){
                        if(nyitva==0){
                            $('.submit-btn.active').animate({'margin-top': 0});
                            $('.col-1-toggler').slideToggle('fast');
                            $(this).toggleClass('active');
                            $('.alert-condition').toggleClass('bordered');
                            $('.price-alert-box-close').slideToggle('fast');
                            if(nyitva == 1){nyitva=0;}else{nyitva=1;};
                        }
			return false;
		});
                
		$('.price-alert-box-close').click(function(){
			$('.submit-btn').animate({'margin-top': '-42px'});
			$('.col-1-toggler').slideToggle('fast');
			$('.submit-btn').toggleClass('active');
			$('.price-alert-box-close').slideToggle('fast');
			$('.alert-condition').toggleClass('bordered');
                        if(nyitva == 1){nyitva=0;}else{nyitva=1;};
			return false;
		});
	
	///////////////////////////////////////////////////////////////////////////////////////////
});
