function ShowDescr(id)
{
	var descr = $('#descr_'+id);
	descr.show();
}

var onpage = 9;
var cached_pages = [];
query_string = location.search.split('&');

if(query_string[1])
{
	query_id = query_string[1].split('=')[1];	
}

if(query_string[2])
{
	query_p = query_string[2].split('=')[1];
}
else
{
	query_p = 1;
}

cached_pages[query_p] = 1;

function move_catalog(action, p, id)
{
	$('#page_'+p+' a').css("font-weight", "bold");
	$('#page_'+p+' a').css("color", "#FFE4A2");
		
	prev_li = $('#page_'+(p-1)+' a');
	next_li = $('#page_'+(p+1)+' a');
	
	if(prev_li)
	{
		prev_li.css("font-weight", "normal");
		prev_li.css("color", "#D8A15B");
	}
	
	if(next_li)
	{
		next_li.css("font-weight", "normal");
		next_li.css("color", "#D8A15B");
	}
	
	// Если уже загружены
	if(cached_pages[p] == 1)
	{
		if(action == 'left')
		{
			$(".carousel-content").animate({left: '+=597px'}, 1500);
			if(p == 1)
		    {
		    	$('.arrow-left').hide();
		    	$("#arrow-left").unbind("click");
		    }
		    else
		    {
		    	$("#arrow-left").unbind("click");
				$('#arrow-left').click(function () {
			    	move_catalog('left', (p-1), id);
			    });
			    
		    }
		    		    
		    if(total > onpage*p)
			{
				$('.arrow-right').show();
				$("#arrow-right").unbind("click");
				$('#arrow-right').click(function () { 
			      move_catalog('right', (p+1), id);
			    });
			    
			}
			else
			{
				$('.arrow-right').hide();
				$("#arrow-right").unbind("click");
			}
		}
		else if(action == 'right')
		{
			$(".carousel-content").animate({left: '-=597px'}, 1500);
			if(p != 1)
			{
				$('.arrow-left').show();
			}
			$("#arrow-left").unbind("click");
			$('#arrow-left').click(function () {
		    	move_catalog('left', (p-1), id);
		    });
		    
		    
		    $("#arrow-right").unbind("click");
		    		    
		    if(total > onpage*p)
		    {
		    	$('#arrow-right').click(function () {
		    	move_catalog('right', (p+1), id);
			    });
			    
		    }
		    else
		    {
		    	$("#arrow-right").unbind("click");
		    	$('.arrow-right').hide();
		    }
		    
		}
		return;
	}
	
	if(action == 'right')
	{
		$.get("/?mid=3", { ajax: 1, p: p, id: id},
	   	function(data){
	   		$('#id_carousel_content').append(data);
			width = $(".carousel-content").css('width');
			width = parseInt(width);
			$(".carousel-content").css('width', (width+597));
			$(".carousel-content").animate({left: '-=597px'}, 1500);
			
			//alert(total+' '+(onpage*p));
			
			if(total > onpage*p)
			{
				$('.arrow-right').show();
				$('#arrow-right').attr('href', "javascript:void(0);");
				$('#arrow-right').removeAttr('onclick');
				$("#arrow-right").unbind("click");
				$('#arrow-right').click(function () { 
			      move_catalog('right', p+1, id);
			    });
			    
			}
			else
			{
				$('.arrow-right').hide();
				$("#arrow-right").unbind("click");
			}
			
			$('#arrow-left').attr('href', "javascript:void(0);");
			$('#arrow-left').removeAttr('onclick');
			$('.arrow-left').show();
			$("#arrow-left").unbind("click");
			$('#arrow-left').click(function () {
		    	move_catalog('left', (p-1), id);
		    });
		    
			cached_pages[p] = 1;
	   	});
	}
	else if(action == 'left')
	{
		$.get("/?mid=3", { ajax: 1, p: p, id: id},
	   	function(data){
	   		$('#id_carousel_content').prepend(data);
			width = $(".carousel-content").css('width');
			width = parseInt(width);
			$(".carousel-content").css('width', (width+597));
			$(".carousel-content").css('left', (parseInt($('.carousel-content').css('left')) - 597));
			$(".carousel-content").animate({left: '+=597px'}, 1500);
			
			//alert(total+' '+(onpage*p));
			
			if(total > onpage*p)
			{
				$('.arrow-right').show();
				$('#arrow-right').attr('href', "javascript:void(0);");
				$('#arrow-right').removeAttr('onclick');
				$("#arrow-right").unbind("click");
				$('#arrow-right').click(function () { 
			      move_catalog('right', p+1, id);
			    });
			    
			}
			else
			{
				$('.arrow-right').hide();
				$("#arrow-right").unbind("click");
			}
			
			if(p != 1)
			{
				$('#arrow-left').attr('href', "javascript:void(0);");
				$('#arrow-left').removeAttr('onclick');
				$('.arrow-left').show();
				$("#arrow-left").unbind("click");
				$('#arrow-left').click(function () {
			    	move_catalog('left', (p-1), id);
			    });
		    }
		    else
		    {
		    	$('.arrow-left').hide();
				$("#arrow-left").unbind("click");
		    }
		    
			cached_pages[p] = 1;
	   	});
	}
}


