$(document).ready(function() {
	$(".figure img").css("display", "none");
	$(".figure").each(function() {
		$id = $(this).attr("id");
		if ($id) {
			$count = $(this).children("img").size();
			$random = (Math.floor(Math.random($count) * $count) + 1);
			$active = $(".figure#" + $id + " img:nth-child(" + $random + ")");

			$active.css("display", "block");

			$("li#" + $active.attr("class")).addClass("active");
		} else {
			$(this).children("img").css("display", "block")
		}
	});
});

function updateLink(link, target) {
	document.location.target = "" + target;
	document.location.href = "" + link;
}
