var currentPage = 1;

$(document).ready(function() {

	$(".showAdvice").click(function() {
		var idAdvice = $(this).attr("id").substring(4);
		$("#splashScreen").show();
		$("#advice"+idAdvice).show();
	});
	
	$(".closeLink").click(function() {
		$(".advicePopup").hide();
		$("#splashScreen").hide();
	});
	
	$(".topCloseLink").click(function() {
		$(".advicePopup").hide();
		$("#splashScreen").hide();
	});

	$("#previousPage").click(function() {showPage(currentPage-1)});
	$("#nextPage").click(function() {showPage(currentPage+1)});

	if ($("#advicesInset ol li.page"+(currentPage+1)).length>0) {
		$("#nextPage").show();
	}

	if(window.location.hash && window.location.hash.length>1) {
		var idAdvice = window.location.hash.substring(1);
		if ($("#advice"+idAdvice).length == 1) {
			$("#splashScreen").show();
			$("#advice"+idAdvice).show();
			showPage($("#show"+idAdvice).parent().attr("class").substring(4));
		}
	}
	
});

function showPage(page) {
	currentPage = page;
	if (currentPage<1 || $("#advicesInset ol li.page"+currentPage).length==0) {
		currentPage=1
	}
	$("#advicesInset ol li").hide();
	$("#advicesInset ol li.page"+currentPage).show();
	if (currentPage==1) {
		$("#previousPage").hide();
	} else {
		$("#previousPage").show();
	}
	if ($("#advicesInset ol li.page"+(currentPage+1)).length==0) {
		$("#nextPage").hide();
	} else {
		$("#nextPage").show();
	}
}