$(function() {
	// uses jquery.cycle
	// In cycle I replaced hide() with addClass("hide")
	// and show() with removeClass("hide").show()
	// this needs to be done if the jquery.cycle is upgraded
	if (!isMobile) {
		//puts in new control bar if the old control bar is hard coded
		$('#tmpSlideshowControls').replaceWith('<div id="navControls"><div id="navArea"></div><input id="carouselPause" type="image" src="/global/graphics/carouselpause.gif" name="image" title="Pause Slideshow" alt="Pause Slideshow" width="22" height="14"><input id="carouselPlay" type="image" src="/global/graphics/carouselplay.gif" name="image" title="Play Slideshow" alt="Play Slideshow" width="22" height="14"></div>');
		//starts up control bar and carousel if more than one slide
		if ($('div.tmpSlide').size() > 1) {
			//unhides control bar
			$('#navControls').css('visibility','visible');
			//basic behavior of slide show
			$('#tmpSlideshow').cycle({
				fx: 'fade',
				timeout: 11000,
				pager: '#navArea',
				slideExpr: 'div.tmpSlide'
			});
			//pauses slideshow if any numbered slide on control bar is clicked
			$('#navArea a').click(function(){
				$('#tmpSlideshow').cycle('pause');
				$('#carouselPlay').removeClass('hide');
				$('#carouselPause').addClass('hide');
			});
			//one time hides the play button - future behavior is on click events
			$('#carouselPlay').addClass('hide');
			//what happens when play is pressed
			$('#carouselPlay').click(function(){
				$('#tmpSlideshow').cycle('resume');
				$('#carouselPlay').addClass('hide');
				$('#carouselPause').removeClass('hide');
			});
			//what happens when pause is pressed
			$('#carouselPause').click(function(){
				$('#tmpSlideshow').cycle('pause');
				$('#carouselPlay').removeClass('hide');
				$('#carouselPause').addClass('hide');
			});
			//hover for play button
			$("#carouselPlay").hover(
			  function () {
				$(this).attr("src","/global/graphics/carouselplayhover.gif");
			  },
			  function () {
				$(this).attr("src","/global/graphics/carouselplay.gif");
			  }
			);
			//hover for pause button
			$("#carouselPause").hover(
			  function () {
				$(this).attr("src","/global/graphics/carouselpausehover.gif");
			  },
			  function () {
				$(this).attr("src","/global/graphics/carouselpause.gif");
			  }
			);
			//adds title to numbered buttons in control bar
			var maxCarouselSlides = $('#navArea a').size();
			$('#navArea a').each(function(){
				var slideNumber = $(this).text();
				if (slideNumber < 10) {
					$(this).css('padding', '0 4px 0 5px');
				}
				$(this).attr('title', ($('#tmpSlide-' + slideNumber + ' div.tmpSlideCopy h4').text() + ' - Slide ' + slideNumber + ' of ' + maxCarouselSlides));
			});
		} else {
			//if only one slide then delete the control bar and make first slide active
			$('#tmpSlideshowControls').remove();
			$('#navControls').remove();
			$('#tmpSlide-1').show();
		}
	}
});



