mmove=0;
function showCityBlock(){
	$('body').addClass('inactive');
	$('.city_chooser').fadeIn(300);
}
function hideCityBlock(){
	$('.city_chooser').fadeOut(300, function(){$('body').removeClass('inactive');});
}
$(document).ready(function(){
	//showCityBlock();
	$('.city_chooser .close').click(function(){
		hideCityBlock();
	});
	$('.city_chooser .postcard').click(function(){
		hideCityBlock();
	});
	$('.city .choose_city').append('<li class="close"><a href="#">×</a></li>');
	function checkObj(obj){
		if($(obj).attr('value')>0) {
			$(obj).parent().parent().find('.add_to_cart').removeClass('inactive');
		} else {
			$(obj).attr('value',0)
			$(obj).parent().parent().find('.add_to_cart').addClass('inactive');
		}
	}
	$('.gallery').each(function(){
		$(this).find('.container').wrapInner('<div class="slide" />');
		$(this).find('.container').before('<input type="submit" class="arrow left" value=""/>');
		$(this).find('.container').before('<input type="submit" class="arrow right" value=""/>');
	});
	$('.gallery .arrow.right').click(function(){
		if(mmove==0){
			mmove=1;
			dx=$(this).parent('.gallery').find('.item').first().outerWidth(true);
			$(this).parent('.gallery').find('.slide').animate({left: '-'+dx+'px'},dx, function(){
				$(this).css('left',0);
				$(this).find('.item').first().insertAfter($(this).find('.item').last());
				mmove=0;
			});
		}
		return false;
	});
	
	$('.gallery .arrow.left').click(function(){
		if(mmove==0){
			mmove=1;
			dx=$(this).parent('.gallery').find('.item').last().outerWidth(true);
			$(this).parent('.gallery').find('.slide').css('left','-'+dx+'px');
			$(this).parent('.gallery').find('.item').last().insertBefore($(this).parent('.gallery').find('.item').first());
			$(this).parent('.gallery').find('.slide').animate({left: '0'},dx, function(){mmove=0; });
		}
		return false;
	});
	$('.catalog .count').each(function(){
		checkObj(this);
		$(this).before('<input type="submit" class="minus" value=""/>');
		$(this).after('<input type="submit" class="plus" value=""/>');
	});
	$('.catalog .plus').click(function(){
		$(this).parent().children('.count').attr('value',Math.floor($(this).parent().children('.count').attr('value'))+1);
		checkObj($(this).parent().children('.count'));
		return false;
	});
	$('.catalog .minus').click(function(){
		$(this).parent().children('.count').attr('value',Math.floor($(this).parent().children('.count').attr('value'))-1);
		checkObj($(this).parent().children('.count'));
		return false;
	});
	$('.catalog .compare').click(function(){
		if($(this).hasClass('active')){
			$(this).removeClass('active');
		} else {
			$(this).addClass('active');
		}
		return false;
	});
	$('.catalog .add_to_cart').click(function(){
		return false;
	});
	$('.catalog .count').keyup(function(){
		checkObj(this);
	});
	$('.catalog th a').mouseover(function(){
		if($('.catalog a[mouseover=yes]').length==0) {
			setTimeout('checkover()',10);
			num=10;
		}
		$(this).attr('mouseover','yes');
	});
	$('.catalog th a').mouseleave(function(){
		$(this).attr('mouseover','no');
		$(this).parent().children('.thumb').fadeOut(300);
	});
	$('.city .choose_city b').click(function(){
		if(!$(this).parent().parent('ul').hasClass('shown')){
			$(this).parent().parent('ul').addClass('shown');
		} else {
			$(this).parent().parent('ul').removeClass('shown');
		}
		return false;
	});
	$('.city .choose_city .close a').click(function(){
		$(this).parent().parent('ul').removeClass('shown');
		return false;
	});
	$('.eshop').each(function(){								
		$(this).find('ul').parent('li').children('a').addClass('dashed');
		$(this).find('ul').parent('li').children('b').children('a').addClass('dashed');
		$(this).find('a').closest('li').children('ul').css('display','none');
		$(this).find('b').parents('li').children('ul').css('display','block');
		$(this).find('a.active').parent('li').children('ul').css('display','block');
		$(this).find('a.active').removeClass('dashed');
	});
	$('.dashed').click(function(){
		$(this).closest('li').parent('ul').children('li').children('ul').each(function(){
			if($(this).css('display')=='block'){
				$(this).slideUp(100);
			}
		});
		if($(this).closest('li').children('ul').css('display')=='block'){
			$(this).closest('li').children('ul').slideUp(100);
		} else {
			$(this).closest('li').children('ul').slideDown(100);
		}
		return false;
	});
	$('.active').click(function(){
		return false;
	});

});
num=0
function checkover(){
	if(num>0){
		num--;
		setTimeout('checkover()',10);
	} else {
		if($('.catalog a[mouseover=yes]').length>0) {
			$('.catalog a[mouseover=yes]').each(function(){
				$(this).parent().children('.thumb').fadeIn(120);
			});
		}
	}
}

