(function ($) {
	$(function () {
		// setup
		var $bannerImage = $('div#bannerArea');
		var $banners = $('a.banner', $bannerImage);
		var $bannerNav = $('ul', $bannerImage);
		var $bannerLinks = $('li > a', $bannerNav);
		var animationDelay = 500;
		var rotationDelay = 5000;
		$banners.not(':first-child').hide();
	
		// rotation
		var rotateImages = function () {
			$currentBanner = $banners.filter(':visible').fadeOut(animationDelay);
			$currentLink = $bannerLinks.filter('.current').removeClass('current');
			$nextBanner = $currentBanner.next('.banner').length ? $currentBanner.next('.banner') : $banners.filter(':first-child');
			$nextLink = $bannerLinks.filter('.link_' + $nextBanner.attr('id'));
			$nextBanner.fadeIn(animationDelay);
			$nextLink.addClass('current');
		};
		rotationInterval = setInterval(rotateImages, rotationDelay);
		
		// jump links
		$bannerLinks.bind('click', function (e) {
			e.preventDefault();
			$this = $(e.currentTarget);
			if (!$this.hasClass('current')) {
				// next two lines clear/set (reset) rotation interval
				clearInterval(rotationInterval);
				//image no longer rotates once clicked
				//rotationInterval = setInterval(rotateImages, rotationDelay);
				target = $this.attr('href');
				$bannerLinks.filter('.current').removeClass('current');
				$banners.filter(':visible').fadeOut(animationDelay);
				$this.addClass('current');
				$banners.filter(target).fadeIn(animationDelay);
			}
		});
	});
})(jQuery);
