//recalcula tamanho após redimensionamento
window.onresize = function()
{
	//executa
	mostraHTMLFull(url2,'recalcula',largura2,altura2,left2,top2,botoes2,pixels2,relativo2,alturaV32,larguraV32);
}

//declaração de variaveis para recalculamento de tamanho
var url2 = '';
var largura2 = '';
var altura2 = '';
var left2 = '';
var top2 = '';
var botoes2 = '';
var pixels2 = '';
var relativo2 = '';
var alturaV32 = '';
var larguraV32 = '';
var alturaFlashDiv = '';
var larguraFlashDiv = '';

function mostraHTMLFull(url,acao,largura,altura,left,top,botoes,pixels,relativo,alturaV3,larguraV3)
// url
// acao      - string            - [mostra|esconde|minimiza|maximiza|recalcula]
// largura   - inteiro ou string - porcentagem[0-100% **seguido do simbolo %**] ou pixel[>0]
// altura    - inteiro ou string - porcentagem[0-100% **seguido do simbolo %**] ou pixel[>0]
// top       - inteiro ou string - porcentagem[0-100% **seguido do simbolo %**] ou pixel[>0]
// left      - inteiro ou string - porcentagem[0-100% **seguido do simbolo %**] ou pixel[>0]
// botoes    - inteiro           - [0|1] ativa os botoes ** padrao 1
// pixels    - inteiro           - [0|1] decide se usa medidas em pixels ou porcentagem *** atualmente sem utilidade. Usar valor diferente de [0|1]****
// relativo  - inteiro           - [0|1] mantem caixa html com início relativo ao site v3
// alturaV3  - inteiro           - pixel[>0] *** obrigatorio quando usado posicionamento relativo a V3
// larguraV3 - inteiro           - pixel[>0] *** obrigatorio quando usado posicionamento relativo a V3

{
	var divA01 = document.getElementById('da01');
	var iframe = document.getElementById('fa01');
	var divA02 = document.getElementById('da02');
	var divBotoes = document.getElementById('botoes');
	var divV3 = document.getElementById('flashDiv');
	
	if(botoes==undefined) 
		var botoes=1;
		
	if(relativo==undefined) 
		var relativo=0;
	
	//habilita botoes
	if(botoes=='1')
		divBotoes.style.display = 'block';
	else
		divBotoes.style.display = 'none';
	
	if(acao=='mostra' || acao=='recalcula') // somente na hr de mostrar existe os cálculos
	{
		//cópia de parametros para recalculagem de tamanho
		url2 = url;		
		largura2 = largura;
		altura2 = altura;
		left2 = left;
		top2 = top;
		botoes2 = botoes;
		pixels2 = pixels;
		relativo2 = relativo;
		alturaV32 = alturaV3;
		larguraV32 = larguraV3;

		
		//calculo de margem relativa a V3
		var alturaRelativa = 0;
		var larguraRelativa = 0;
		
		if(relativo=='1')
		{
			alturaRelativa = divV3.offsetHeight-alturaV3;
			if(alturaRelativa<0)
				alturaRelativa = 0;
				
			//subtrai 3 para acertar uma pequena diferneça entre navegadores, evitando assim o scroll no firefox e IE
			alturaRelativa = Math.floor(parseFloat(alturaRelativa/2))-3; 
			
			larguraRelativa = divV3.offsetWidth-larguraV3;
			if(larguraRelativa<0)
				larguraRelativa = 0;
				
			//subtrai 3 para acertar uma pequena diferneça entre navegadores, evitando assim o scroll no firefox e IE
			larguraRelativa = Math.floor(parseFloat(larguraRelativa/2))-2			
		}
		
		
		//a comparação de pixels igual a 0 ou 1 mantem a compatibilidade
		if(pixels=='0')
		{
			var width = 100;
			var height = 100;
			
			//calcula margem relativa
			var porAltura = 0;
			var porLargura = 0;
			if(relativo=='1')
			{
				porAltura = parseInt((alturaRelativa*100)/divV3.offsetHeight);
				porLargura = parseInt((larguraRelativa*100)/divV3.offsetWidth);				
			}
			
			top = top+porAltura;
			left = left+porLargura;
			
			//aplica margem
			divA01.style.top = top+'%';
			divA01.style.left = left+'%';
			
			//calcula largura proporcional ao restante
			width = width-left;
			width = parseInt(parseInt(largura)*parseInt(width)/100);	
			
			//calcula altura proporcional ao restante
			height = height-top;	
			height = parseInt(parseInt(altura)*parseInt(height)/100);
			
			divA01.style.width = width+'%';
			divA01.style.height = height+'%';			
		}
		else if(pixels=='1')
		{
			var width = largura;
			var height = altura;
			
			divA01.style.width = width+'px';
			divA01.style.height = height+'px';
			
			//aplica margem relativa
			top = top+alturaRelativa;
			divA01.style.top = top+'px';
			
			left = left+larguraRelativa;
			divA01.style.left = left+'px';
		}
		else
		{		
			//expressão regular que verifica se é utilizado porcentagem ou pixels
			var exp = /%/;
			
			//margens top e left
			if(exp.exec(top) && exp.exec(left))
			{
				top = top.replace('%','');
				left = left.replace('%','');
				
				top = parseInt(top);
				left = parseInt(left);
				
				//calcula margem em % em caso de relativo a V3
				var porTop = 0;
				var porLeft = 0;
				if(relativo=='1')
				{
					porTop = Math.round((alturaRelativa*100)/divV3.offsetHeight);
					porLeft = Math.round((larguraRelativa*100)/divV3.offsetWidth);				
				}
				
				top = top+porTop;
				left = left+porLeft;
				
				//aplica margem
				divA01.style.top = top+'%';
				divA01.style.left = left+'%';
				
				//altura e largura
				if(exp.exec(largura) && exp.exec(altura))
				{
					var width = 100;
					var height = 100;
					
					largura = largura.replace('%','');
					altura = altura.replace('%','');
					
					largura = parseInt(largura);
					altura = parseInt(altura);
					
					//calcula largura proporcional ao restante
					width = width-left;
					width = Math.round(largura*width/100);	
					
					//calcula altura proporcional ao restante
					height = height-top;
					height = Math.round(altura*height/100);			
					
					//aplica largura e altura
					divA01.style.width = width+'%';
					divA01.style.height = height+'%';
				
				}
				else if((!exp.exec(largura)) && (!exp.exec(altura)))
				{				
					var width = largura;
					var height = altura;
					
					//aplica largura e altura
					divA01.style.width = width+'px';
					divA01.style.height = height+'px';
				}				
			}
			else if((!exp.exec(top)) && (!exp.exec(left)))
			{	
				//aplica margem relativa
				top = parseInt(top)+alturaRelativa;	
				divA01.style.top = top+'px';
				
				left = parseInt(left)+larguraRelativa;
				divA01.style.left = left+'px';
				
				//altura e largura
				if(exp.exec(largura) && exp.exec(altura))
				{
					var width = 100;
					var height = 100;
					
					largura.replace('%','');
					altura.replace('%','');
					
					//calcula largura proporcional ao restante
					width = width-Math.round(left*100/divV3.offsetWidth);
					width = Math.round(parseInt(largura)*width/100);	
					
					//calcula altura proporcional ao restante
					height = height-Math.round(top*100/divV3.offsetHeight);
					height = Math.round(parseInt(altura)*height/100);			
					
					//aplica largura e altura
					divA01.style.width = width+'%';
					divA01.style.height = height+'%';
				
				}
				else if((!exp.exec(largura)) && (!exp.exec(altura)))
				{				
					var width = largura;
					var height = altura;
					
					//aplica largura e altura
					divA01.style.width = width+'px';
					divA01.style.height = height+'px';
				}
			}		
		}

		if(acao=='mostra')
		{
			if(url.length >0)
				iframe.src = url;

			divA02.style.display = 'none';
			divA01.style.display = 'block';
		}		
	}
	else if(acao=='minimiza')
	{
		divA01.style.display = 'none';			
		divA02.style.display = 'block';		
	}
	else if(acao=='maximiza')
	{
		divA02.style.display = 'none';			
		divA01.style.display = 'block';			
	}
	else if(acao=='esconde')
	{
		divA01.style.display = 'none';
	}
}
