/**
 * Classe para renderizar galeria de banners
 * @param {Object} $banners
 * @param {Object} $thumbs
 * @param {String} $caption
 */
var bannerGallery = {
	_banner:[],
	_thumb:[],
	_caption:'',
	_active:1,
	_interval:4000,
	_idInterval:0,
	init:function($banners, $thumbs,$caption){
		this._banner = $($banners);
		this._thumb = $($thumbs);
		this._caption = $caption;
		this.showBanner(this._active);
		
		$.each(this._thumb,function(i){
			$(this).click(function(){
				bannerGallery.stop();
				bannerGallery.showBanner(i+1);
				setTimeout(function(){bannerGallery.play()},bannerGallery._interval);
			});
		});
			
		this.play();
	},
	showBanner:function(i){
		$(this._banner).css({
			/*position:'absolute',*/
			/*left:'0px',*/
			opacity:0,
			display:'none'
		}).eq(i-1)
			.css({display:'block'})
			.animate({
				opacity:1
			},{
				duration: 1400,
				easing:'easeOutCirc'
		});
		$(this._caption).text($(this._banner).eq(i-1).find('img').attr('alt'));
		this._active = i;
		
		this._thumb.find('span').removeClass('over');
		this._thumb.eq(i-1).find('span').addClass('over');
		/*
		if(window["Cufon"]) {
			Cufon.replace('.sp-text');
		}
		*/
	},
	play:function(){
		this._idInterval = setInterval(function(){
			if(bannerGallery._active == bannerGallery._banner.length)
				bannerGallery._active = 1;
			else
				bannerGallery._active++;
				
			bannerGallery.showBanner(bannerGallery._active);
		},this._interval);
	},
	stop:function(){
		clearInterval(this._idInterval);
	}
}