jQuery(document).ready(function() {
	var paused = false;
	var numslides = jQuery(".slides img").size();	// gets the number of slides in the slideshow
	
	jQuery(".slides").cycle({	// options object passed to the slideshow function
		timeout: 5000,		// time per slide
		pager: "#hero .pagination",		// container class for the numbered buttons
		pagerAnchorBuilder: function(idx, slide) {		// uses existing pagination html for the pager
			return "#hero .pagination ." + slide.className + " a";
		}
	});
	
	if(numslides > 1) {		// if there is more than one slide
		jQuery(".pagination a:gt(" + (numslides-1) + "):not('.pagination a:last')").hide();		// hide the pagination corresponding to slides not present
		
		jQuery(".pagination a:not('.pagination a:last')").click(function() {		// for all the numbered buttons
			jQuery(".slides").cycle("pause");	// pause the slideshow when clicked
			jQuery(".pagination li:last").removeClass("pause").addClass("play");		// change the last button image to play
			paused = true;		// keep track of the slideshow state
		});
		
		jQuery(".pagination li:last").click(function() {		// handle the play/pause button functionality
			if(paused) {	// if the slideshow is paused when this button is clicked
				jQuery(".slides").cycle("resume");		// resume the slideshow
				jQuery(this).removeClass("play").addClass("pause");		// change the image back to pause
				paused = false;		// keep track of the slideshow state
			} else {	// otherwise
				jQuery(".slides").cycle("pause");	// pause the slideshow
				jQuery(this).removeClass("pause").addClass("play");		// change the image to play
				paused = true;		// keep track of the slideshow state
			}
		});
	} else {	// if there is only one slide
		jQuery(".pagination").hide();	// hide the pagination altogether
	}
	
});