/**
 *	Determines the current banner and its position, then calculates
 *	the new banners left backround position, animates to it and resets
 *	the class on the banner.
 */
function animateBanner() {
	var $banner = $('#banner');
	var bannerCount = 5;
	var bannerWidth = 350;

	var currentBanner = parseInt($banner.attr('class').replace('b', ''));
	var currentLeftPosition = ((bannerWidth * currentBanner) - bannerWidth) * -1;

	if (currentBanner < 5) {
		var newBanner = currentBanner;
		newBanner++;
		var newLeftPosition = currentLeftPosition + -350;
	} else {
		var newBanner = 1;
		var newLeftPosition = 0;
	}

	$banner.animate({
		'backgroundPosition': newLeftPosition + 'px 0'
	}, 3750, 'easeOutExpo', function() {
		$banner.removeClass('b' + currentBanner).addClass('b' + newBanner);
	});
}

$(document).ready(function() {

	/**
	 *	Makes link elements with a rel attribute
	 *	of external open in a new window.
	 */
	$('a[rel*="external"]').bind('click', function(e) {
		console.log(this.href);
		window.open($(this).attr('href'));
		e.preventDefault();
	});

	/**
	 *	A script that runs every twelve seconds to
	 *	animate the banner in the header.
	 */
	setInterval(animateBanner, 12000);

});
