function Esconde() 
{
	document.getElementById('banner-float').style.display = 'none';
}
jQuery( function( $ )
{
	/**
	 *
	 * Vídeos 
	 * http://www.gaflon.com.br
	 *
	 **/
	if( exists( 'p.novidadesRight' ) )
	{

		/**
		 *
		 * Abre o player dos áudios em um popup
		 *
		 **/
		$( 'p.novidadesRight a' ).click( function( )
		{

			/**
			 *
			 * Configurações do popup
			 *
			 **/
			var	properties  = '';
				properties += 'width'		+ '=' + 450	+ ',';
				properties += 'height'		+ '=' + 380	+ ',';
				properties += 'toolbar'		+ '=' +  0	+ ',';
				properties += 'location'	+ '=' +  0	+ ',';
				properties += 'status'		+ '=' +  0	+ ',';
				properties += 'menubar'		+ '=' +  0	+ ',';
				properties += 'scrollbars'	+ '=' +  0	+ ',';
				properties += 'resizable'	+ '=' +  0	+ ',';
				properties += 'top'			+ '=' + 150 + ',';
				properties += 'left'		+ '=' + ( ( screen.width - 450 ) / 2 );



			/**
			 *
			 * Abre o popup
			 *
			 **/
			window_open( $( this ).attr( 'href' ), 'player', properties );


			return false;

		});

	}




	/**
	 *
	 * Fale Conosco
	 * http://www.gaflon.com.br/fale-conosco.php
	 *
	 **/
	if( exists( 'form#form-contato' ) )
	{

		/**
		 *
		 * Máscaras
		 *
		 **/
		$( 'input#telefone' ).setMask( 'phone' );
		$( 'input#celular' ).setMask( 'phone' );



		/**
		 *
		 * Validação do formulário de contato
		 *
		 **/
		$( 'form#form-contato' ).submit( function( )
		{

			// Nome
			if( is_empty( 'input#nome' ) )
			{
				alert( 'Informe seu nome!' );
				$( 'input#nome' ).focus( );
				return false;
			}

			// E-mail
			if( is_empty( 'input#email' ) )
			{
				alert( 'Informe seu e-mail!' );
				$( 'input#email' ).focus( );
				return false;
			}
			else if( !validate_field( 'email', $( 'input#email' ).val( ) ) )
			{
				alert( 'E-mail inválido! Verifique o e-mail informado' );
				$( 'input#email' ).focus( );
				return false;
			}

			// Telefone
			if( !is_empty( 'input#telefone' ) )
			{
				if( !validate_field( 'telefone', $( 'input#telefone' ).val( ) ) )
				{
					alert( 'Telefone inválido! Verifique o telefone informado' );
					$( 'input#telefone' ).focus( );
					return false;
				}
			}

			// Celular
			if( !is_empty( 'input#celular' ) )
			{
				if( !validate_field( 'telefone', $( 'input#celular' ).val( ) ) )
				{
					alert( 'Celular inválido! Verifique o celular informado' );
					$( 'input#celular' ).focus( );
					return false;
				}
			}

			// Mensagem
			if( is_empty( 'textarea#mensagem' ) )
			{
				alert( 'Escreva sua mensagem!' );
				$( 'textarea#mensagem' ).focus( );
				return false;
			}

		});

	}
	
	
	
	/**
	 *
	 * Abre o link em uma nova janela
	 *
	 **/
	$( 'a.window-open' ).live( 'click', function( )
	{

		window_open( $( this ).attr( 'href' ), ( $( this ).attr( 'rel' ) ) ? $( this ).attr( 'rel' ) : $( this ).attr( 'href' ) );
		return false;

	});



	/**
	 *
	 * Carrega a função que evita abertura de janelas com o mesmo contéudo
	 *
	 **/
	prevent_duplicated_windows;



});



/**
 *
 * Verifica se o campo está vazio
 *
 * @param element: Elemento que será validado
 * @return Boolean
 *
**/
function is_empty( element )
{
	return ( $( element ).val( ) === '' ) ? true : false;
}



/**
 *
 * Verifica se o valor do input/textarea é igual ao valor informado
 *
 * @param element: Elemento que será validado
 * @param comparare_with: Valor que será utilizado na comparação
 * @return Boolean
 *
**/
function is_equals( element, comparare_with )
{
	return ( $( element ).val( ) == comparare_with ) ? true : false;
}



/**
 *
 * Verifica o tamanho (length) informado no input de acordo com a operação especificada
 *
 * @param element: Elemento que será validado
 * @param operation: Operação que será efetuada
 * @param comparare_with: Valor que será utilizado na comparação
 *
**/
function length_of( element, operation, comparare_with )
{
	var value_length = $( element ).val( ).length;
	var result = false;

	switch( operation )
	{
		case '>':
			result = ( value_length > comparare_with ) ? true : false;
			break;

		case '>=':
			result = ( value_length >= comparare_with ) ? true : false;
			break;

		case '<':
			result = ( value_length < comparare_with ) ? true : false;
			break;

		case '<=':
			result = ( value_length <= comparare_with ) ? true : false;
			break;

		case '==':
			result = ( value_length == comparare_with ) ? true : false;
			break;

		case '!=':
			result = ( value_length != comparare_with ) ? true : false;
			break;
	}

	return result;
}



/**
 *
 * Verifica se o elemento existe no DOM
 *
 * @param element: Elemento que será verificado
 * @return Boolean
 *
**/
function exists( element )
{
	return ( $( element ).length >= 1 ) ? true : false;
}



/**
 *
 * Busca um determinado valor em um array
 *
 * @param val: Valor que será procurado no array
 * @return boolean
 *
 **/
Array.prototype.in_array = function( val )
{

	var array_length = this.length;


	for( var i = 0; i < array_length; i++ )
	{
		if( this[ i ] == val )
		{
			return true;
		}
	}

	return false;
}



/**
 *
 * Procura por um valor em array e retorna o repectivo índice caso seja encontrado
 *
 * @param val: Valor que será procurado
 * @param array: Array onde o valor será procurado
 * @return String
 *
 **/
function array_search( val, array )
{
	var key = '';

	for( key in array )
	{
		if( array[ key ] == val )
		{
			return key;
		}
	}

	return false;

}



/**
 *
 * Verifica se o índice informado existe em um array
 *
 * @param key: Índice que será procurado
 * @return Int
 *
 **/
Array.prototype.array_key_exists = function( key )
{
	if ( !this || ( this.constructor !== Array && this.constructor !== Object ) )
	{
		return false;
	}

	return key in this;
}



/**
 *
 * Retorna a string informada repetida o número de vezes definido pela variável "repeat"
 *
 * @param string: Texto (string) que será repetida
 * @param repeat: Define o número de vezes que a string será repetida
 * @return String
 *
 **/
function str_repeat( string, repeat )
{
	return new Array( repeat + 1 ).join( string ); 
}



/**
 *
 * Preenche uma strong com um determinado valor definido
 *
 * @param input: Valor que será preenchido
 * @param pad_length: Tamanho (número de caracteres) do valor final
 * @param pad_string: O que será utilizado no preenchimento
 * @param pad_type: Define se será um preenchimento à esquerda (STR_PAD_LEFT), à direita (STR_PAD_RIGHT) ou em ambos (STR_PAD_BOTH)
 * @return String
 *
 **/
function str_pad( input, pad_length, pad_string, pad_type )
{
	var half = '';
	var pad_to_go;

	var str_pad_repeater = function( s, len )
	{
		var collect = '';
		var i;

		while( collect.length < len )
		{
			collect += s;
		}

		collect = collect.substr( 0, len );

		return collect;
	};


	input += '';
	pad_string = pad_string !== undefined ? pad_string : ' ';


	if( pad_type != 'STR_PAD_LEFT' && pad_type != 'STR_PAD_RIGHT' && pad_type != 'STR_PAD_BOTH' )
	{
		pad_type = 'STR_PAD_RIGHT';
	}


	if( ( pad_to_go = pad_length - input.length ) > 0 )
	{
		if( pad_type == 'STR_PAD_LEFT' )
		{
			input = str_pad_repeater( pad_string, pad_to_go ) + input;
		}
		else if( pad_type == 'STR_PAD_RIGHT' )
		{
			input = input + str_pad_repeater( pad_string, pad_to_go );
		}
		else if( pad_type == 'STR_PAD_BOTH' )
		{
			half	= str_pad_repeater( pad_string, Math.ceil( pad_to_go / 2 ) );
			input	= half + input + half;
			input	= input.substr( 0, pad_length );
		}
	}

	return input;
}



/**
 *
 * Valida o valor do campo informado, utilizando Expressões Regulares
 *
 * @param type: Tipo de campo que será validado
 * @param value: Valor informado no campo que será validado
 * @return Boolean
 *
 **/
function validate_field( type, value )
{

	var filter;


	if( type == 'cnpj' )
	{
		return validate_cnpj( value );
	}
	else if( type == 'cpf' )
	{
		return validate_cpf( value );
	}
	else
	{

		switch( type )
		{
			case 'email':
				filter = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i;
				break;
	
			case 'url':
				filter = /^(http(s)?\:\/\/)?(localhost|[a-zA-Z0-9\.-]+\.[a-zA-Z]{2,3})((\/\S*)|(\/)[a-zA-Z0-9\.\?\/\{\}_%=&+-]+)?$/;
				break;
	
			case 'telefone':
				filter = /^\([0-9]{2}\) [0-9]{4}-[0-9]{4}$/;
				break;
	
			case '0800':
				filter = /^(0800) [0-9]{7}$/;
				break;
	
			case '0300':
				filter = /^(0300) [0-9]{7}$/;
				break;
	
			case 'servico-ddg':
				filter = /^(0[38]00) [0-9]{7}$/;
				break;
	
			case 'data':
				filter = /^(((0[1-9]|[12][0-9]|3[01])(\/)(0[13578]|1[02])(\/)[12][0-9]{3})|((0[1-9]|[12][0-9]|30)(\/)(0[469]|11)(\/)[12][0-9]{3})|((29)(\/)(02)(\/)(1804|1808|1812|1816|1820|1824|1828|1832|1836|1840|1844|1848|1852|1856|1860|1864|1868|1872|1876|1880|1884|1888|1892|1896|1904|1908|1912|1916|1920|1924|1928|1932|1936|1940|1944|1948|1952|1956|1960|1964|1968|1972|1976|1980|1984|1988|1992|1996|2000|2004|2008|2012|2016|2020|2024|2028|2032|2036|2040|2044|2048|2052|2056|2060|2064|2068|2072|2076|2080|2084|2088|2092|2096|2104|2108|2112|2116|2120|2124|2128|2132|2136|2140|2144|2148|2152|2156|2160|2164|2168|2172|2176|2180|2184|2188|2192|2196))|((0[1-9]|[12][0-8])(\/)(02)(\/)[12][0-9]{3}))$/;
				break;
	
			case 'mes-ano':
				filter = /^(0[1-9]|1[012])(\/)[12][0-9]{3}$/;
				break;
	
			case 'hora':
				filter = /^([0-1][0-9]|2[0-3]):([0-5][0-9])$/;
				break;
	
			case 'cep':
				filter = /^[0-9]{5}-[0-9]{3}$/;
				break;
	
			case 'estado':
				filter = /^(AC|AL|AP|AM|BA|CE|DF|ES|GO|MA|MT|MS|MG|PA|PB|PR|PE|PI|RJ|RN|RS|RO|RR|SC|SP|SE|TO)$/;
				break;
	
			default:
				return false;
		}
	
		return ( filter.test( value ) ) ? true : false;

	}

}



/**
 *
 * Valida o número do CNPJ
 *
 * @param cnpj: Número do CNPJ que será validado
 * @return Boolean
 *
 **/
function validate_cnpj( cnpj )
{

	var filter_cnpj = /^([0-9]{2})\.([0-9]{3})\.([0-9]{3})\/([0-9]{4})\-([0-9]{2})$/;


	if( !filter_cnpj.test( cnpj ) )
	{
		return false;
	}
	else
	{
		var sum1 = 0, sum2 = 0, sum3 = 0, calc1 = 5, calc2 = 6;
		cnpj = cnpj.replace( /[.\/-]/g, '' );
	}

	for( var i = 0; i <= 12; i++ )
	{
		calc1 = ( calc1 < 2 ) ? 9 : calc1;
		calc2 = ( calc2 < 2 ) ? 9 : calc2;

		if( i <= 11 )
		{
			sum1 += cnpj.charAt( i ) * calc1;
		}

		sum2 += cnpj.charAt( i ) * calc2;
		sum3 += cnpj.charAt( i );
		calc1--;
		calc2--;
	}

	sum1 %= 11;
	sum2 %= 11;

	return ( sum3 && cnpj.charAt( 12 ) == ( sum1 < 2 ? 0 : ( 11 - sum1 ) ) && cnpj.charAt( 13 ) == ( sum2 < 2 ? 0 : ( 11 - sum2 ) ) ) ? true : false;
}



/**
 *
 * Valida o número do CPF
 *
 * @param cpf: Número do CPF que será validado
 * @return Boolean
 *
 **/
function validate_cpf( cpf )
{
	for( i = 0; i <= 9; i++ )
	{
		i = i.toString( );

		if( cpf == i + i + i + '.' + i + i + i + '.' + i + i + i + '-' + i + i )
		{
			return false;
		}
	}

	soma = 0;
	cpf = cpf.replace( /\./g, '' ).replace( /-/g, '' );
	for( n = 0; n < 9; n++ )
	{
		soma += parseInt( cpf.charAt( n ) ) * ( 10 - n );
	}

	resto = 11 - ( soma % 11 );

	if( resto == 10 || resto == 11 )
	{
		resto = 0;
	}

	if( resto != parseInt( cpf.charAt( 9 ) ) )
	{
		return false;
	}

	soma = 0;

	for( i = 0; i < 10; i++ )
	{
		soma += parseInt( cpf.charAt( i ) ) * (11 - i);
	}

	resto = 11 - ( soma % 11 );

	if( resto == 10 || resto == 11 )
	{
		resto = 0;
	}

	if( resto != parseInt( cpf.charAt( 10 ) ) )
	{
		return false;
	}

	return true;
}



/**
 *
 * "Quebra" uma string utilizando um delimitador
 *
 * @param delimiter: Delimitador utilizado para "quebrar" a string
 * @param string: String que será "quebrada"
 * @param [limit]: Se indicado, define o número máximo de posições do novo array que será criado. Se o número for negativo, todos os componentes exceto
 * o último serão retornados.
 * @return Boolean / Array
 *
 **/
function explode( delimiter, string, limit )
{
	var empty_array = { 0 : '' };


	if( arguments.length < 2 || typeof arguments[ 0 ] == 'undefined' || typeof arguments[ 1 ] == 'undefined' )
	{
		return null;
	}


	if( delimiter === '' || delimiter === false || delimiter === null )
	{
		return false;
	}


	if( typeof delimiter == 'function' || typeof delimiter == 'object' || typeof string == 'function' || typeof string == 'object' )
	{
		return empty_array;
	}


	if( delimiter === true )
	{
		delimiter = '1';
	}


	if( !limit )
	{
		return string.toString( ).split( delimiter.toString( ) );
	}
	else
	{
		var splitted = string.toString( ).split( delimiter.toString( ) );

		var part_a = splitted.splice( 0, limit - 1 );
		var part_b = splitted.join( delimiter.toString( ) );

		part_a.push( part_b );

		return part_a;
	}

}



/**
 *
 * Limita a quantidade de caracteres exibidos e adiciona reticências após a última palavra inteira que será visualizada
 *
 * @param $string: String que será limitada
 * @param $limit: Número máximo de caracteres exibidos
 * @param [$only_first_paragraph]: Se indicado, será retornado apenas o primeiro parágrafo do texto. Padrão: false
 * @return String
 *
 **/
function limit_text( string, limit, only_first_paragraph )
{

	if( typeof only_first_paragraph != 'undefined' && only_first_paragraph )
	{
		string = explode( '\n', string );
		string = string[ 0 ];
	}


	if( string.length > limit )
	{
		string = string.substr( 0, limit );
		string = string.substr( 0, string.lastIndexOf( ' ' ) ) + ' ...';
	}


	return string;

}



/**
 *
 * Remove tags de uma string
 *
 * @param input: String que terá as tags removidas
 * @param [allowed]: Lista das tags que não serão removidas. Ex.: Para não remover as tags "<a>" e "<p>", "allowed" deverá estar "<a><p>"
 * @return String
 *
 **/
function strip_tags( input, allowed )
{

	allowed = ( ( ( allowed || '' ) + '' )
		.toLowerCase( )
		.match( /<[a-z][a-z0-9]*>/g ) || [] )
		.join( '' );


	var	tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi;
	var	comments_and_php_tags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi;


	return input.replace( comments_and_php_tags, '' ).replace( tags, function( $0, $1 )
	{
		return allowed.indexOf( '<' + $1.toLowerCase( ) + '>' ) > -1 ? $0 : '';
	});

}



/**
 *
 * Converte os caracteres especiais "&", "<", ">" e " (apsas duplas) de uma string para suas respectivas entidades HTML
 *
 * @param text: Texto que terá os caracteres especiais convertidos
 * @return String
 *
 **/
function htmlspecialchars( string, quote_style, charset, double_encode )
{

	var optTemp = 0, i = 0, noquotes = false;


	if( typeof quote_style === 'undefined' || quote_style === null )
	{
		quote_style = 2;
	}


	string = string.toString( );


	if( double_encode !== false )
	{
		string = string.replace( /&/g, '&amp;' );
	}


	string = string.replace( /</g, '&lt;' ).replace( />/g, '&gt;' );


	var OPTS = {
		'ENT_NOQUOTES'			: 0,
		'ENT_HTML_QUOTE_SINGLE'	: 1,
		'ENT_HTML_QUOTE_DOUBLE'	: 2,
		'ENT_COMPAT'			: 2,
		'ENT_QUOTES'			: 3,
		'ENT_IGNORE'			: 4
	};


	if( quote_style === 0 )
	{
		noquotes = true;
	}


	if( typeof quote_style !== 'number' )
	{

		quote_style = [ ].concat( quote_style );


		for( i = 0; i < quote_style.length; i++ )
		{
			if( OPTS[ quote_style[ i ] ] === 0 )
			{
				noquotes = true;
			}
			else if( OPTS[ quote_style[ i ] ] )
			{
				optTemp = optTemp | OPTS[ quote_style[ i ] ];
			}
		}

		quote_style = optTemp;

	}


	if( quote_style & OPTS.ENT_HTML_QUOTE_SINGLE )
	{
		string = string.replace( /'/g, '&#039;' );
	}


	if( !noquotes )
	{
		string = string.replace( /"/g, '&quot;' );
	}


	return string;

}



/**
 *
 * Abre o link em uma nova janela
 *
 * @param url: URL que será aberta
 * @param name: Nome da janela
 * @param properties: Propriedades da nova janela ( popup )
 * @return void
 *
 **/
function window_open( url, name, properties )
{

	/**
	 *
	 * Identifica se a URL informada já está com o "http"
	 *
	 **/
	var absolutePath = ( exists( 'base' ) ) ? $( 'base' ).attr( 'href' ) : '';
	var filter = /^(http)/;
	var url = ( filter.test( url ) ) ? url : absolutePath + url;



	/**
	 *
	 * Verifica se o name foi informado
	 *
	 **/
	if( typeof name === 'undefined' )
	{
		name = 'tfp';
	}



	/**
	 *
	 * Verifica se foram adicionadas propriedades
	 *
	 **/
	if( typeof properties === 'undefined' )
	{
		properties = '';
	}


	window_name = window.open( url, name, properties );

}



/**
 *
 * Evita que várias janelas com o mesmo nome sejam abertas
 *
 * @return void
 *
 **/
function prevent_duplicated_windows( )
{

	if( window.window_name && window.window_name.open && !window.window_name.closed )
	{
		window.window_name.opener = null;
	}

}
