bannerManager = function()
{
	var me = this;
	
	me.banners = [];
	me.currentBannerIndex = 0;
	me.transitionSpeed = 1000;
	me.transitionIntervalTime = 5000;
	me.transitionInterval = null;
	
	me.init = function()
	{
		me.transitionInterval = setTimeout(me.showNextBanner, me.transitionIntervalTime);
	}
	
	me.addBanner = function(fileName, fileCaption)
	{
		banner = new bannerImage();
		banner.caption = fileCaption;
		banner.setImage(fileName);
		
		me.banners.push(banner);
	}
	
	me.showNextBanner = function()
	{
		if (++me.currentBannerIndex >= me.banners.length) me.currentBannerIndex = 0;
		nextBannerIndex = me.currentBannerIndex;
		
		nextBanner = me.banners[nextBannerIndex];
		
		if (nextBanner.isLoaded) {
			$('figure.bannerIndex').animate({
				opacity: 0
			}, me.transitionSpeed, function(){
				$('img', this).attr('src', nextBanner.image.src);
				$('figcaption', this).hide().text(nextBanner.caption);
				
				$(this).animate({
					opacity: 1
				}, me.transitionSpeed, function(){
					if (nextBanner.caption != '') {
						$('figcaption', this).slideDown();
							//.css('height', 30)
							//.css('width', 0)
							//.css('overflow', 'hidden')
							//.show()
							//.animate({width: '300px'});
					}
				})
			});
			
			nextTimeout = me.transitionIntervalTime;
		} else {
			nextTimeout = 100;
		}
		
		me.transitionInterval = setTimeout(me.showNextBanner, me.transitionIntervalTime);
	}
}

bannerImage = function()
{
	var me = this;
	
	me.image = '';
	me.caption = '';
	me.isLoaded = false;
	
	me.setImage = function(fileName)
	{
		me.image = new Image();
		me.image.src = fileName;
		
		$(me.image).load(function(){
			me.isLoaded = true;
		});
	}
}
