var divs = new Array(), current=0, totalitems = 1;
var links = new Array();

jQuery(document).ready(function($){

	$(window).load(function(){
	
		//rotate content and keep introblock tall enough to contain all content
		if ($("#introblock").length > 0) {
		
			var containerdiv = $("#introblock");
			divs = containerdiv.children("div");
		
			setContainerHeight();
			
			setTimeout(changeIntro,11000);
			
		}
		
		//make last nav in top links have class 'last'
		if ($("#wpmenu1").length > 0) {		
			$('#wpmenu1 ul li:last').addClass("last");			
		}
		
		//make last nav in footer links have class 'last'		
		if ($("#wpmenu5").length > 0) {		
			$('#wpmenu5 ul li:last').addClass("last");			
		}
		
		if ($("#wpmenu6").length > 0) {	
			$('#wpmenu6 ul li:last').addClass("last");			
		}
		
		if ($('#wpmenu4').length > 0) {		
			moveClasses();
		}
		
	});

//cycle content
function changeIntro() {	
	
	totalitems = divs.length - 1;

	$(divs[current]).fadeOut(1000);

	if (current==totalitems) {
		current = 0;
	} else {
		current = current +1;
	}
	
	$(divs[current]).fadeIn(1000);
	
	setTimeout(changeIntro,11000);
	
}	

//keep container on cycled content tall enough to contain it properly
function setContainerHeight() {

	/* Make sure container is proper height */
	var mydiv = $("#introblock");
	var mydivholder =mydiv.children("div");
	var maxheight = 0;
	var i = 0;

	while(i < mydivholder.length) {

		var myheight = $(mydivholder[i]).height();

		if (maxheight < myheight) {
    		maxheight = myheight;
		} 

		i++;
	}

	$("#introblock").height(maxheight);
}

//remove classes from the a tag and put on li for topnav
function moveClasses() {

	$('a.topnavaboutp').parents('li').attr('id', 'topnavaboutp');
	$('a.topnavaboutsl').parents('li').attr('id', 'topnavaboutsl');
	$('a.topnavgetstarted').parents('li').attr('id', 'topnavgetstarted');
	$('a.topnavservices').parents('li').attr('id', 'topnavservices');
	$('a.topnavclasses').parents('li').attr('id', 'topnavclasses');
	$('a.topnavteacher').parents('li').attr('id', 'topnavteacher');

}


});