var Banners = new Class
({
	//Variaveis de efeito
	effect: "fade",
	effectType: "in",
	hideEffectType: "out",
	changeTime: "1000",
	effectPosition: "horizontal", //Usado somente em slide	
	
	containersType: 'li',
	
	activatedClass: "active",
	inactivatedClass: "inactive",

	currentBanner: '0',
	totalBanners: '0',
	
	banners: new Array(),
	
	timeOutId: null,

	initialize: function(params)
	{
		this.effect = params.type;
		this.effectType = params.effectType;
		this.setHideType(this.effectType);
		this.effectPosition = params.effectPosition;
		
		//Tempo de duração do efeito
		this.changeTime = params.changeTime;
		
		this.banners = $(params.containerId).getChildren(this.containerType);
		this.totalBanners = this.banners.length;
		
		if(this.totalBanners)
			this.start();
	},
	
	start: function()
	{
		this.changeBanner();
	},
	
	changeBanner: function(index)
	{
		if(index != null)
		{
			this.currentBanner = index;
			clearTimeout(this.timeOutId);
		}
		else
		{
			if(this.currentBanner == this.totalBanners)
				this.currentBanner = 0;
		}
		
		this.doEffect(this.currentBanner);
		++this.currentBanner;
		this.setTimeOut();
	},
	
	setTimeOut: function()
	{
		var that = this;
		this.timeOutId = window.setTimeout( function() {
		    that.changeBanner();
		}, this.changeTime );
	},
	
	doEffect: function(index)
	{
		/*alert(index);
		alert(this.currentBanner);
		alert(this.totalBanners);*/
		var that = this;
		var banner = this.banners[index];
		if(this.effect == 'fade')
			banner.fade(this.effectType);
		else if(this.effect == 'slide')
			banner.slide(this.effectType, [this.effectPosition]);
		
		$each(this.banners, function(element)
		{	
			if(element.id != banner.id)
			{
				if(that.effect == 'fade')
					element.fade(that.hideEffectType);
				else if(that.effect == 'slide')
					element.slide(that.hideEffectType, [that.effectPosition]);
			}
		});		
	},
	
	setHideType: function(effectEffectType)
	{	
		switch(effectEffectType)
		{
			case 'in':
				this.hideEffectType = 'out';
			break;
			
			case 'show':
				this.hideEffectType = 'hide';
			break;
		}
	}
});


var BannerNavegacao = new Class
({
	Extends: Banners,

	previous: function()
	{
		clearTimeout(this.timeOutId);

		--this.currentBanner;

		if(this.currentBanner == 0)
			this.currentBanner = this.totalBanners - 1;
		else
			--this.currentBanner;

		this.changeBanner(this.currentBanner);
	},

	next: function()
	{
		clearTimeout(this.timeOutId);

		if(this.currentBanner == this.totalBanners)
			this.currentBanner = 0;

		this.changeBanner(this.currentBanner);
	}
});
