function createAnimatedBanner(element, data, initialImageIndex) {
	var images = [];
	var links = [];
	data.each(function(datum) {
		images.push(datum.image);
		links.push(datum.link);
	});
	window.addEvent('domready', function() {
		var bannerId = element.getElement('input[name=animated_banner_id]');
		if (bannerId) {
			var bannerIdValue = bannerId.get('value');
			bannerId.dispose();
			bannerId = bannerIdValue;
		}
		if (!bannerId) bannerId = 0;
		
		if (window.ie6) {
			try {
				document.execCommand('BackgroundImageCache', false, true);
			} catch(e) { }
		}
		element.setStyle('backgroundImage', 'url(' + images[initialImageIndex] + ')');
		var bannerImages = new Asset.images(images, {
			onComplete : function() {
				var banner = element;
				if (banner) {
					
					banner.setStyle('position', 'relative');
					
					var bannerCoordinates = banner.getCoordinates();
					
					// Create the div that is to fade.
					var fadingDiv = new Element('div', {
						styles : {
							width : bannerCoordinates.width + 'px',
							height : bannerCoordinates.height + 'px',
							opacity : 0,
							backgroundPosition : 'top left',
							backgroundRepeat : 'no-repeat',
							position : 'absolute'
						}
					}).inject(banner, 'top');
					
					var navigationList = new Element('ul', {
						'class' : 'banner-navigation'
					}).inject(banner, 'bottom');
					
					var navigationButtons = [];
					for (var imageIndex = 0; imageIndex < images.length; ++imageIndex) {
						navigationButtons.push(new Element('li', {
							text : imageIndex + 1,
							events : {
								click : function(e) {
									var index = parseInt(e.target.get('text')) - 1;
									fadeToNewImage(index);
								}
							}
						}).inject(navigationList));
					}
					navigationButtons[initialImageIndex].addClass('selected');
					
					var progressSpinner = new Element('li', {
						'class' : 'progress',
						position : 'absolute'
					}).inject(navigationList);
					
					if (window.ie6) {
						progressSpinner.setStyle(progressSpinner.getStyle('background-image').replace(/\.png/, '.gif'));
					}
					
					var progressSpinnerFades = !/MSIE/.test(navigator.userAgent);
					
					var setProgress = function(progress) {
						progress = Math.round(progress * 64);
						if (progress < 0) progress = 0;
						if (progress > 63) progress = 63;
						var row = Math.floor(progress / 8);
						var column = progress % 8;
						progressSpinner.setStyle('background-position', -(column * 20) + 'px -' + (row * 20) + 'px');
					}
					
					var fader = new Fx.Tween(fadingDiv, {
						property : 'opacity',
						duration : 1000,
						link : 'cancel'
					});
					// The function that is used to fade divs.
					var currentImage = initialImageIndex;
					var fadingToNewImage = false;
					var fadeToNewImage = function(index) {
						fadingToNewImage = true;
						autoAdvanceProgress = 0;
						if (progressSpinnerFades) {
							progressSpinner.fade('out');
						} else {
							progressSpinner.setStyle('display', 'none');
							setProgress(0);
						}
						currentImage = index;
						Cookie.write('the_think_tank::animated_banner_image_index::' + bannerId, currentImage, { duration: 15 / (60 * 60 * 24) });
						fadingDiv.setStyles({
							opacity : 1,
							backgroundImage : banner.getStyle('backgroundImage')
						});
						(function() {
							banner.setStyle('backgroundImage', 'url(' + bannerImages[index].src + ')');
						}).delay(1);
						for (var i = 0; i < navigationButtons.length; ++i) {
							if (i == index) {
								navigationButtons[i].addClass('selected');
							} else {
								navigationButtons[i].removeClass('selected');
							}
						}
						fader.start(0).chain(function() {
							
							if (progressSpinnerFades) {
								progressSpinner.fade('in');
							} else {
								progressSpinner.setStyle('display', 'block');
							}
							fadingToNewImage = false;
						});
					};
					
					var autoAdvanceProgress = 0;
					(function() {
						if (fadingToNewImage) return;
						setProgress(autoAdvanceProgress += 1 / 64);
						if (autoAdvanceProgress > 1) {
							fadeToNewImage((currentImage + 1) % images.length);
						}
					}).periodical(100);
					
					banner.addEvent('click', function(e) {
						if (e.target == banner) {
							var link = links[currentImage];
							if (link) window.location.href = link;
						}
					});
					
				}
			}
		});	
	});
}
