$(document).ready(function() {
	// set selected class if applicable

	$("ul.navtop").children("li").each(function() {
		$(this).children("ul").each(function() {
			$(this).children("li").each(function() {
				var compare = window.location.href;
				compare = compare.split("/");
				if ( ("/" + compare[3]+ "/") == $(this).children("a").attr("href"))
				{
					$(this).addClass("selected");
				}
			});
		});
	});
	
	// show random images in main nav area
	var rand_img_one = getRandNum(3) + 1;
	$("#one .image img.quoteimage").attr( {src: "/cmsimages/1st_" + rand_img_one + "_small.jpg"} );
	$("#one .image img.quotetext").attr( {src: "/cmsimages/1st_" + rand_img_one + "_small_quote.jpg"} );
	var rand_img_two = getRandNum(3) + 1;
	$("#two .image img.quoteimage").attr( {src: "/cmsimages/2nd_" + rand_img_two + "_small.jpg"} );
	$("#two .image img.quotetext").attr( {src: "/cmsimages/2nd_" + rand_img_two + "_small_quote.jpg"} );
	var rand_img_three = getRandNum(3) + 1;
	$("#three .image img.quoteimage").attr( {src: "/cmsimages/3rd_" + rand_img_three + "_small.jpg"} );
	$("#three .image img.quotetext").attr( {src: "/cmsimages/3rd_" + rand_img_three + "_small_quote.jpg"} );

	/*
	// show only one spotlight randomly and hide others
	if ( $("*").index( $("#reusablecontentarea_3")[0] ) > -1 ) {
		var spotlights = $("#reusablecontentarea_3 > .spotlight-content");
		var rand_spotlight = getRandNum(3);
		spotlights.hide();
		$(spotlights[rand_spotlight]).show();
	}
	*/
	
	// hide the spotlights content areas on load, slide in on click
	//$("#slider-text .text").addClass("hide");

	// needed so it doesn't try to animate another before another one is finished.
	var oktoanimate = true;

	// slide tab content on click
	//*
	$("#tab-legacy").click( function() {
		slideTab("#tab-legacy-content");
		return false;
	});
	$("#tab-groups").click( function() {
		slideTab("#tab-groups-content");
		return false;
	});
	$("#tab-news").click( function() {
		slideTab("#tab-news-content");
		return false;
	});

	// needed so it doesn't try to animate another before another one is finished.
	var oktoanimate = true;

	function slideTab(tab) {
		if(oktoanimate) {
			// only animate if is not already out
			if ( $(tab).filter(".show").length == 0 ) {
				oktoanimate = false;

				// animate in all that are already out
				list = $("#slider-text .show");
				$(list).removeClass("show");
				$(list).addClass("hide");
				$(list).removeAttr("style");

				// animate this one out
				$(tab).filter(".hide").slideDown("slow", function() {
					$(this).removeClass("hide");
					$(this).addClass("show");
					oktoanimate = true;
				});
			} else {
				oktoanimate = false;

				// animate in this one
				$(tab).removeClass("show");
				$(tab).slideUp("slow", function() {
					$(this).addClass("hide");
					oktoanimate = true;
				});
			}
		}
	}
});
