$(document).ready(function(){
	$('table.catalog').find('input.order').before('<input type="submit" class="minus" value=""/>');
	$('table.catalog').find('input.order').after('<input type="submit" class="plus" value=""/>');
	$('table.catalog').find('.order').each(function(){
		if($(this).attr('value')>0){
			count_order=$(this).parent().parent().prevAll().length;
			$(this).parents('table.catalog').before('<span class="selection num'+count_order+'" />');
			$('.num'+count_order).css('top',$(this).parent().offset().top);
			$('.num'+count_order).css('height',$(this).parent().innerHeight()+2);
			$('.num'+count_order).css('width',$(this).parents('table.catalog').width());
			$('.num'+count_order).text(' ');
		}
	});
	$('.map_big').append('<span class="city_title" />');
	$('.map_big .city').mouseenter(function(){
		$('.map_big .city_title').text($(this).children('span').text()).css('left',$(this).css('left')).css('top',$(this).css('top')).fadeIn(150);
	});
	$('.map_big .city').mouseleave(function(){
		$('.map_big .city_title').fadeOut(150);
	});
	$('.map_big .city').click(function(){
		$('.filials').empty();
		$(this).children('div').clone().appendTo($('.filials')).css('display','block');
	});
	$('table.catalog .plus').click(function(){
		var cnt=$(this).parent().children('.order').attr('value');
		cnt=Math.floor(cnt)+1;
		if(cnt==1){
			count_order=$(this).parent().parent().prevAll().length;
			$(this).parents('table.catalog').before('<span class="selection num'+count_order+'" />');
			$('.num'+count_order).css('top',$(this).parent().offset().top);
			$('.num'+count_order).css('height',$(this).parent().innerHeight()+2);
			$('.num'+count_order).css('width',$(this).parents('table.catalog').width());
			$('.num'+count_order).text(' ');
		}
		if(cnt<100){
			$(this).parent().children('.order').attr('value', cnt);	
		}
		return false;
	});
	$('table.catalog .minus').click(function(){
		var cnt=$(this).parent().children('.order').attr('value');
		cnt=Math.floor(cnt)-1;
		if(cnt==0){
			$('.num'+$(this).parent().parent().prevAll().length).remove();
		}
		if(cnt>=0){
			$(this).parent().children('.order').attr('value', cnt);	
		}
		return false;
	});
	$('table.catalog .order').change(function(){
		if($(this).attr('value')==''){$(this).attr('value',0);}
		if($(this).attr('value')>0) {
			count_order=$(this).parent().parent().prevAll().length;
			if(!$('.num'+count_order).css('height')){
			$(this).parents('table.catalog').before('<span class="selection num'+count_order+'" />');
			$('.num'+count_order).css('top',$(this).parent().offset().top);
			$('.num'+count_order).css('height',$(this).parent().innerHeight()+2);
			$('.num'+count_order).css('width',$(this).parents('table.catalog').width());
			$('.num'+count_order).text(' ');
			}
		} else {
			$('.num'+$(this).parent().parent().prevAll().length).remove();
		}
	});

});

