$(function() {
//цитаты в типичке
	$('#content blockquote').append('<span class="blockquote_end"></span>');
//стиль таблиц в типичке
	$('#content table').each(function() {
		$(this).find('tr th:first').addClass('th_first');
		$(this).find('tr th:last').addClass('th_last');
		$(this).find('tr:last td:first').addClass('td_first');
		$(this).find('tr:last td:last').addClass('td_last');
	});	
	$('#content table tr:odd').addClass('odd');
	$('#content table tr').each(function() {
		$(this).find('td:last').addClass('b_none');
	});
//фикс меню
	var top = $('#menu').offset().top;
	$(window).scroll(function() {
		var w_top = $(this).scrollTop();
		if(w_top>top) {
			$('#menu').addClass('fix');
		}else{
			$('#menu').removeClass('fix');
		}
	});
//меню продуктов на главной        
	var width_first = $('.product_menu a:first').width()+'px';	
    $('.product_menu a:first').addClass('active');
	$('.product_menu .float_block').css('width', width_first);
	$('.product_menu a').bind('click', function() {
		var active = $(this);
		var class_id = $(this).attr('id');
		var text = $(this).text();
		var width = $(this).width()+'px';
		var coord = 0;
		$(this).prevAll('a').each(function() {
			coord = $(this).width()+coord+46;
		});
		$('.product_menu .float_block').animate({
			left: coord,
			width: width
		},400, function() {
			$('.product_menu a.active').removeClass('active');
			active.addClass('active');
			$('.head_block').text(text);
			$('#illust_s').removeClass().addClass(class_id);
			if(class_id == 'main_illustr1'){
				$('.text_block p').hide();
				$('.text_block p.shifer').show();
			}
			if(class_id == 'main_illustr2'){
				$('.text_block p').hide();
				$('.text_block p.plita').show();
			}
            if(class_id == 'main_illustr3'){
				$('.text_block p').hide();
				$('.text_block p.trub').show();
			}
		});
		return false;
	});    
    $('.product_menu a:eq(' + Math.floor(Math.random() * 4) + ')').click();
});

function filter() {    
    var evt = (evt) ? evt : (window.event) ? event : null;
    if (!( event.ctrlKey || event.altKey 
      || (47<event.keyCode && event.keyCode<58 && event.shiftKey==false) 
      || (95<event.keyCode && event.keyCode<106)
      || (event.keyCode==8) || (event.keyCode==9) 
      || (event.keyCode>34 && event.keyCode<40) 
      || (event.keyCode==46)
      || (event.keyCode==190) 
      || (event.keyCode==188))) {
        evt.preventDefault();
        return
      };
  }
  
function trunc(num) {
  if( num > 0 ) return Math.floor(num);
  if( num < 0 ) return Math.ceil(num);
  return 0;
  
}
jQuery(function($){
  var sort_a = $('div.cities a'),
      sort_rel,
      sort_address = $('div.addresses');
  sort_a.click( function() {
    sort_rel = $(this).attr('class');
    sort_rel = '.' + sort_rel;
    if(sort_address.find('.opened').size()) {
      if(sort_address.find(sort_rel).hasClass('opened')) {
      } else {
        sort_address.find('.opened').removeClass('opened').stop(true,true).animate( {
          height: 'hide',
          opacity: 'hide'
        }, function() {
          sort_address.find(sort_rel).stop(true,true).animate( {
            height: 'show',
            opacity: 'show'
          }).addClass('opened');
        });
      }
    } else {
      sort_address.find(sort_rel).stop(true,true).animate( {
        height: 'show',
        opacity: 'show'
      }).addClass('opened');
    }
    return false;
  });
});

