$(document).ready(function(){

	// homepage cycle(); functions to follow //
	//------------------------------------//
	//initially not resuming from a mouseout
	resume = 0;
	//initially no slides have run
	slidecounter = 0;
		//initIndex() used on startup, and after 
		//mouseout to highlight current index
	function initIndex(curr,next,opts){
		//clean up index highlighting
		$('.ctitle').removeClass("active");
		//if not resuming from mouseout
		if(resume != 0){
			//keep current slide highlighted 
			index = "#index-"+opts.currSlide;
			//until next pass
			resume = 0;
	} else {
		//if not initial cycle, set index to next slide - otherwise set index to 0
		if(slidecounter != 0){ index = "#index-"+opts.nextSlide; } else { var index = "#index-0"; }
	}
	//set the index
	$(index).addClass("active");
		//keep counting
		slidecounter++;
	}
	
	//only used on mouseover
	function hitIndex(curr,next,opts){
		//clean up index highlighting
		$('.ctitle').removeClass("active");
		//highlight current mouseover index
		index = "#index-"+opts.currSlide;
		$(index).addClass("active");
	}
	
	//variables for cycle timers
	ctimeout = 4500;
	cspeed = 1000;
	
	//check if home page loaded, initiate original cycle
	if ($('#slides').length) { // implies *not* zero
		$('#slides').cycle({ 
	    timeout: ctimeout,
	    speed:   cspeed, 
	    startingSlide: 0,
	    before: 	initIndex 
		});
	} 
	
	//change slide index mouseover, stop cycling
	$('.ctitle a').mouseover(function() {
		var slideIndex = $('.ctitle a').index(this);
		$('#slides').cycle({ 
	    timeout: 0, 
	    startingSlide: slideIndex,
	    after: 	hitIndex
		});
	});
	
	//resume cycle at current slide mouseout
	$('.ctitle a').mouseout(function() {
		var slideIndex = $('.ctitle a').index(this);
		resume = 1;
		$('#slides').cycle({ 
	    timeout: ctimeout, 
	    speed:   cspeed, 
	    startingSlide: slideIndex,
	    before: 	initIndex
		});
	});
	
});//docready
