/* GO BANNER GO */
$(function(){
	window.banner = new BannerFlutuante( BANNER );
//	banner.init(); 	
});
function openBanner() {
    banner.init();
}
function closeBanner() {
    banner.hide();
}

/* Class: BannerFlutuante */
function BannerFlutuante( opt )
{
	/* CONFIGURACOES DO BANNER FLUTUANTE */
	this.CONFIG = {
		/* ID DO CONTAINER */
		CONTAINER_ID	: 'bannerFlutuante',
		
		/* LARGURA */
		CONTAINER_WIDTH	: 0,
		
		/* ALTURA */
		CONTAINER_HEIGHT: 0,
		
		/* DISTANCIA CENTRALIZADA */
		CONTAINER_TOP	: '0',
		CONTAINER_LEFT	: '0',
		
		/* URL DO SWF */
		SWF_PATH		: '',
		
		/* QUANTOS SEGUNDOS ATE ESCONDER O BANNER */
		TIMER			: 1000,
		
		/* TRANSPARENCIA */
		TRANSPARENT		: true
	}
	
	if ( typeof opt != 'undefined' )
		this.CONFIG = $.extend( this.CONFIG, opt );
	
	/* CRIA BANNER */
	this.createDOM = function()
	{
		$( document.body )
			.append('<div id="' + this.CONFIG.CONTAINER_ID + '"></div>');
			
		$( 'div#' + this.CONFIG.CONTAINER_ID )
			.css({		        
				'display'	    : 'none',
				'position'	    : 'absolute',
				'z-index'	    : '1200',
				'width'		    : this.CONFIG.CONTAINER_WIDTH + 'px',
				'height'	    : this.CONFIG.CONTAINER_HEIGHT + 'px',
				'top'		    : this.CONFIG.CONTAINER_TOP,
				'left': this.CONFIG.CONTAINER_LEFT,
				'margin': '0 auto',
				'margin-left' :  ( - ( this.CONFIG.CONTAINER_WIDTH / 2 ) ) + 'px'
			//	'margin'	    : this.CONFIG.CONTAINER_TOP.indexOf( '%' ) != -1 ? ( - ( this.CONFIG.CONTAINER_HEIGHT / 2 ) ) + 'px 0 0 ' + ( - ( this.CONFIG.CONTAINER_WIDTH / 2 ) ) + 'px' : ''
			})
			.append( '<div id="bannerFlutuante_flashContainer"></div>' );
			
		swfobject.embedSWF( this.CONFIG.SWF_PATH, this.CONFIG.CONTAINER_ID + '_flashContainer', this.CONFIG.CONTAINER_WIDTH, this.CONFIG.CONTAINER_HEIGHT, '9.0.0', null, {}, this.CONFIG.TRANSPARENT ? { 'wmode': 'transparent', 'scale' : 'noscale' } : {} );
		
		//criar bg
		$( document.body )
			.append('<div id="bgBanner"></div>');
			
		$( 'div#bgBanner')
			.css({		        
				'background'    : '#fff',
				'filter'        : 'alpha(opacity=50)',
				'opacity'       : '0.5',
				'position'	    : 'absolute',
				'z-index'	    : '1199',
				'width'		    : '100%',
				'height'		: '100%',
			//	'height'	    : $( "body" ).height() + 'px',
				'top'		    : '0',
				'left'          : '0'				
				
		})	
	}
	
	/* TEMPORIZADOR DE EXIBICAO */
	this.timer = function()
	{
		var _this = this;
		
		setTimeout(function(){ _this.hide() }, this.CONFIG.TIMER * 1000 );
	}

	/* EXIBE BANNER */
	this.show = function()
	{
		var obj = $( '#' + this.CONFIG.CONTAINER_ID );		
		obj.show();
		
		var bg = $( 'div#bgBanner' );		
		bg.show();
	}
	
	/* ESCONDE BANNER */
	this.hide = function()
	{	    
		var obj = $( '#' + this.CONFIG.CONTAINER_ID );		
		obj.hide();
		var bg = $( 'div#bgBanner' );		
		bg.hide();
	}
	
	/* INICIALIZACAO */
	this.init = function()
	{
		this.createDOM();
		this.show();
		this.timer();
	}
}
