var cache = [];  

function print_info(sit, tim){
  if (sit != null && tim != null) {
    var list_tim = $.trim(tim.join(' '));
    var list_sit = $.trim(sit.join(' '));
  //search_tims(jQuery.trim(list));
    $.get("get_sit.php", { 'sit' : list_sit, 'tim' : list_tim },
      function(data){
        $('.answer').html(data);
      });
  } else {$('.answer').html('<p class="center">Выберите интересующие тимы и темы, можно несколько.</p>');}
  cache['tim'] = tim;
  cache['sit'] = sit;
}

function add_all(target, selected) {
  var tar = $('#sel_'+target);
  var row = rows[target].all;
  //console.log(row);
  tar.append(row);
  if (selected) {
    tar.children('option[value="all"]').attr('selected', 'selected');
  } 
  //cache[target] = "all";
}

$(function(){
	
	$('.intro').hide().removeClass('hide');
	$('.hide_intro').hide();
	
	$('.hide_intro').click(function() {
		$('.intro').slideUp();
		$('.hide_intro').hide();
		$('.show_intro').show();		
	});
	
	$('.show_intro').click(function() {
		$('.intro').slideDown();
		$('.show_intro').hide();
		$('.hide_intro').show();		
	});
	
    $('.up_link').live("click", function(){
		var top = $('#sel_tim').offset().top - 50;
        $("html, body").animate({scrollTop: top}, 1200, function() {} );
        return false;
    });
	
  cache['tim'] = $('#sel_tim').val();
  cache['sit'] = $('#sel_sit').val();
  
  $('#sel_tim').change(function() {
    var new_tim = $(this).val();
    //console.log(new_tim);
    print_info(cache['sit'], new_tim);
    $('body').focus();
	$('.hack_focus').focus();
  }).change();
  
  $('#sel_sit').change(function() {
    var new_sit = $(this).val();
    //console.log(new_sit);
    print_info(new_sit, cache['tim']);
    $('body').focus();
	$('.hack_focus').focus();
  }).change();  
  	
});
