$(document).ready(function() {

	window.t = window.setTimeout(rotateFeature, 10000);
						   
	// Feature selectors
	$("#features div").each(function() {
		$("#selectors").append('<li class="new"></li>');
		$("#selectors li.new").append('<a></a>');
		$("#selectors li.new a").attr("href", "#"+$(this).attr("id"));
		$("#selectors li.new a").attr("title", $(this).children("h2").text());
		$("#selectors li.new a").append($(this).children("h2").text());
		if ($(this).hasClass("active")) { $("#selectors li.new").addClass("active"); }
		$("#selectors li.new").removeClass("new");
	});
	$("#selectors a").click(function(e) {
		e.preventDefault();
		window.clearTimeout(window.t);
		showFeature($(this).attr("href"));
	});
	
	// Set feature background
	$("#features div").each(function() {
		$(this).css("background","url(/media/onsfoundation/images/feature/"+$(this).attr("id")+".png) no-repeat top left");
		$(document).pngFix();
	});
	
});

function showFeature(id) {
	$("#features div.active").removeClass("active");
	$("#selectors li.active").removeClass("active")
	$(id).addClass("active");
	$("#selectors a[href='"+id+"']").parent().addClass("active");
} // function showFeature(id)

function rotateFeature() {
	var next = "#"+$("#features div.active").next("div").attr("id");
	if (next=="#undefined") {
		next = "#"+$("#features div").first("div").attr("id");
	} // if (next=="#undefined")
	showFeature(next);
	window.t = window.setTimeout(rotateFeature, 10000);
} // function rotateFeature()
