$(document).ready(function() {

  //$("#counter").css('margin-top', $(document).height()-410+'px');
  //$("#counter").css('margin-top', '40px');

  wcol = ($("body").width() - 980) / 2;

  $("#lcol").width(wcol);
  $("#rcol").width(wcol);

  $('.title_menu').click(function() {
	id_menu = $(this).attr('id');

	if ( $('#block_'+id_menu).is(':hidden') ){
		$('.title_menu').attr('class','title_menu');
		$(this).attr('class','title_menu active');
		$('.div_menu').hide();
		$('#block_'+id_menu).slideDown('slow');
       $('#menu_filter td:first>a').click();
	}else{
     $('#block_'+id_menu).slideUp('slow');
     $('.title_menu').attr('class','title_menu');
    }

  });

  $('#back').click(function() {
   num_img = parseInt($(this).attr('class'));
      $('.interior_img').hide();
    if(num_img){
     new_num = num_img - 1;
      $('#img_'+new_num).show();
      $(this).attr('class', new_num);
      $('#next').attr('class', new_num);
    }else{
      cnt_img = $('.interior_img').size();
      new_num = cnt_img-1;  
      $('#img_'+new_num).show();
      $(this).attr('class', new_num);
      $('#back').attr('class', new_num);
    }

  });

  $('#next').click(function() {

     num_img = parseInt($(this).attr('class'));
     new_num = num_img + 1;
     $('.interior_img').hide();

     if ( $('#img_'+new_num).length ){

      $('#img_'+new_num).show();
      $(this).attr('class', new_num);
      $('#back').attr('class', new_num);
     }else{
      $('#img_0').show();
      $(this).attr('class', '0');
      $('#back').attr('class', '0');
     }
  });
  
   $('#menu_sub_filter td>a').click(function() {
     type_doods = $(this).attr('href');
     p_class = $(this).parent("td").attr('class');

     $('#menu_sub_filter td').removeClass("active");
     $('#menu_sub_filter td').removeClass("empty");

     $('#menu_sub_filter td.'+p_class).attr('class', 'active '+p_class);
     $('#menu_sub_filter td.'+p_class+'_2').attr('class', 'active empty '+p_class+'_2');
    
     $('body').css('cursor','wait');
     $.get("/catalogue/japanese/", { 'srchPat[0]': type_doods },
     function(data){
      /*if(type_doods == 2) $('#menu').css('height','482');
      else $('#menu').css('height','242');*/
      $('#menu').html(data);
      $('body').css('cursor','default');
     });
    return false;
  });
  
   $('#menu_sub_filter_ita td>a').click(function() {
     type_doods = $(this).attr('href');
     p_class = $(this).parent("td").attr('class');

     $('#menu_sub_filter_ita td').removeClass("active");
     $('#menu_sub_filter_ita td').removeClass("empty");

     $('#menu_sub_filter_ita td.'+p_class).attr('class', 'active '+p_class);
     $('#menu_sub_filter_ita td.'+p_class+'_2').attr('class', 'active empty '+p_class+'_2');
    
    //$('#table_menu').height('238');
    
     $('body').css('cursor','wait');
     $.get("/catalogue/italian/", { 'srchPat[1]': type_doods },
     function(data){
      $('#menu').html(data);
      $('body').css('cursor','default');
     });
    return false;
  });
  
   $('#menu_filter td>a').click(function() {
     type_doods = $(this).attr('href');
    
     $('#menu_sub_filter td').removeClass("active");
     $('#menu_sub_filter td').removeClass("empty");
    
     $('#menu_sub_filter_ita td').removeClass("active");
     $('#menu_sub_filter_ita td').removeClass("empty");
    
     $('#menu_filter td').attr('class', '');
     $(this).parent("td").attr('class', 'active');
    
    
    if(type_doods == '/catalogue/japanese/'){
     $('#menu_sub_filter_ita').hide();
     $('#menu_sub_filter').show();
     $("#menu_sub_filter td:first>a").click();
     $('#menu').css('height','482');
     //$('#table_menu').height('480');
    }
    
    if(type_doods == '/catalogue/italian/'){
     $('#menu_sub_filter').hide();
     $('#menu_sub_filter_ita').show();
     $("menu_sub_filter td:first>a").click();
     $("#menu_sub_filter_ita td:first>a").click();
     $('#menu').css('height','242');
     //$('#table_menu').height('238');
     //alert($('#table_menu').height());
    }
    
    
    /*$('body').css('cursor','wait');
     $.get(type_doods,
     function(data){
      $('#menu').html(data);
      $('body').css('cursor','default');
     });*/
    return false;
  });
  
   $('#prevLink').live('click', function() {
    page_goods = $(this).attr('href');
    section = $('#menu_filter td.active>a').attr('href');

    $('body').css('cursor','wait');
     $.get(page_goods,
     function(data){

      $('#menu').html(data);
      $('body').css('cursor','default');
     });
    return false;
  });
  
   $('#nextLink').live('click', function() {
    page_goods = $(this).attr('href');
    section = $('#menu_filter td.active>a').attr('href');
    
    $('body').css('cursor','wait');
     $.get(page_goods,
     function(data){
      $('#menu').html(data);
      $('body').css('cursor','default');
     });
    return false;
  });
    
   $('.light').live('mouseover', function() {
    //$(this).attr('class','light_active');
  });
  
  $('.light_active').live('mouseout', function() {
    //$(this).attr('class','light');
  });

  //$('#jap').click();
  $("#menu_sub_filter td:first>a").click();
});

