/*

Funções de navegação de imagem folha
Autor: João Marcos Menezes
Data: 14/07/2003
Ultima atualização em: 04/11/2003

Precisa da variavel imgName que contem o nome da imagem
Esta deve ser declarada na pagina html antes do include do js
Precisa de variavel mapa true/false, para detalhes

*/

// Dimensoes do quadrado
var tamWid = 62.5;
var tamHei = 50;
var topIni = 208;
var lefIni = 38;
var inix = 0;
var iniy = 0;
var maxx = 0;
var maxy = 0;
var maxxtela = 0;
var maxytela = 0;
var maxxsz = 0;
var maxysz = 0;
var tamZoom = 2;
var tamBloco = 100;
var topPaginas = 650;
var movendo = false;

// Scroll
var clipTop = 0;
var clipWidth = 630;
var clipWidthOri = 630;
var clipBottom = 154;
var clipLeft = 0;
var clipRoda = 0;
var lefter = 70;

// Objeto do layer
var obj = null;

// Inis da tela
var inixtela = 0;
var iniytela = 0;
var sizeAnt = 0;

var tabLayer = '<table id="tabCrop" ';
var fimTabLayer = ' border="1" cellpadding="0" cellspacing="0" bordercolor="#000000"><tr><td><img src="../../images/spacer.gif"></td></tr></table>';

// Para recalcular maxxtela e maxytela
function recalculaMaxTela() {

   // Primeiro deve achar numero inteiro de blocos
   maxxtela = parseInt(maxxsz * 16);
   while ((maxxtela % (tamBloco * tamZoom)) != 0) {
      maxxtela += 1;
   }
   maxytela = parseInt(maxysz * 16);
   while ((maxytela % (tamBloco * tamZoom)) != 0) {
      maxytela += 1;
   }
      
   maxxtela -= (5 * (tamZoom * tamBloco));
   maxytela -= (4 * (tamZoom * tamBloco));

   maxx = maxxtela / 16;
   maxy = maxytela / 16;

   return;   
}

// Para verificar x e y
function verificaXyTela() {

   if (inix > maxx) {
      inix = maxx;
   }
   
   if (iniy > maxy) {
      iniy = maxy;
   }
   
   if (inix < 0) {
      inix = 0;
   }
   
   if (iniy < 0) {
      iniy = 0;
   }
   
   if (inixtela > maxxtela) {
      inixtela = maxxtela;
   }
   
   if (iniytela > maxytela) {
      iniytela = maxytela;  
   }
   
   if (inixtela < 0) {
      inixtela = 0;
   }
   
   if (iniytela < 0) {
      iniytela = 0;
   }

   return;
}   

// Monta quadro DHTML
function montaQuadro(inicial) {

   // Para x e y inicias
   var lnkLoc = location.href;
   var xParam = 0;
   var yParam = 0;
   var xImg = '';
   
   // Ajusta a tela
   var cltWid = 0;   
   if (bw.ns4) {
      cltWid = window.innerWidth;
   } else {
      cltWid = document.body.clientWidth;      
   }
   var smDiv = (cltWid - 800)/2;
   
   // Obtem parametros
   // alert(lnkLoc);
   if ((lnkLoc.indexOf("?px=") > -1) 
         && (lnkLoc.indexOf("py=") > -1)) {
      
      xParam = parseInt(lnkLoc.substring(lnkLoc.indexOf("?px=") + 4, lnkLoc.indexOf("py")));
      if (lnkLoc.indexOf("img=") > -1) {
        
            yParam = parseInt(lnkLoc.substring(lnkLoc.indexOf("py=") + 3, lnkLoc.indexOf("img=")));
        
      } else {
            
            yParam = parseInt(lnkLoc.substring(lnkLoc.indexOf("py=") + 3));
            
      }
      
   }
   
   // Verifica se foi passado determinada imagem como parametro
   if (inicial) {
       if (lnkLoc.indexOf("img=") > -1) {
            
            xImg = lnkLoc.substring(lnkLoc.indexOf("img=") + 4);
            if (xImg != '') {
                imgName = xImg + "/" + xImg;
            }
        
       }
   }
        
   // Para debug
   // alert("Xparam: " + xParam + " - Yparam: " + yParam + " - Img: " + xImg);

   // Tamanhos da imagem grande
   if (mapa) {
        maxxsz = 221; //imgFull.width;
        maxysz = 203; //imgFull.height;
        tamWid = 31.25;
        tamHei = 25;
        tamBloco = 50;
        topIni = 226;
        lefIni = 18;
   } else {
        maxxsz = 198; //imgFull.width;
        maxysz = 279; //imgFull.height;
   }

   // Carrega thumbnail   
   if (bw.ns4) {
      document.layers["divFull"].document.images[0].src = imgName + "_m.jpg";
   } else {
      document.images['imgFull'].src = imgName + "_m.jpg";
   }

   // Inicializar layer de corte
   if (bw.ns4) {      
      document.layers["cropDiv"].top = topIni;
      if (cltWid <= 800) {
         document.layers["cropDiv"].left = lefIni;   
      } else {
         document.layers["cropDiv"].left = lefIni + smDiv;
      }
   } else if (bw.ns6) {
      document.getElementById("cropDiv").style.top = topIni;
      if (cltWid <= 800) {
         document.getElementById("cropDiv").style.left = lefIni;
      } else {
         document.getElementById("cropDiv").style.left = lefIni + smDiv;
      }
         
   } else {
      cropDiv.style.top = topIni;
      if (cltWid <= 800) {
         cropDiv.style.left = lefIni;
      } else {
         cropDiv.style.left = lefIni + smDiv;
      }
   }
   
   // Recalcular tela
   recalculaMaxTela();
     
   // Inicializa objetos dinamicos de layer
   if (inicial) {

      // Drag and drop   
      obj = new lib_obj('cropDiv');
      obj.dragdrop();
      
      // Scroll de imagens
      if (!mapa) {
        preparaScroll();
      }

      // Clica nos iniciais
      if (xParam != 0 && yParam != 0) {
         if (xParam > 36 && yParam > 114) {

            // Move dhtml            
            tempX = xParam;
            tempY = yParam;
            imgClick(0, 0);
            
         } else {

            // Monta tela inicial
            mover('J');
            
         }

      } else {

         // Monta tela inicial
         mover('J');
         
      }
      
   } else {

      // Monta tela inicial
      mover('J');
   
   }
   
   return;
}

// Para zoom
function zoom(tipo) {
   
   var aum = false;
   if (tipo == 'M') {
      
      if (tamZoom < 3) {
         aum = true;
         tamZoom++;
      } else {
         return;
      }
      
   } else {
      
      if (tamZoom > 1) {
         aum = false;
         tamZoom--;
      } else {
         return;
      }
   }
   
   if (tamZoom == 1) {
      if (mapa) {
         tamWid = 18.75;
         tamHei = 12.5;        
      } else {
         tamWid = 37.5;
         tamHei = 25;
      }
   } else if (tamZoom == 2) {
      if (mapa) {
         tamWid = 31.25;
         tamHei = 25;
      } else {
         tamWid = 62.5;
         tamHei = 50;
      }        
   } else if (tamZoom == 3) {
      if (mapa) {
         tamWid = 43.75;
         tamHei = 37.5;
      } else {
         tamWid = 87.5;
         tamHei = 75;
      }
   }
   
   // Tem que ajustar as coordenadas baseando-se nos inis da tela
   if (inixtela != 0) {
      if (inixtela > (tamBloco * tamZoom)) {
         while (inixtela % (tamBloco * tamZoom) != 0) {
            inixtela -= 1;            
         }

      } else {
         inixtela = 0;
      }
      
   }

   if (iniytela != 0) {
      if (iniytela > (tamBloco * tamZoom)) {
         while (iniytela % (tamBloco * tamZoom) != 0) {
            iniytela -= 1;
         }

      } else {
         iniytela = 0;
      }
      
   }

   // Proporcao do zoom (centro)
   if (aum) {
      inixtela = inixtela - (1*tamZoom*tamBloco);
      iniytela = iniytela - (1*tamZoom*tamBloco);
   } else {
      inixtela = inixtela + (2*tamZoom*tamBloco);
      iniytela = iniytela + (2*tamZoom*tamBloco);
   }
      
   if (inixtela < 0) {
      inixtela = 0;
   }
   if (iniytela < 0) {
      iniytela = 0;
   }

   // Calcula inix e iniy
   inix = inixtela / 16;
   iniy = iniytela / 16;
   
   // Recalcula maxtela
   recalculaMaxTela();
   
   // Move quadrados   
   mover('J');
   return;
   
}

// Para mover quadrado dhtml
function mover(direcao) {

   // Ajusta a tela
   var cltWid = 0;
   
   if (bw.ns4) {
      cltWid = window.innerWidth;
   } else {
      cltWid = document.body.clientWidth;      
   }
   var smDiv = (cltWid - 800)/2;   

   if (bw.ns4) {
      
      if (cltWid > 790) {
         // Desabilita scroll Hor
         document.width = window.innerWidth;
      } else {
         document.width = 1000;
      }

   } else if (bw.ns6) {

      // Não possivel

   } else {

      if (cltWid > 758) {
         // Desabilita scroll Hor
         document.body.style.overflowX = 'hidden';
      } else {
         document.body.style.overflowX = 'scroll';
      }
      
   }

   // Verifica click de direcao
   if (direcao == 'C') {
      iniy -= ((tamBloco*tamZoom)/16) * 1;
      iniytela -= ((tamBloco*tamZoom) * 1);
   } else if (direcao == 'B') {
      iniy += ((tamBloco*tamZoom)/16) * 1;
      iniytela += ((tamBloco*tamZoom) * 1);
   } else if (direcao == 'E') {
      inix -= ((tamBloco*tamZoom)/16) * 1;
      inixtela -= ((tamBloco*tamZoom) * 1);
   } else if (direcao == 'D') {
      inix += ((tamBloco*tamZoom)/16) * 1;
      inixtela += ((tamBloco*tamZoom) * 1);
   }
  
   // Verifica x e y da tela
   verificaXyTela();
   
   // Muda posicoes
   nx = inix + lefIni;;
   ny = iniy + topIni;   
   dd_obj.clX = nx;
   dd_obj.clY = ny;
   this.x = nx;
   this.y = ny;
   dd_obj.x = nx;
   dd_obj.y = ny;
   obj.css.left=x;
   obj.css.top=y;

   // Atualiza layer
   if (bw.ns4) {
      document.layers["cropDiv"].top = topIni + iniy;      
      if (cltWid <= 800) {
         document.layers["cropDiv"].left = lefIni + inix;     
      } else {
         document.layers["cropDiv"].left = lefIni + inix + smDiv;
      }
       
   } else if (bw.ns6) {
      document.getElementById("cropDiv").style.top = topIni + iniy;
      if (cltWid <= 800) {
         document.getElementById("cropDiv").style.left = lefIni + inix;
      } else {
         document.getElementById("cropDiv").style.left = lefIni + inix + smDiv;
      }
      
   } else {      
      cropDiv.style.top = topIni + iniy;
      if (cltWid <= 800) {
         cropDiv.style.left = lefIni + inix;     
      } else {
         cropDiv.style.left = lefIni + inix + smDiv;
      }
   }
   
   // Verifica tamanho do layer
   if ((inix + tamWid) > maxxsz) {      
      layerw = maxxsz - inix;
   } else {
      layerw = tamWid;
   }
   if ((iniy + tamHei) > maxysz) {      
      layerh = maxysz - iniy;
   } else {
      layerh = tamHei;
   }
  
   // Monta layer
   if (bw.ns6) {

      document.getElementById("cropDiv").style.width = layerw;
      document.getElementById("cropDiv").style.height = layerh;
      document.getElementById("tabCrop").style.height = layerh;

   } else if (bw.ns4) {
      
      // Fim de codigo
      // Devido ao document.write que deve ser usado
         
   } else {   
      cropDiv.style.width = layerw;
      cropDiv.style.height = layerh;
      tabCrop.height = layerh;
   }

   // Calcula as 20 imagens da tela   
   var blocoanda = tamBloco * tamZoom;
   
   if (mapa) {
      blocoanda = (tamBloco*2) * tamZoom;
   }
   
   var blocoy = iniytela;
   
   if (mapa) {
      blocoy = iniytela * 2;
   }
   
   var imagem = new Array(21);
   var cntImg = 1;
   for (j=1; j<5; j++) {
      for (z=1; z<6; z++) {
         var blocox = inixtela + ((z-1) * blocoanda);
         if (mapa) {
            blocox = (inixtela*2) + ((z-1) * blocoanda);
         }
         imagem[cntImg] = imgName + "-" + tamZoom + "-" + blocox + "-" + blocoy + ".jpg";
         cntImg++;
      }
      blocoy += blocoanda;      
   }
   
   // Seleciona objetos de acordo com o browser
   if (bw.ns4) {
      dAmp = document.layers["divAmp"];
         
   } else if (bw.ns6) {
      dAmp = document.getElementById("divAmp").style;
      
   } else {
      dAmp = divAmp.style;

   }

   // Carrega array de imagens na tela
   if (bw.ns4) {
      for (j=1; j<21; j++) {
         dAmp.document.images[j-1].src = "../../images/spacer.gif";
      }
      for (j=1; j<21; j++) {
         dAmp.document.images[j-1].src = imagem[j];
      }
   } else {
      for (j=1; j<21; j++) {
         document.images[j-1].src = "../../images/spacer.gif";
      }      
      for (j=1; j<21; j++) {
         document.images[j-1].src = imagem[j];
      }
   }

   if (bw.ns4) {
   
      // Layer para NS4
      document.layers["cropDiv"].width = layerw;
      document.layers["cropDiv"].height = layerh;
      document.layers["cropDiv"].document.clear();
      document.layers["cropDiv"].document.write(tabLayer);      
      document.layers["cropDiv"].document.write('width="' + layerw + '" height="' + layerh + '"');      
      document.layers["cropDiv"].document.write(fimTabLayer);
   }      
   
   return;

}

// Funcao de browser check
function lib_bwcheck(){
  this.ver=navigator.appVersion
  this.agent=navigator.userAgent
  this.dom=document.getElementById?1:0
  this.opera5=this.agent.indexOf("Opera 5")>-1
  this.ie5=(this.ver.indexOf("MSIE 5")>-1 && this.dom && !this.opera5)?1:0;
  this.ie6=(this.ver.indexOf("MSIE 6")>-1 && this.dom && !this.opera5)?1:0;
  this.ie7=(this.ver.indexOf("MSIE 7")>-1 && this.dom && !this.opera5)?1:0;
  this.ie4=(document.all && !this.dom && !this.opera5)?1:0;
  this.ie=this.ie4||this.ie5||this.ie6
  this.mac=this.agent.indexOf("Mac")>-1
  this.ns6=(this.dom && parseInt(this.ver) >= 5) ?1:0;
  this.ns4=(document.layers && !this.dom)?1:0;
  this.bw=(this.ie7||this.ie6||this.ie5||this.ie4||this.ns4||this.ns6||this.opera5)
  return this
}

// Checagem de browser (para movimentacao de mouse)
bw=new lib_bwcheck()
var IE = document.all?true:false;
if (!IE) document.captureEvents(Event.MOUSEMOVE|Event.MOUSEDOWN|Event.MOUSEUP)

// Para movimentar o mouse, deve detectar X e Y ou simplesmente movimentar layer (Drag and drop)
document.onmousemove=lib_dd_move;

// Para resize de tela
function lib_resize() {

   var cltWid = 0;
   
   if (bw.ns4) {
      cltWid = window.innerWidth;      
   } else {
      cltWid = document.body.clientWidth;      
   } 
   
   if (cltWid != sizeAnt) {
   
      if (bw.ns4) {
         dAmp = document.layers["divAmp"];
         dPrincipal = document.layers["divPrincipal"];
         dInstrucoes = document.layers["divInstrucoes"];
         dFinal = document.layers["divFinal"];
         dBotoes = document.layers["divBotoes"];
         dFull = document.layers["divFull"];
         if (!mapa) {
            dTabela = document.layers["divTabela"];
         }
         dCrop = document.layers["cropDiv"];
         
         if (mapa) {
            dSupEsq = document.layers["divSupEsq"];
            dSupDir = document.layers["divSupDir"];
            dSupCima = document.layers["divSupCima"];
            dSupBaixo = document.layers["divSupBaixo"];
            dTextoMp = document.layers["divTextoMp"];
            dReport = document.layers["divReport"];
         }
            
      } else if (bw.ns6) {
         dAmp = document.getElementById("divAmp").style;
         dPrincipal = document.getElementById("divPrincipal").style;
         dInstrucoes = document.getElementById("divInstrucoes").style;
         dFinal = document.getElementById("divFinal").style;
         dBotoes = document.getElementById("divBotoes").style;
         dFull = document.getElementById("divFull").style;
         if (!mapa) {
            dTabela = document.getElementById("divTabela").style;
         }
         dCrop = document.getElementById("cropDiv").style;

         if (mapa) {
            dSupEsq = document.getElementById("divSupEsq").style;
            dSupDir = document.getElementById("divSupDir").style;
            dSupCima = document.getElementById("divSupCima").style;
            dSupBaixo = document.getElementById("divSupBaixo").style;
            dTextoMp = document.getElementById("divTextoMp").style;
            dReport = document.getElementById("divReport").style;
         }
         
      } else {
         dAmp = divAmp.style;
         dPrincipal = divPrincipal.style;
         dInstrucoes = divInstrucoes.style;
         dFinal = divFinal.style;
         dBotoes = divBotoes.style;
         dFull = divFull.style;
         if (!mapa) {
            dTabela = divTabela.style;
         }
         dCrop = cropDiv.style;
         if (mapa) {         
            dSupEsq = divSupEsq.style;
            dSupDir = divSupDir.style;
            dSupCima = divSupCima.style;
            dSupBaixo = divSupBaixo.style;
            dTextoMp = divTextoMp.style;
            dReport = divReport.style;
         }
   
      }
      
      // Resize do objeto divAmp
      var smDiv = (cltWid - 800)/2;
      if (cltWid <= 800) {
         dPrincipal.left = 10;   
         dInstrucoes.left = 440;
         dFinal.left = 10;
         dBotoes.left = 36;
         if (mapa) {
            dInstrucoes.left = 280;
            dAmp.left = 265;
            dFull.left = 16;
         } else {
            dInstrucoes.left = 440;
            dAmp.left = 255;
            dFull.left = 36;
         }
         if (!mapa) {
            dTabela.left = 16;
         }
         dCrop.left =  lefIni + inix;
         if (mapa) {
            dReport.left = 60;
            dSupEsq.left = 4;
            dSupDir.left = 241;
            dSupCima.left = 4;
            dSupBaixo.left = 4;
            dTextoMp.left = 16;
         }
         
      } else {
         dPrincipal.left = 10 + smDiv;
         dFinal.left = 10 + smDiv;
         dBotoes.left = 36 + smDiv;
         if (mapa) {            
            dInstrucoes.left = 280 + smDiv;
            dAmp.left = 265 + smDiv;
            dFull.left = 16 + smDiv;
         } else {
            dInstrucoes.left = 440 + smDiv;
            dAmp.left = 255 + smDiv;
            dFull.left = 36 + smDiv;
         }
         if (!mapa) {
            dTabela.left = 16 + smDiv;
         }
         dCrop.left =  lefIni + inix + smDiv;
         if (mapa) {
            dReport.left = 60 + smDiv;
            dSupEsq.left = 4 + smDiv;
            dSupDir.left = 241 + smDiv;
            dSupCima.left = 4 + smDiv;
            dSupBaixo.left = 4 + smDiv;
            dTextoMp.left = 16 + smDiv;
         }
      }
      
      if (!mapa) {
          var x = new getObj('divPaginas');
       	  if (document.layers) {
             if (cltWid <= 800) {
                x.style.clip.left = clipLeft;
                x.style.left = lefter;
             } else {
                totLefter = lefter + smDiv;
                x.style.clip.left = clipLeft;
                x.style.left = totLefter;
             }	    
             x.style.top = topPaginas;
       		x.style.clip.top = clipTop;
       		
       		x.style.clip.right = clipWidth;
       		x.style.clip.bottom = clipBottom;
       		
          } else if (document.getElementById || document.all) {
       		//lyrheight = x.obj.offsetHeight;
       		if (cltWid <= 800) {
       		   x.style.clip = 'rect('+clipTop+' '+clipWidth+' '+clipBottom+' ' +clipLeft+')'
       		   x.style.left = lefter;
       		} else {
       		   totLefter = lefter + smDiv;
       		   x.style.clip = 'rect('+clipTop+' '+clipWidth+' '+clipBottom+' ' +clipLeft+')'
       		   x.style.left = totLefter;
       		}
          }
      }
      
   }
   
   // Widt anterior
   sizeAnt = cltWid;

   // window.status = "Resize: " + cltWid + " - lefter: " + lefter;  
   
   return;
}

// Variaveis para X e Y da tela do browser
var tempX = 0;
var tempY = 0;
var tempScrollx = 0;
var tempScrolly = 0;

// Quando for clicado na imagem passa x e y e posiciona layer
function imgClick(x, y) {
	
	// Detecta x (left) e y (top)
	if (x == 0 || y == 0) {
	   x = tempX;
	   y = tempY;
	}	

   var cltWid = 0;
   
   if (bw.ns4) {
      cltWid = window.innerWidth;      
   } else {
      cltWid = document.body.clientWidth;      
   }   

   var smDiv = (cltWid - 800)/2;	
   
   if (cltWid > 800) {
   
      x = x - smDiv;   
      
   }

	// Mapping de click
	// window.status = "X: " + x + " - Y: " + y;

   if (tamZoom == 1) {
      if (mapa) {
         tamWid = 18.75;
         tamHei = 12.5;        
      } else {
         tamWid = 37.5;
         tamHei = 25;
      }
   } else if (tamZoom == 2) {
      if (mapa) {
         tamWid = 31.25;
         tamHei = 25;
      } else {
         tamWid = 62.5;
         tamHei = 50;
      }        
   } else if (tamZoom == 3) {
      if (mapa) {
         tamWid = 43.75;
         tamHei = 37.5;
      } else {
         tamWid = 87.5;
         tamHei = 75;
      }
   }

   // Tem que ajustar as coordenadas baseando-se nos inis da tela
   inix = x - lefIni;
	iniy = y - topIni;   
   inixtela = parseInt(inix * 16);
   iniytela = parseInt(iniy * 16);

   if (inixtela != 0) {
      if (inixtela > (tamBloco * tamZoom)) {
         while (inixtela % (tamBloco * tamZoom) != 0) {
            inixtela -= 1;            
         }

      } else {
         inixtela = 0;
      }
      
   }

   if (iniytela != 0) {
      if (iniytela > (tamBloco * tamZoom)) {
         while (iniytela % (tamBloco * tamZoom) != 0) {
            iniytela -= 1;
         }

      } else {
         iniytela = 0;
      }
      
   }

   // Avança 2 quadros
   if (!movendo) {
      inixtela -= (tamBloco * tamZoom) * 2;
      iniytela -= (tamBloco * tamZoom) * 2;
   }

   // Calcula inix e iniy
   inix = inixtela / 16;
   iniy = iniytela / 16;

   // Recalcula maxtela
   recalculaMaxTela();

   // Move quadrados   
   mover('J');

	return;
}

// Função para mover objetos dhtml na tela
lib_obj.prototype.moveIt = function(x,y) {

   // Recalcula maxx e maxy
   recalculaMaxTela();
   
   x = tempX;
   y = tempY;

   var cltWid = 0;
   
   if (bw.ns4) {
      cltWid = window.innerWidth;      
   } else {
      cltWid = document.body.clientWidth;      
   }   

   var smDiv = (cltWid - 800)/2;	
   
   //window.status = "LSL -> X: " + tempX + " x: " + x + " - Y: " + tempY + " y: " + y + " - Nx: " + nx + "Ny: " + ny;
   
   // Vars de comparacao
   var cmpX = x;
   var cmpY = y;      
   var cmpMaxX = maxx + lefIni;
   var cmpMaxY = maxy + topIni;
   var cmpLefIni = lefIni;
   
   if (cltWid > 800) {
      cmpMaxX = maxx + lefIni + smDiv;
      cmpLefIni = lefIni + smDiv;
   }

   // Se estiver dentro da area do objeto
   if (cmpX <= cmpMaxX && cmpX > cmpLefIni) {
      this.x=x;
      this.css.left=x;
   }
   if (cmpY <= cmpMaxY && cmpY > topIni) {
      this.y=y; 
      this.css.top=y
   }
}

// Funcoes para Drag em Drop de objeto DHTML (layer)

// Para Debug, manda mensagem
function lib_message(txt) { 
   alert(txt); 
   return false;
}

// Para criar a lib do objeto DHTML que vai se movimentar pela tela
function lib_obj(obj,nest){
  
  if(!bw.bw) return lib_message('Drag and drop não suportado pelo browser')
  nest=(!nest) ? "":'document.'+nest+'.'
  this.evnt=bw.dom? document.getElementById(obj):
    bw.ie4?document.all[obj]:bw.ns4?eval(nest+"document.layers." +obj):0;
  if(!this.evnt) return lib_message('Objeto de movimentação não encontrado ('+obj+')'
    +'- \nSe usar Netscape use versão 4.7 ou superior!')
  this.css=bw.dom||bw.ie4?this.evnt.style:this.evnt;
  this.ref=bw.dom||bw.ie4?document:this.css.document;
  this.x=parseInt(this.css.left)||this.css.pixelLeft||this.evnt.offsetLeft||0;
  this.y=parseInt(this.css.top)||this.css.pixelTop||this.evnt.offsetTop||0
  this.w=this.evnt.offsetWidth||this.css.clip.width||
    this.ref.width||this.css.pixelWidth||0;
  this.h=this.evnt.offsetHeight||this.css.clip.height||
    this.ref.height||this.css.pixelHeight||0
  this.c=0 //Clip values
  if((bw.dom || bw.ie4) && this.css.clip) {
  this.c=this.css.clip; this.c=this.c.slice(5,this.c.length-1);
  this.c=this.c.split(' ');
  for(var i=0;i<4;i++){this.c[i]=parseInt(this.c[i])}
  }
  this.ct=this.css.clip.top||this.c[0]||0;
  this.cr=this.css.clip.right||this.c[1]||this.w||0
  this.cb=this.css.clip.bottom||this.c[2]||this.h||0;
  this.cl=this.css.clip.left||this.c[3]||0
  this.obj = obj + "Object"; eval(this.obj + "=this")
  return this
}

dd_is_active=0; 
dd_obj=0; 
dd_mobj=0

// Eventos de drag em drop do mouse
function lib_dd(){
  dd_is_active=1
  document.onmousedown=lib_dd_down
  document.onmouseup=lib_dd_up
}

// Para inicializar drag and drop
lib_obj.prototype.dragdrop = function(obj){
  if(!dd_is_active) lib_dd()
  this.evnt.onmouseover=new Function("lib_dd_over("+this.obj+")")
  this.evnt.onmouseout=new Function("dd_mobj=0")
  if(obj) this.ddobj=obj
}

// Fecha drag and drop
lib_obj.prototype.nodragdrop = function(){
  this.evnt.onmouseover=""; this.evnt.onmouseout=""
  dd_obj=0; dd_mobj=0
}

// Funções para gerenciar eventos do drag em drop
function lib_dd_over(obj) {
   dd_mobj=obj;
}

// Quando o mouse é solto
function lib_dd_up(e){
   
   // Se estiver movendo layer de drag and drop
   if (movendo) {
      dd_obj=0;
      imgClick(tempX, tempY);
      movendo = false;
      //window.status = "UP -> X: " + tempX + " - Y: " + tempY + " - Nx: " + nx + "Ny: " + ny;
   }
}

function lib_dd_down(e){ //Mousedown
  if(dd_mobj){
    x=(bw.ns4 || bw.ns6)?e.pageX:event.x||event.clientX
    y=(bw.ns4 || bw.ns6)?e.pageY:event.y||event.clientY
    dd_obj=dd_mobj
    dd_obj.clX=x-dd_obj.x;
    dd_obj.clY=y-dd_obj.y
    movendo = true;
  }
  //window.status = "DOWN -> X: " + tempX + " - Y: " + tempY + " - Nx: " + nx + "Ny: " + ny;
}

// Mousemove
function lib_dd_move(e,y,rresize){
   
   // Define scroll de acordo com o browser
   // Scroll server para calcular os layer quando tiver mudanca de page na tela
   if (bw.ns4) {      
      // Nao necessario
      //tempScrolly = window.pageYOffset;
      //tempScrollx = window.pageXOffset;
   } else if (bw.ns6) {
      // Nao necessario
   } else {
      tempScrollx = document.body.scrollLeft;
      tempScrolly = document.body.scrollTop;
   }

   x=(bw.ns4 || bw.ns6)?e.pageX:event.x||event.clientX
   y=(bw.ns4 || bw.ns6)?e.pageY:event.y||event.clientY
   
   x = x + tempScrollx;
   y = y + tempScrolly;

   if (dd_obj && movendo) {
      nx=x-dd_obj.clX; ny=y-dd_obj.clY
      if(dd_obj.ddobj) dd_obj.ddobj.moveIt(nx,ny)
      else dd_obj.moveIt(nx,ny)
   }
      
   tempX = x;
   tempY = y;

   if (tempX < 0){tempX = 0;}
   if (tempY < 0){tempY = 0;}
   
   /*if (dd_obj) {
      //window.status = "Move -> X: " + tempX + " - Y: " + tempY + " - Nx: " + nx + "Ny: " + ny;
   } else {
      //window.status = "Mouse -> X: " + tempX + " - Y: " + tempY;
   }*/
   // Para debug do temp Scroll X e Y
   // window.status = "Mouse -> X: " + tempX + " - Y: " + tempY + " - Scroll X: " + tempScrollx + " - " + " Scroll Y: " + tempScrolly;
   
   lib_resize();
   
   if(!bw.ns4) return false

}

// Fim das funcoes de drag and drop

// Rotina de teclas
function rotinaTeclas() {

   if (document.all) {
      
      // Para zoom
      if (event.keyCode==43) {
         zoom('N');   
      } else if (event.keyCode==45) {
         zoom('M');
      }
   
      // Para setas
      if (event.keyCode==49) {
         mover('B');
         mover('E');         
      } else if (event.keyCode==50) {
         mover('B');
      } else if (event.keyCode==51) {
         mover('B');
         mover('D');
      } else if (event.keyCode==52) {
         mover('E');
      } else if (event.keyCode==54) {
         mover('D');
      } else if (event.keyCode==55) {
         mover('C');
         mover('E');
      } else if (event.keyCode==56) {
         mover('C');
      } else if (event.keyCode==57) {
         mover('C');
         mover('D');
      }
   }
   
   return;

}
   
// Key press do browser
document.onkeypress = rotinaTeclas;

// Scroll
var qtdPx = 0;
var time,theTime,DHTML;

function getObj(name) {
  
   if (document.getElementById) {
      this.obj = document.getElementById(name);
	   this.style = document.getElementById(name).style;
   } else if (document.all) {
	   this.obj = document.all[name];
	   this.style = document.all[name].style;
   } else if (document.layers) {
	   this.obj = getObjNN4(document,name);
	   this.style = this.obj;
   }
}

function getObjNN4(obj,name) {
	
   var x = obj.layers;
   var foundLayer;
	for (var i=0;i<x.length;i++) {
	   if (x[i].id == name)
		   foundLayer = x[i];
		else if (x[i].layers.length)
			var tmp = getObjNN4(x[i],name);
		if (tmp) foundLayer = tmp;
	}
	return foundLayer;
}

function preparaScroll() {
	
	DHTML = (document.getElementById || document.all || document.layers)
	if (!DHTML) return;
	
	var x = new getObj('divPaginas');

   var cltWid = 0;
   
   if (bw.ns4) {
      cltWid = window.innerWidth;      
   } else {
      cltWid = document.body.clientWidth;      
   }   

   var smDiv = (cltWid - 800)/2;	
	if (document.layers) {
      x.style.clip.left = clipLeft;   
      x.style.top = topPaginas;
		x.style.clip.top = clipTop;
		
		x.style.clip.right = clipWidth;
		x.style.clip.bottom = clipBottom;
		
	} else if (document.getElementById || document.all) {
		//lyrheight = x.obj.offsetHeight;
	   x.style.clip = 'rect('+clipTop+' '+clipWidth+' '+clipBottom+' ' +clipLeft+')'
	}
	
}

function moverLayer(layername, qtd, tempo) {

   // Verifica se DHTML
   if (!DHTML) return;
   
   // Obtem o layer
   thelayer = new getObj(layername);
   if (!thelayer) return;
   
   // Obtem dados para scroll
   qtdPx = qtd;
   theTime = tempo;
   
   // Faz scroll
   fazerScroll();
}

function fazerScroll() {
	
	if (!DHTML) return;
	
   var cltWid = 0;
   
   if (bw.ns4) {
      cltWid = window.innerWidth;      
   } else {
      cltWid = document.body.clientWidth;      
   }   

   var smDiv = (cltWid - 800)/2;	
	
	clipLeft += qtdPx;
	clipWidth += qtdPx;
	lefter -= qtdPx;
	clipRoda += qtdPx;
	
	if (clipLeft < 0 || clipRoda > lyrWidth) {
      clipLeft -= qtdPx;
      clipWidth -= qtdPx;
      lefter += qtdPx;
      clipRoda -= qtdPx;
      return;
	}

	if (document.getElementById || document.all) {
      if (cltWid <= 800) {
         clipstring = 'rect('+clipTop+' '+clipWidth+' '+clipBottom+' ' + clipLeft + ')'            
         thelayer.style.left = lefter;
      } else {
         totLefter = lefter + smDiv;
         clipstring = 'rect('+clipTop+' '+clipWidth+' '+clipBottom+' ' + clipLeft + ')'            
         thelayer.style.left = totLefter;         
      }
      
      thelayer.style.clip = clipstring;
      
	} else if (document.layers) {
	   
      thelayer.style.clip.top = clipTop;
      thelayer.style.clip.bottom = clipBottom;
      thelayer.style.clip.width = clipWidthOri;

      if (cltWid <= 800) {      
         thelayer.style.clip.left = clipLeft;
         thelayer.style.left = lefter;
      } else {
         totLefter = lefter + smDiv;
         thelayer.style.clip.left = clipLeft;
         thelayer.style.left = totLefter;         
      }
            
	}
	time = setTimeout('fazerScroll()',theTime);
}

// Funcao usada para parar o scroll
function pararScroll() {
   if (time) {
      clearTimeout(time);
   }
}

// Para trocar imagem
function trocaImagem(imagem) {
   
   imgName = imagem + '/' + imagem;
   montaQuadro(false);
   return;
   
}

// Para acesso a posicao nas imagens/mapa
function acessa(vx, vy) {
    
    tamZoom=3;
    zoom('N');
    
    var cltWid = 0;
   
    if (bw.ns4) {
       cltWid = window.innerWidth;      
    } else {
       cltWid = document.body.clientWidth;      
    }   

    var smDiv = (cltWid - 800)/2;	
   
    if (cltWid > 800) {
   
        tmpX = vx + smDiv;
      
    } else {
        
        tmpX = vx;    
    }

    imgClick(tmpX,vy);
    return;
    
}

// Para mouse over das imagens do mapa
function mapaovr(ident) {

   if (bw.ns4) {
      dSupE = document.layers["divSupEsq"];
      dSupD = document.layers["divSupDir"];
      dTxt = document.layers["divTextoMp"];
         
   } else if (bw.ns6) {
      dSupE = document.getElementById("divSupEsq").style;
      dSupD = document.getElementById("divSupDir").style;
      dTxt = document.getElementById("divTextoMp").style;
      
   } else {
      dSupE = divSupEsq.style;
      dSupD = divSupDir.style;
      dTxt = divTextoMp.style;
   }

   if (ident == '1') {    

      if (bw.ns4) {
         dSupE.document.images[28].src = "../../images/quad_bd_sup_2.gif";
         dTxt.document.images[48].src = "../../images/texto_mapa_1.gif";
      } else {
         document.images[28].src = "../../images/quad_bd_sup_2.gif";
         document.images[48].src = "../../images/texto_mapa_1.gif";
      }
      
   } else if (ident == '2') {
   
      if (bw.ns4) {
         dSupE.document.images[29].src = "../../images/quad_bd_inf_2.gif";
         dTxt.document.images[48].src = "../../images/texto_mapa_2.gif";
      } else {
         document.images[29].src = "../../images/quad_bd_inf_2.gif";
         document.images[48].src = "../../images/texto_mapa_2.gif";
      }
   
   } else if (ident == '3') {
   
      if (bw.ns4) {
         dSupE.document.images[30].src = "../../images/quad_bd_inf_2.gif";
         dTxt.document.images[48].src = "../../images/texto_mapa_3.gif";
      } else {
         document.images[30].src = "../../images/quad_bd_inf_2.gif";
         document.images[48].src = "../../images/texto_mapa_3.gif";
      }
   
   } else if (ident == '4') {
   
      if (bw.ns4) {
         dSupE.document.images[31].src = "../../images/quad_bd_inf_2.gif";
         dTxt.document.images[48].src = "../../images/texto_mapa_4.gif";
      } else {
         document.images[31].src = "../../images/quad_bd_inf_2.gif";
         document.images[48].src = "../../images/texto_mapa_4.gif";
      }
   
   } else if (ident == '5') {
   
      if (bw.ns4) {
         dSupE.document.images[32].src = "../../images/quad_bd_inf_2.gif";
         dTxt.document.images[48].src = "../../images/texto_mapa_5.gif";
      } else {
         document.images[32].src = "../../images/quad_bd_inf_2.gif";
         document.images[48].src = "../../images/texto_mapa_5.gif";
      }
   
   } else if (ident == '6') {
   
      if (bw.ns4) {
         dSupE.document.images[33].src = "../../images/quad_bd_sup_d2.gif";
         dTxt.document.images[48].src = "../../images/texto_mapa_6.gif";
      } else {
         document.images[33].src = "../../images/quad_bd_sup_d2.gif";
         document.images[48].src = "../../images/texto_mapa_6.gif";
      }
   
   } else if (ident == '7') {
   
      if (bw.ns4) {
         dSupE.document.images[34].src = "../../images/quad_bd_inf_d2.gif";
         dTxt.document.images[48].src = "../../images/texto_mapa_7.gif";
      } else {
         document.images[34].src = "../../images/quad_bd_inf_d2.gif";
         document.images[48].src = "../../images/texto_mapa_7.gif";
      }
   
   } else if (ident == '8') {
   
      if (bw.ns4) {
         dSupE.document.images[35].src = "../../images/quad_bd_inf_d2.gif";
         dTxt.document.images[48].src = "../../images/texto_mapa_8.gif";
      } else {
         document.images[35].src = "../../images/quad_bd_inf_d2.gif";
         document.images[48].src = "../../images/texto_mapa_8.gif";
      }
   
   } else if (ident == '9') {
   
      if (bw.ns4) {
         dSupE.document.images[36].src = "../../images/quad_bd_inf_d2.gif";
         dTxt.document.images[48].src = "../../images/texto_mapa_9.gif";
      } else {
         document.images[36].src = "../../images/quad_bd_inf_d2.gif";
         document.images[48].src = "../../images/texto_mapa_9.gif";
      }
   
   } else if (ident == '10') {
   
      if (bw.ns4) {
         dSupE.document.images[37].src = "../../images/quad_bd_inf_d2.gif";
         dTxt.document.images[48].src = "../../images/texto_mapa_10.gif";
      } else {
         document.images[37].src = "../../images/quad_bd_inf_d2.gif";
         document.images[48].src = "../../images/texto_mapa_10.gif";
      }
   
   } else if (ident == '11') {
   
      if (bw.ns4) {
         dSupE.document.images[38].src = "../../images/quad_bd_cima_esq2.gif";
         dTxt.document.images[48].src = "../../images/texto_mapa_11.gif";
      } else {
         document.images[38].src = "../../images/quad_bd_cima_esq2.gif";
         document.images[48].src = "../../images/texto_mapa_11.gif";
      }

   } else if (ident == '12') {
   
      if (bw.ns4) {
         dSupE.document.images[39].src = "../../images/quad_bd_cima_2.gif";
         dTxt.document.images[48].src = "../../images/texto_mapa_12.gif";
      } else {
         document.images[39].src = "../../images/quad_bd_cima_2.gif";
         document.images[48].src = "../../images/texto_mapa_12.gif";
      }

   } else if (ident == '13') {
   
      if (bw.ns4) {
         dSupE.document.images[40].src = "../../images/quad_bd_cima_2.gif";
         dTxt.document.images[48].src = "../../images/texto_mapa_13.gif";
      } else {
         document.images[40].src = "../../images/quad_bd_cima_2.gif";
         document.images[48].src = "../../images/texto_mapa_13.gif";
      }

   } else if (ident == '14') {
   
      if (bw.ns4) {
         dSupE.document.images[41].src = "../../images/quad_bd_cima_2.gif";
         dTxt.document.images[48].src = "../../images/texto_mapa_14.gif";
      } else {
         document.images[41].src = "../../images/quad_bd_cima_2.gif";
         document.images[48].src = "../../images/texto_mapa_14.gif";
      }

   } else if (ident == '15') {
   
      if (bw.ns4) {
         dSupE.document.images[42].src = "../../images/quad_bd_cima_dir2.gif";
         dTxt.document.images[48].src = "../../images/texto_mapa_15.gif";
      } else {
         document.images[42].src = "../../images/quad_bd_cima_dir2.gif";
         document.images[48].src = "../../images/texto_mapa_15.gif";
      }

   } else if (ident == '16') {
   
      if (bw.ns4) {
         dSupE.document.images[43].src = "../../images/quad_bd_baixo_esq2.gif";
         dTxt.document.images[48].src = "../../images/texto_mapa_16.gif";
      } else {
         document.images[43].src = "../../images/quad_bd_baixo_esq2.gif";
         document.images[48].src = "../../images/texto_mapa_16.gif";
      }

   } else if (ident == '17') {
   
      if (bw.ns4) {
         dSupE.document.images[44].src = "../../images/quad_bd_baixo_2.gif";
         dTxt.document.images[48].src = "../../images/texto_mapa_17.gif";
      } else {
         document.images[44].src = "../../images/quad_bd_baixo_2.gif";
         document.images[48].src = "../../images/texto_mapa_17.gif";
      }

   } else if (ident == '18') {
   
      if (bw.ns4) {
         dSupE.document.images[45].src = "../../images/quad_bd_baixo_2.gif";
         dTxt.document.images[48].src = "../../images/texto_mapa_18.gif";
      } else {
         document.images[45].src = "../../images/quad_bd_baixo_2.gif";
         document.images[48].src = "../../images/texto_mapa_18.gif";
      }

   } else if (ident == '19') {
   
      if (bw.ns4) {
         dSupE.document.images[46].src = "../../images/quad_bd_baixo_2.gif";
         dTxt.document.images[48].src = "../../images/texto_mapa_19.gif";
      } else {
         document.images[46].src = "../../images/quad_bd_baixo_2.gif";
         document.images[48].src = "../../images/texto_mapa_19.gif";
      }

   } else if (ident == '20') {
   
      if (bw.ns4) {
         dSupE.document.images[47].src = "../../images/quad_bd_baixo_dir2.gif";
         dTxt.document.images[48].src = "../../images/texto_mapa_20.gif";
      } else {
         document.images[47].src = "../../images/quad_bd_baixo_dir2.gif";
         document.images[48].src = "../../images/texto_mapa_20.gif";
      }
   }
   
   return;

}

// Para mouse out das imagens do mapa
function mapaout(ident) {
   
   if (bw.ns4) {
      dSupE = document.layers["divSupEsq"];
      dSupD = document.layers["divSupDir"];
      dTxt = document.layers["divTextoMp"];
         
   } else if (bw.ns6) {
      dSupE = document.getElementById("divSupEsq").style;
      dSupD = document.getElementById("divSupDir").style;
      dTxt = document.getElementById("divTextoMp").style;
      
   } else {
      dSupE = divSupEsq.style;
      dSupD = divSupDir.style;
      dTxt = divTextoMp.style;
   }

   if (ident == '1') {    

      if (bw.ns4) {
         dSupE.document.images[28].src = "../../images/quad_bd_sup_1.gif";
      } else {
         document.images[28].src = "../../images/quad_bd_sup_1.gif";
      }
      
   } else if (ident == '2') {
   
      if (bw.ns4) {
         dSupE.document.images[29].src = "../../images/quad_bd_inf_1.gif";
      } else {
         document.images[29].src = "../../images/quad_bd_inf_1.gif";
      }
   
   } else if (ident == '3') {
   
      if (bw.ns4) {
         dSupE.document.images[30].src = "../../images/quad_bd_inf_1.gif";
      } else {
         document.images[30].src = "../../images/quad_bd_inf_1.gif";
      }
   
   } else if (ident == '4') {
   
      if (bw.ns4) {
         dSupE.document.images[31].src = "../../images/quad_bd_inf_1.gif";
      } else {
         document.images[31].src = "../../images/quad_bd_inf_1.gif";
      }
   
   } else if (ident == '5') {
   
      if (bw.ns4) {
         dSupE.document.images[32].src = "../../images/quad_bd_inf_1.gif";
      } else {
         document.images[32].src = "../../images/quad_bd_inf_1.gif";
      }
   
   } else if (ident == '6') {
   
      if (bw.ns4) {
         dSupE.document.images[33].src = "../../images/quad_bd_sup_d1.gif";
      } else {
         document.images[33].src = "../../images/quad_bd_sup_d1.gif";
      }
   
   } else if (ident == '7') {
   
      if (bw.ns4) {
         dSupE.document.images[34].src = "../../images/quad_bd_inf_d1.gif";
      } else {
         document.images[34].src = "../../images/quad_bd_inf_d1.gif";
      }
   
   } else if (ident == '8') {
   
      if (bw.ns4) {
         dSupE.document.images[35].src = "../../images/quad_bd_inf_d1.gif";
      } else {
         document.images[35].src = "../../images/quad_bd_inf_d1.gif";
      }
   
   } else if (ident == '9') {
   
      if (bw.ns4) {
         dSupE.document.images[36].src = "../../images/quad_bd_inf_d1.gif";
      } else {
         document.images[36].src = "../../images/quad_bd_inf_d1.gif";
      }
   
   } else if (ident == '10') {
   
      if (bw.ns4) {
         dSupE.document.images[37].src = "../../images/quad_bd_inf_d1.gif";
      } else {
         document.images[37].src = "../../images/quad_bd_inf_d1.gif";
      }

   } else if (ident == '11') {
   
      if (bw.ns4) {
         dSupE.document.images[38].src = "../../images/quad_bd_cima_esq1.gif";
      } else {
         document.images[38].src = "../../images/quad_bd_cima_esq1.gif";
      }

   } else if (ident == '12') {
   
      if (bw.ns4) {
         dSupE.document.images[39].src = "../../images/quad_bd_cima_1.gif";
      } else {
         document.images[39].src = "../../images/quad_bd_cima_1.gif";
      }

   } else if (ident == '13') {
   
      if (bw.ns4) {
         dSupE.document.images[40].src = "../../images/quad_bd_cima_1.gif";
      } else {
         document.images[40].src = "../../images/quad_bd_cima_1.gif";
      }

   } else if (ident == '14') {
   
      if (bw.ns4) {
         dSupE.document.images[41].src = "../../images/quad_bd_cima_1.gif";
      } else {
         document.images[41].src = "../../images/quad_bd_cima_1.gif";
      }

   } else if (ident == '15') {
   
      if (bw.ns4) {
         dSupE.document.images[42].src = "../../images/quad_bd_cima_dir1.gif";
      } else {
         document.images[42].src = "../../images/quad_bd_cima_dir1.gif";
      }

   } else if (ident == '16') {
   
      if (bw.ns4) {
         dSupE.document.images[43].src = "../../images/quad_bd_baixo_esq1.gif";
      } else {
         document.images[43].src = "../../images/quad_bd_baixo_esq1.gif";
      }

   } else if (ident == '17') {
   
      if (bw.ns4) {
         dSupE.document.images[44].src = "../../images/quad_bd_baixo_1.gif";
      } else {
         document.images[44].src = "../../images/quad_bd_baixo_1.gif";
      }

   } else if (ident == '18') {
   
      if (bw.ns4) {
         dSupE.document.images[45].src = "../../images/quad_bd_baixo_1.gif";
      } else {
         document.images[45].src = "../../images/quad_bd_baixo_1.gif";
      }

   } else if (ident == '19') {
   
      if (bw.ns4) {
         dSupE.document.images[46].src = "../../images/quad_bd_baixo_1.gif";
      } else {
         document.images[46].src = "../../images/quad_bd_baixo_1.gif";
      }

   } else if (ident == '20') {
   
      if (bw.ns4) {
         dSupE.document.images[47].src = "../../images/quad_bd_baixo_dir1.gif";
      } else {
         document.images[47].src = "../../images/quad_bd_baixo_dir1.gif";
      }
   
   }
   
   if (bw.ns4) {
      dTxt.document.images[48].src = "../../images/spacer.gif";
   } else {
      document.images[48].src = "../../images/spacer.gif";
   }
   
   return;

}


