var current_page = 1;
var page_width = 500;
var total_pages;

/**
 * Lekker met brood - Show detail
 */
$("#recipe_wrapper dl").click(function(){
	var id = $(this).attr("id").replace('recipe_', '');
	$("#recept_content").load('/haalmeeruitjebrood/lekkermetbrood/detail/' + String(id));
});


/**
 * Lekker met brood - navigatie
 */
if($("#total_pages").length){
	total_pages = $("#total_pages").html();
	setRecipeNavigation();
	
	$("#btn_first").click(function(){
		if($(this).hasClass("inactive") == false ){
			var new_pos = 0;
			var diff = current_page;
			$("#recipe_wrapper").animate({left: String(new_pos) + "px"}, diff * 150, "linear", function(){
				current_page = 1;
				$("#current_page").html(current_page);
				setRecipeNavigation();
			});
		}
		
	});
	
	$("#btn_previous").click(function(){
		if($(this).hasClass("inactive") == false ){
			var new_pos = -1 * (Number(current_page - 2) * Number(page_width));
			$("#recipe_wrapper").animate({left: String(new_pos) + "px"}, 300, "linear", function(){
				current_page--;
				$("#current_page").html(current_page);
				setRecipeNavigation();
			});
		}
	});

	$("#btn_next").click(function(){
		if($(this).hasClass("inactive") == false ){
			var new_pos = -1 * (Number(current_page) * Number(page_width));
			$("#recipe_wrapper").animate({left: String(new_pos) + "px"}, 300, "linear", function(){
				current_page++;
				$("#current_page").html(current_page);
				setRecipeNavigation();
			});
		}
	});
	
	$("#btn_last").click(function(){
		if($(this).hasClass("inactive") == false ){
			var new_pos = -1 * (Number(total_pages-1)* Number(page_width));
			var diff = total_pages - current_page;
			$("#recipe_wrapper").animate({left: String(new_pos) + "px"}, diff * 150, "linear", function(){
				current_page = total_pages;
				$("#current_page").html(current_page);
				setRecipeNavigation();
			});
		}
	});
}