//DataManager Object
Ext.namespace('ZeeZor.graphics');
ZeeZor.graphics.BannerManager = Ext.extend(Ext.Component,
{
	currentBannerIndex: -1,
	tweenDuration: 2,
	timeout: 15,
	
	initComponent: function()
	{
		this.banners = Ext.get('banners').query('div');
		this.currentBannerIndex = Math.floor(Math.random()*this.banners.length);
	},

	waitToShowNextBanner: function(scope)
	{
		setTimeout(function(){scope.showNextBanner(scope)}, this.timeout * 1000);
	},
	
	showNextBanner: function(scope)
	{
		if (scope == null)
		{
			scope = this;
		}
		if (scope.banners[scope.currentBannerIndex] != null)
		{
			Ext.fly(scope.banners[scope.currentBannerIndex]).fadeOut({duration: scope.tweenDuration});
		}
		scope.currentBannerIndex = (scope.currentBannerIndex < (scope.banners.length-1) ? (scope.currentBannerIndex+1) : 0);
		if (scope.banners[scope.currentBannerIndex] != null)
		{
			Ext.fly(scope.banners[scope.currentBannerIndex]).fadeIn({duration: scope.tweenDuration});
		}

//		if (Ext.get('banner_'+scope.currentBannerIndex) != null)
//		{
//			Ext.get('banner_'+scope.currentBannerIndex).fadeOut({duration: scope.tweenDuration});
//		}
//		scope.currentBannerIndex = (scope.currentBannerIndex < (scope.banners.length-1) ? (scope.currentBannerIndex+1) : 0);
//		if (Ext.get('banner_'+scope.currentBannerIndex) != null)
//		{
//			Ext.get('banner_'+scope.currentBannerIndex).fadeIn({duration: scope.tweenDuration});
//		}
		scope.waitToShowNextBanner(scope);
	}
});

