/*
Converts the featured list to a paged slide in/out box.
*/
var featuredCount = 0;
var rotateInterval;
var featuredOldIndex = 0;
var featuredCurrentIndex = 0;

$("#featured").load("featured.htm ul", function(response, status){
	if (status == "error" || response == "")
		$(this).hide();
	else
	{
		featuredCount = $("#featured li").size();
		$("#featured li:eq("+featuredCurrentIndex+")").fadeIn();
		if (featuredCount > 1) {
			rotateInterval = setInterval(rotateFeatured, 5000); // rotate every 5 seconds
			
			$("#featured").hover(
				function() {
					// stop rotating when the mouse is over the featured area
					clearInterval(rotateInterval);
				},
				function() {
					// start rotating again when the mouse leaves
					rotateInterval = setInterval(rotateFeatured, 5000); // rotate every 5 seconds
				});
		}
	}
});


function rotateFeatured(){
	featuredCurrentIndex = (featuredOldIndex + 1) % featuredCount;
	$("#featured li:eq("+featuredOldIndex+")").fadeOut("slow",
		function() {
			$("#featured li:eq("+featuredCurrentIndex+")").fadeIn("slow");
			featuredOldIndex = featuredCurrentIndex;
		});
}


/*
Highlights the current page in the menu
*/
var fileName = window.location.pathname.substring(window.location.pathname.lastIndexOf('/') + 1);
if (fileName == "")
	fileName = "index.htm";
// clear the current class from any menu links
$("#mainNav a").removeClass("current");
// apply it to the current page
$("#mainNav a[href=" + fileName + "]").addClass("current");