// ZOOMLAYER 1.0
// © 02/09/2006 L3A COMUNICAÇÃO - GUILHERME RANOYA
//
// ESTA FUNÇÃO ABRE E FECHA DIVS NO HTML COM EFEITO DE ZOOM
// O LAYER SE ADAPTA AUTOMATICAMENTE AO ESPAÇO DO NAVEGADOR
//
// 
// ATIVAÇÃO:
// javascript:openlayer("layer_ID", LayerWidth-x, LayerWidth-y, velocidade);
// javascript:closelayer();
//
// CONFIGURAÇÃO
// DEFINA AS PROPRIEDADES CSS DO LAYER ABERTO E DO LAYER EM TRANSIÇÃO
//
//
//						Sintaxe: elemento.style.[propriedadeCSSemJavaScript]=[valor];
//						referencia a Javascript-CSS: http://codepunk.hardwar.org.uk/css2js.htm
//
//                      LAYER ABERTO
						function cssOpenedLayer() {
						elemento.style.border="1px solid #663300";
						elemento.style.backgroundColor="#F9F9F9";
						elemento.style.position="absolute";
						elemento.style.zIndex="100";
						elemento.style.padding="10px 10px 10px 10px";
						}
//
//                      LAYER EM TRANSIÇÃO
						function cssTransitLayer() {
						elemento.style.border="2px solid #000000";
						elemento.style.backgroundColor="transparent";
						elemento.style.position="absolute";
						elemento.style.zIndex="100";
						elemento.style.overflow="hidden";
						}
//
// OBS:
// RECOMENDÁVEL O USO EM DIV COM O CSS: position:absolute
//
//

// Código

// função de captura do mouse

var IE = document.all?true:false

// Verifica se é netscape
if (!IE) document.captureEvents(Event.MOUSEMOVE)

// setup para usar função getMouseXY no evento onMouseMove
document.onmousemove = getMouseXY;

// variaveis temporarias para X e Y
var tempX = 0
var tempY = 0

// funcao principal para receber X e Y de mouse

function getMouseXY(e) {
  if (IE) { // pega dados do IE
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {  // pega dados do Netscape
    tempX = e.pageX
    tempY = e.pageY
  }  
  // verifica se os dados são positivos
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  
   
  return true
}


// função de zoom do layer (abre ou fecha)
// não usar esta função... usar openlayer(...) ou closelayer()

function zoomCore(dadorazao, dadolimite, dadopulo, opcao) {
	
	if (opcao == 'abre') {
		
		if (contador == 0) {
			
			razao = dadorazao;
			
			limitey = parseInt(limitex/razao);
			
			limitex = parseInt(dadolimite);
			
			pulo = parseInt(dadopulo);
					
			n = 0;


			// deixa apenas o número no FireFox (retira o "px" de "200px")
			

			if (!IE) {
	
				if (posicaoinitx.substring(0,posicaoinitx.indexOf("px")) > 0 ) {
					retiraPX = posicaoinitx.substring(0,posicaoinitx.indexOf("px"));
					posicaoinitx = parseInt(retiraPX);
				}
	
				if (posicaoinity.substring(0,posicaoinity.indexOf("px")) > 0 ) {
					retiraPX2 = posicaoinity.substring(0,posicaoinity.indexOf("px"));
					posicaoinity = parseInt(retiraPX2);	
				}

			}	
			
		}
	
	} 
	
	// aplica a CSS transitoria
	
	cssTransitLayer();

	// caso o link esteja próximo a borda em baixo

	if ( (posicaoinity + limitey) > document.body.clientHeight) {
	
		fatorvertical = -1 * limitey / 19;  
		
			// caso estoure a borda de cima
	
			if ( posicaoinity - n < 0) {
			
			n=limitey;
			contador = 0;
			cssOpenedLayer();
			clearInterval(thread1);
			
			}
		  
		} else {
	
	fatorvertical = 1;
	
	}
	
	if (opcao == 'abre') {
		
		n = n + pulo;
			
	} else {
	
		n = n - pulo;
		
	}

	// condição de termino da rotina (atingiu o tamanho)
	if ((n*razao)>(limitex)) {
		
		n=limitey;
		contador = 0;
		cssOpenedLayer();
		clearInterval(thread1);
		
		
		}
		
	if ( n < 0 ) {
		
		n = 0
		contador = 0;
		elemento.style.visibility="hidden";
		clearInterval(thread1);
		
		}
	
	if ((n*razao) < 0) {
	
		n = 1 / razao;
		contador = 0;
		elemento.style.visibility="hidden";
		clearInterval(thread1);
		
		}

		
	contador++;
	
// caso o link esteja proximo a borda esquerda
if (posicaoinitx < (limitex/2)) {

	// cresce o div
	posicaox = posicaoinitx + n/10;
	posicaoy = posicaoinity - 5 + (20 * n * razao / limitex * fatorvertical);
	
	} else {
	
	//caso o link esteja próximo da borda direita
	if ((posicaoinitx + limitex/2) > (document.body.clientWidth - 40) ) {
		deslocamentonegativo = 0.93;
		} else {
		deslocamentonegativo = 2;
	} 
	
	// cresce o div
	posicaox = posicaoinitx + 20 - (n*razao/deslocamentonegativo);
	posicaoy = posicaoinity - 5 + (20 * n * razao / limitex * fatorvertical) ;
	}

// aplica dados

if (IE) {
elemento.style.width=(n*razao);
elemento.style.height=n;
elemento.style.marginLeft=posicaox;
elemento.style.marginTop=posicaoy;
} else {
elemento.style.width=(n*razao) + "px";
elemento.style.height=n + "px";
elemento.style.marginLeft= posicaox + "px";
elemento.style.marginTop=posicaoy + "px";
}

	
}

// função de abertura do layer
// openlayer( "qual layer" , tamanho do layer em X , tamanho do layer em Y , velocidade );

function openlayer(onde, sizex, sizey, step) {

	elemento=document.getElementById(onde);
	elemento.style.visibility="visible";
		
	if (IE) {
	elemento.style.marginLeft=tempX;
	posicaoinitx = (tempX-20);
	elemento.style.marginTop=tempY;
	elemento.style.top=0;
	elemento.style.left=0;
	posicaoinity = tempY;
	elemento.style.width=1;
	elemento.style.height=1;

	} else {
	elemento.style.marginLeft=tempX + "px";
	posicaoinitx = (tempX-20) + "px";
	elemento.style.marginTop=tempY + "px";
	elemento.style.top=0 + "px";
	elemento.style.left=0 + "px";
	posicaoinity = tempY + "px";
	elemento.style.width=1 + "px";
	elemento.style.height=1 + "px";

	}

	contador = 0;
	proporcao=sizex/sizey;
	limitex=sizex;
	pulo=step;

	// ativa thread
	
	thread1 = setInterval("zoomCore(proporcao, limitex, pulo, 'abre')", 1);

}

// função de fechamento do layer aberto

function closelayer() {

	contador = 0;

	// ativa thread
	
	thread1 = setInterval("zoomCore('0', '0', '0', 'fecha')", 1);

}

function abrelogin() {
	
	openlayer('login', 400,320,40);
	
}

function abrelogin2() {
	
	openlayer('loginb', 300,200,40);
	
}
