$(document).ready(function() {
	$(".rotator .figure img").css("display", "none");
	$(".rotator .figure").each(function() {
		$id = $(this).attr("id");
		if ($id) {
			$count = $(this).children("img").size();
			$random = (Math.floor(Math.random($count) * $count) + 1);
			$active = $(".rotator .figure#" + $id + " img:nth-child(" + $random + ")");
			$active.css("display", "block");
			$("li#" + $active.attr("class")).addClass("active");
			window.setTimeout("rotate()", 5000);
		} else {
			$(this).children("img").css("display", "block")
		}
	});	
});

function rotate() {
	$random++;
	if ($random > $count ) {
		$next = $(".rotator .figure#" + $id + " img:first-child(");
$random = 1;
		
	}
	$next = $(".rotator .figure#" + $id + " img:nth-child(" + $random + ")");
	$active.fadeOut(500);
	$next.fadeIn(500);
	$previous = $active;
	$active = $next;
	$("li#" + $previous.attr("class")).removeClass("active");
	$("li#" + $active.attr("class")).addClass("active");
	window.setTimeout("rotate()", 5000);
}

function updateLink(link, target) {
	document.location.target = "" + target;
	document.location.href = "" + link;
}