$(function(){
  //Блокируем переход по сслыками
  $('#search').find('div.search_v li a').click(function(){
    $(this).parents('ul').find('li').removeClass('active');
    $(this).parent().addClass('active');
    $(this).parents('div.search_v').trigger('click');
    return false;
  });
  //TODO клик вне элемента
//  $('#search').find('div.search_v li:first').show();
  $('#search').find('div.search_v').click(function(){
    if($(this).find('li:visible').length>1){
      $(this).find('ul li:not(.active)').hide();
    }else{
      $(this).find('ul li').show();
    }
  });

  $('#search_button').click(function(){
    var new_location='', type_link, color_link, surface_link;
    new_location = $(this).find('a').attr('href');
    type_link = $('#search_type').find('li.active a').attr('href');
    type_link = (type_link=='#')? '' : type_link;
    color_link = $('#search_color').find('li.active a').attr('href');
    color_link = (color_link=='#')? '' : color_link;
    surface_link = $('#search_surface').find('li.active a').attr('href');
    surface_link = (surface_link=='#')? '' : surface_link;
    if (!Boolean(type_link || color_link || surface_link)){
      alert('Задайте условие для поиска');
      return false;
    }
    if (Boolean(color_link && surface_link)){
      alert('Можно выбрать или тип поверхности или оттенок');
      return false;
    }
    if (color_link != '') new_location +=  color_link + '/';
    if (surface_link != '') new_location +=  surface_link + '/';
    if (type_link != '') new_location +=  type_link + '/';
    $(this).find('a').attr('href',new_location);
    return true;
  });
  
});
