$(document).ready(function(){
	$('.compare_link').on('click',function(){
		var item_id=$(this).attr('data-id');
		if($(this).attr('data-action')=='add'){
			$.ajax({
				type:'post',
				url:'/index.php?ajax_action=compare',
				data:{id:item_id,act:'add'},
				beforeSend:function(){
				},
				success:function(r){
					$('header .compare a').addClass('active');
					$('header .compare span').html(r);
				}
			});
			/*
			$.post('/index.php?ajax_action=compare',{id:item_id,act:'add'});
			$(this).attr('data-action','del');
			$(this).html('Убрать из сравнения');
			$('.compare span').html(($('.compare span').html()*1+1));
			*/
			$(this).attr('href','/compare.html');
			$(this).removeAttr('data-action');
			$(this).addClass('active');
			var picture='';
			if($(this).data('detail')==1){
				picture=$('#detail_photo');
			}
			else{
				picture=$('.image_'+item_id);
			}
			animate_picture(picture,'.compare');
			return false;
		}
		else if($(this).attr('data-action')=='del'){
			$.post('/index.php?ajax_action=compare',{id:item_id,act:'del'});
			$(this).attr('data-action','add');
			$(this).html('Добавить к сравнению');
			$('.compare span').html(($('.compare span').html()*1-1));
			return false;
		}
	});
	$('.delete_from_compare').on('click',function(){
		var item_id=$(this).attr('data-id');
		$.post('/index.php?ajax_action=compare',{id:item_id,act:'del'});
		$.ajax({
			url:window.location.href,
			headers:{
				"Pragma":"no-cache",
				"Expires":-1,
				"Cache-Control":"no-cache"
			}
		}).done(function(){
			window.location.reload(true);
		});
		return false;
	});
});
