function slideSwitch( slideTo ) {
	
	if (slideTo != undefined) {
		// button was clicked
		$("#promo-buttons-container a").removeClass("current active");
		$("#promo-buttons-container a").eq(slideTo).addClass("current active");
		
		var slideshow = $("#slideshow a");
		$("#slideshow a").removeClass("last-active");
		$("#slideshow a.active").addClass("last-active");
		$("#slideshow a.active").removeClass("active");
		slideshow.eq(slideTo).css({opacity: 0.0})
		         .addClass('active')
		         .animate({opacity: 1.0}, 1000);
	}
	else {
		// slideshow is playing
		// get the 'active' button
		var activeButton = $("#promo-buttons-container a.active");
		// determine the next button
		var nextButton = activeButton.next().length ? activeButton.next() : $("#promo-buttons-container a:first");
		activeButton.removeClass("current");
		activeButton.removeClass("active");

		nextButton.addClass("current");
		nextButton.addClass("active");
	
		// get the 'active' image
		var $active = $('#slideshow A.active');
	    
		// determine the next image
		if ( $active.length == 0 ) $active = $('#slideshow A:last');
		var $next = $active.next().length ? $active.next() : $('#slideshow A:first');
	
		$active.addClass('last-active');
	
		// added 'slideTo' variable to allow transition to a selected slide
		// defaults to null, but if it's >= 0, it will use this index for '$next'
		var slideTo = ( slideTo+1 )? slideTo : null;
		if ( slideTo != null ) $next = $('#slideshow A').eq(slideTo);
		
		$next.css({opacity: 0.0})
			 .addClass('active')
			 .animate({opacity: 1.0}, 1000, function() {
				 $active.removeClass('active last-active');
			 });	
	}
	
}

$(document).ready(function() {

	// Clears interval on hover over image and resume playing on mouse out
	$('#slideshow').hover(function() {
	    clearInterval(playSlideshow);
		},
		function() {
			playSlideshow =  setInterval( "slideSwitch()", 4000 ); // Interval after mouseover
	});
	
	// Adds 'current' class to active link
	//  $('.promo-button').click(function(){
	//  $('.promo-button').removeClass('current');
	//  $(this).addClass('current');
	//});
	
	// hide all images except first to avoid initial flicker
	$("#slideshow A").css({opacity: 0.0});
	$("#slideshow A:first").css({opacity: 1.0});
	
	// use setInterval to traverse list
	var playSlideshow = setInterval( "slideSwitch()", 3000 ); // Default Interval
	
	// create buttons to move to specific slide
	var $slideButtons = $("#promo-buttons-container a.promo-button");
	$slideButtons.click(function(){
		// stop the slideshow, to keep it from trying to overlap our transition
		clearInterval(playSlideshow);
		// call the function using the index of the clicked button
		//alert($(this).html());
		if ($(this).hasClass("active")) {
			
		}
		else {
			slideSwitch( $slideButtons.index(this) );
		}
		// restart the slideshow
		playSlideshow = setInterval( "slideSwitch()", 30000 ); // Interval after clicking a link below
	});
});
