



var activeBanner = 0;

var slideWidth = 0;

var timer = null;

var timeout = 7; // seconds

$(function() {

	// google analytics
	// not removed just done differently now. 
// 	$('a').each(function(index, element) {
//
// 		if ( $(element).attr('googleAnalytics') ) {
// 			$(element).click(function(event) {
//
// 				event.preventDefault();
//
// 				// load the tracker
// 				_gat._getTrackerByName()._trackEvent('Outbound Links', $(this).attr('googleAnalytics'));
//
// 				var linkValue = $(this).attr('href');
// 				window.open(linkValue);
//
// 				return false;
//
// 			});
// 		}
//
// 	});

	// get the width that we need to slide out.
	slideWidth = parseInt($('#imageBanners').width()) + 10;

	// some css values that are required by the parent container
	$('#imageBanners').css('position', 'relative');
	$('#imageBanners').css('overflow', 'hidden');

	// set the initial position of the sliding entries.
	$('#imageBanners').find('img').each(function(index,value) {
		$(value).css('position', 'absolute');
		$(value).css('top', '0px');
		if ( index == 0 ) {
			$(value).css('left', '0px');
		} else {
			$(value).css('left', slideWidth + 'px');
		}

		$(value).show();
	});

	if ( $('#imageBanners').find('img').length > 1 ) {

		// attach to the left click
		$('#leftNav').click(function(event) {
			event.preventDefault;

			previousBanner(true);

			return false;
		});

		// attach to the right click
		$('#rightNav').click(function(event) {
			event.preventDefault;

			nextBanner(true);

			return false;
		});

		// fire up the timer.
		timer = setTimeout('nextBanner(false)', timeout * 1000);

	} else {

		// hide the navigation links
		$('#leftNav').hide();
		$('#rightNav').hide();

	}

});

function nextBanner(clicked) {

	if ( activeBanner >= $('#imageBanners').find('img').length - 1 ) {
		//return false;
	}

	if ( timer ) {
		clearTimeout(timer);
	}

	// slide out the current image.
	slideOutBanner('l');

	if ( activeBanner >= $('#imageBanners').find('img').length - 1 ) {
		// increase the active element
		activeBanner = 0;
	} else {
		// increase the active element
		activeBanner++;
	}


	// slide in the new image.
	slideInBanner('l');

	if ( clicked ) {
		// fire up the timer.
		timer = setTimeout('nextBanner(false)', (3 * timeout) * 1000);
	} else {
		// fire up the timer.
		timer = setTimeout('nextBanner(false)', timeout * 1000);
	}
}

function previousBanner(clicked) {
	if ( activeBanner <= 0) {
		//return false;
	}

	if ( timer ) {
		clearTimeout(timer);
	}

	// slide out the current image.
	slideOutBanner('r');

	if ( activeBanner <= 0) {
		activeBanner = $('#imageBanners').find('img').length - 1;
	} else {
		// increase the active element
		activeBanner--;
	}

	// slide in the new image.
	slideInBanner('r');

	// do the pointer update
	swapYearPointer();

	// do the text overlay update
	swapTextOverlay();

	if ( clicked ) {
		// fire up the timer.
		timer = setTimeout('previousBanner(false)', (3 * timeout) * 1000);
	} else {
		// fire up the timer.
		timer = setTimeout('previousBanner(false)', timeout * 1000);
	}
}

function slideOutBanner(direction) {
	if ( direction == 'l' ) {
		$($('#imageBanners').find('img')[activeBanner]).animate({left: '-' + slideWidth + 'px'});
	} else if ( direction == 'r' ) {
		$($('#imageBanners').find('img')[activeBanner]).animate({left: slideWidth + 'px'});
	}
}

function slideInBanner(direction) {
	if ( direction == 'l' ) {
		$($('#imageBanners').find('img')[activeBanner]).css('left' , slideWidth + 'px');
	} else if ( direction == 'r' ) {
		$($('#imageBanners').find('img')[activeBanner]).css('left' , '-' + slideWidth + 'px');
	}
	$($('#imageBanners').find('img')[activeBanner]).animate({left: '0px'});
}

function recordOutboundLink(link, category, action) {
    _gat._getTrackerByName()._trackEvent(category, action);
    if ( link.href != '#' ) {
    	setTimeout('document.location = "' + link.href + '"', 100);
    }
}

function recordOutboundLinkNoLink(link, category, action) {
    _gat._getTrackerByName()._trackEvent(category, action);
}




