(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();
		
		// toggle the visibility of the navigation bar
		var toggleBannerNav = function () {
			bottomVal = parseInt($bannerNav.css('bottom')) >= 0 ? '-50px' : '0px';
			$bannerNav.stop().animate({'bottom':bottomVal}, animationDelay);
		};
		// hide the navbar initially
		setTimeout(toggleBannerNav,(rotationDelay / 2));
		// toggle the navbar position on mouseover/mouseleave
		$bannerNav.bind('mouseenter mouseleave', toggleBannerNav);
		
		// 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);
				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);