// Variáveis globais
var T; // para armazenar o objeto da div global tudo
var W; // para armazenar a largura da tela últil
var H; // para armazenar a altura da tela útil
var N; // para armazenar o objeto da barra de navegação
var NTop; // posição inicial da barra de nvagegação

var categorias = new Array('secoes', 'projetos', 'cases', 'cvisual', 'conteudo', 'curadoria', 'video');
var categoria_ativa = 0;
var cell_trava = true; // trava a exibição dos rollovers nas células enquanto não carregaram as imagens
var celula_linha_atual = 1; // determina qual a linha que está sendo adicionada (animação)
var celulas = new Array(); // armazena as células presentes na página
var celulas_liberadas = false; // trava o click nas células até que a animação tenha terminado
var celulas_requisitacao = ""; // determina se houve uma requisitação para abertura de células
var celulas_ultimo_objeto; //armazena o último objeto que solicitou celulas_carrega()
var celulas2 = new Array(); // armazena as células presentes na página
var colunas = 0; // armazena os modos 2 = 4X3 e 1 = 3X2 de colunas.
var conta_celulas = 0; // contagem de células presentes na página
var conta_celulas2 = 0; // contagem de células presentes na página
var contato_fechado = true; // determina se o menu de contato está aberto ou fechado
var contatoPos = 0; // checa qual a posição em relação a tela em que está o final do botão contato
var controlPress = false; // Identifica se a tecla control está pressionada
var form_em_foco = false; // determina se o formulário está em edição ou não
var item_em_foco = 0; // determina que botão do menu está em foco (0=nenhum, 1=contato, 2=atuação, 3=demais)
var linkou_maisinfo = false; // determina se o painel de +info está aberto
var menu_aberto = false; // determina se o menu está aberto ou fechado
var menu_liberado = false; // trava o menu até que ele seja destravado
var menu_maisinfo_aberto = false; // determina se o menu +info está aberto ou fechado
var menuPosAberto = -22; // determina a posição do menu aberto
var menuPosFechado = -900; // determina a posição do menu fechado
var menusInfo = new Array(); // determina quando o menu +info deve aparecer ou não
var permaurl; // armazena o permalink
var permafoco = false; // determina se o permalinkbox está em foco ou não
var sobre_carregou = false; // determina se o painel lateral esquerdo já foi carregado
// - removido para o index.php var sobreAberto = false; // verifica se a página sobre está aberta ou fechada
var sobreRolou = "sobre-quemsomos"; // determina se a seção sobre está em quem somos ou clientes
var sobrePos = 0; // checa qual a posição em relação à tela em que está o botão sobre
var temporizador; // armazena timers
var zoom_ativo; // contém o número parte do id da article que envolve a imagem de zoom atual
var zoom_foi = false; // determina se o zoom está aberto


// JavaScript Document
// Detecção de navegador
var ns = document.layers;
var ie = document.all;
var ns6 = (document.getElementById && !document.all);

// Funções ligadas ao movimento do mouse
function mouses(e){

 var mousePosX;
 var mousePosY;

 if(ie){
  mousePosX = event.clientX;
  mousePosY = event.clientY;
 }else if (ns){
  mousePosX = e.x;
  mousePosy = e.y;
 }else if (ns6){
  mousePosX = e.clientX;
  mousePosY = e.clientY;
 }


 // Ativação ou desativação do menu
 var menu_t = parseInt(N.offsetTop);

 if(item_em_foco==1){ var menu_limit = 280; var menu_limit2 = 0; }
 else if(item_em_foco==2){ var menu_limit = 156; var menu_limit2 = 0; }
 else{ var menu_limit = 90; var menu_limit2 = sobrePos[1]; }

 if((mousePosX<menu_limit2 || mousePosX>contatoPos[1]+contatoPos[2]) && menu_aberto && (!form_em_foco || contato_fechado)){ item_em_foco=3; subs(1, 1); barra_vai(document.getElementById('li_maissoma')); }
 if((mousePosY<menu_t-100 || mousePosY>menu_t+menu_limit) && !form_em_foco ){ menu_vai(1); }

}

function ob_pos(id){ // posição real de um objeto na tela

 var curleft = curtop = 0;
 var obj = document.getElementById(id);
 var obw = parseInt(obj.offsetWidth);
 var obh = parseInt(obj.offsetHeight);

 if(obj.offsetParent){

  do{

   curleft += parseInt(obj.offsetLeft);
   curtop += parseInt(obj.offsetTop);

  } while (obj = obj.offsetParent);

 }else{

  curleft = parseInt(obj.offsetLeft);
  curtop = parseInt(obj.offsetTop);

 }

 return(new Array(curtop, curleft, obw, obh));

}


// Funções diretas iniciais
function tela_ajusta(){ // Inicia e mantém o tamanho de tela útil

 T = document.getElementById('tudo');
 W = parseInt(T.offsetWidth);
 H = parseInt(T.offsetHeight);

}


function reload_tela(inclui_w){

 tela_ajusta();

 var loc = window.location.toString();

 if(loc.indexOf("?")>0) loc = loc + "&W="+W;
 else loc = loc + "?W="+W;
 window.location = loc;

}


function posicionamentos(){

 tela_ajusta();
 
 if(!sobreAberto) document.getElementById('painel-esquerdo').style.left = (W*-2) + "px";
 else if(sobreRolou=="sobre-clientes") document.getElementById('sobre-conteudo-in').style.top = (parseInt(document.getElementById('sobre-quemsomos').offsetHeight)*-1) + "px";

 var tudo_in_in = document.getElementById('tudo-in-in-in');
 
 if(W<1200 && colunas==2){

  colunas = 1;
  window.setTimeout(function(){ celulas_carrega(celulas_ultimo_objeto, true); }, 0);

 }else if(W>=1200 && colunas==1){

  colunas = 2;
  window.setTimeout(function(){ celulas_carrega(celulas_ultimo_objeto, true); }, 0);

 }
 
 if(linkou_maisinfo) var W2 = 300;
 else W2 = 0;
 
 var home = document.getElementById('home');
  
 if(W>=1200){

  if(home) home.style.width = "1200px";
  document.getElementById('painel-direito').style.width = "900px";
  tudo_in_in.style.width = "2100px";
  if(zoom_foi) tudo_in_in.style.left = (W+W2-2100) + "px";
  else tudo_in_in.style.left = (W+W2-1200) + "px";
  document.getElementById('projetos-nav').style.width = (W-944) + "px";
  document.getElementById('linka_maisinfo_article').style.left = (W-900) + "px";
  menuPosFechado = W-900-parseInt(screen.availWidth);
  document.getElementById('li_maissoma').style.right = "920px";
  
  var quem =  document.getElementById('sobre-quemsomos-article');
  if(quem){
   document.getElementById('sobre-conteudo').style.width = "900px";
   quem.style.top = "0";
   document.getElementById('sobre-quemsomos-aside').style.left = "300px";
   document.getElementById('sobre-quemsomos-aside').style.width = (parseInt(document.getElementById('quemsomos-ancora').offsetWidth)-300) + "px";
   document.getElementById('sobre-nav').style.width = (W-944) + "px";
   document.getElementById('sobre-nav').style.right = (W-parseInt(document.getElementById('sobre-conteudo').offsetLeft)) + "px";
   document.getElementById('sobre-clientes-aside').style.left = "600px";
   document.getElementById('sobre-clientes-aside').style.paddingTop = "228px";
   document.getElementById('sobre-clientes-aside').style.top = "0";
  }
  
 }else if(W>=900){

  if(home) home.style.width = "900px";
  document.getElementById('painel-direito').style.width = "600px";
  tudo_in_in.style.width = "1500px";
  if(zoom_foi) tudo_in_in.style.left = (W-1500) + "px";
  else tudo_in_in.style.left = (W+W2-900) + "px";
  document.getElementById('projetos-nav').style.width = (W-644) + "px";
  document.getElementById('linka_maisinfo_article').style.left = (W-600) + "px";
  menuPosFechado = W-600-parseInt(screen.availWidth);
  document.getElementById('li_maissoma').style.right = "620px";

  var quem =  document.getElementById('sobre-quemsomos-article');
  if(quem){
   document.getElementById('sobre-conteudo').style.width = "600px";
   quem.style.top = parseInt(document.getElementById('sobre-quemsomos-aside').offsetHeight) + "px";
   document.getElementById('sobre-quemsomos-aside').style.left = "0";
   document.getElementById('sobre-quemsomos-aside').style.width = "100%";
   document.getElementById('sobre-nav').style.width = (W-644) + "px";
   document.getElementById('sobre-nav').style.right = (W-parseInt(document.getElementById('sobre-conteudo').offsetLeft)) + "px";
   document.getElementById('sobre-clientes-aside').style.left = "0";
   document.getElementById('sobre-clientes-aside').style.paddingTop = "22px";
   document.getElementById('sobre-clientes-aside').style.top = (parseInt(document.getElementById('sobre-clientes-section').offsetTop)+parseInt(document.getElementById('sobre-clientes-section').offsetHeight)) + "px";
  }

 }else{

  if(home) home.style.width = "900px";
  document.getElementById('painel-direito').style.width = "600px";
  tudo_in_in.style.width = "1500px";
  if(zoom_foi) tudo_in_in.style.left = (-600) + "px";
  else tudo_in_in.style.left = (0+W2) + "px";
  document.getElementById('projetos-nav').style.width = 256 + "px";
  document.getElementById('linka_maisinfo_article').style.left = 300 + "px";
  menuPosFechado = 300-parseInt(screen.availWidth);
  document.getElementById('li_maissoma').style.right = "620px";

  var quem =  document.getElementById('sobre-quemsomos-article');
  if(quem){
   document.getElementById('sobre-conteudo').style.width = "600px";
   quem.style.top = parseInt(document.getElementById('sobre-quemsomos-aside').offsetHeight) + "px";
   document.getElementById('sobre-quemsomos-aside').style.left = "0";
   document.getElementById('sobre-quemsomos-aside').style.width = "100%";
   document.getElementById('sobre-nav').style.width = "256px";
   document.getElementById('sobre-nav').style.right = (900-parseInt(document.getElementById('sobre-conteudo').offsetLeft)) + "px";
   document.getElementById('sobre-clientes-aside').style.left = "0";
   document.getElementById('sobre-clientes-aside').style.paddingTop = "22px";
   document.getElementById('sobre-clientes-aside').style.top = (parseInt(document.getElementById('sobre-clientes-section').offsetTop)+parseInt(document.getElementById('sobre-clientes-section').offsetHeight)) + "px";
  }

 }
 
 // Ajusta o painel de informações do painel direito
 if(H<630){

  N.style.top =  "162px";
  NTop = 162;
  document.getElementById('loader').style.top = "199px";

 }else{

  N.style.top =  "377px";
  NTop = 377;
  document.getElementById('loader').style.top = "414px";

 }
 
 menuPosAberto = W-parseInt(screen.availWidth)-22;
 

 if(!menu_aberto) N.style.left = menuPosFechado + "px";
 N.style.width = parseInt(screen.availWidth) + "px";
 document.getElementById('li_barra').style.width = (parseInt(screen.availWidth)*2) + "px";

}


function inicia_tudo(){

 // Altera a nome da classe css do menu
 N = document.getElementById('navegacao');
 N.className = "nave2";
 N.onmouseover = function(){ menu_vai(0); }
 
 if(!celulas_ultimo_objeto){

  celulas_ultimo_objeto = document.getElementById('li_home_in');
  categoria_ativa = 0;
  celulas_ultimo_objeto.cat = 0;

 }

 // Inicia os itens da barra de navegação
 var nava = N.getElementsByTagName('li');

 for(i in nava){ // Movimentação da barra de navegação

  if(nava[i].id=="li_1"){ // Botão Contato

   nava[i].h = parseInt(nava[i].offsetHeight);
   nava[i].getElementsByTagName('a')[0].onmouseover = function(){ if(menu_aberto){ item_em_foco=1; barra_vai(this.parentNode); subs(0, 1); } }

   var campos = nava[i].getElementsByTagName('input');
   for(var c=0; c<campos.length; c++){

    campos[c].onfocus = function(){ form_em_foco = true;  }
    campos[c].onblur = function(){ form_em_foco = false; }

   }

   // Providenciam para que o formulário não feche enquanto o usuário estiver digitando
   var c_nome = document.getElementById('c_nome_in');
   c_nome.onfocus = function(){ form_em_foco = true;  }
   c_nome.onblur = function(){ form_em_foco = false; }
   
   var c_email = document.getElementById('c_email_in');
   c_email.onfocus = function(){ form_em_foco = true;  }
   c_email.onblur = function(){ form_em_foco = false; }
   
   var c_assunto = document.getElementById('c_assunto_in');
   c_assunto.onfocus = function(){ form_em_foco = true;  }
   c_assunto.onblur = function(){ form_em_foco = false; }

   var c_mensagem = document.getElementById('c_mensagem_in');
   c_mensagem.onfocus = function(){ form_em_foco = true;  }
   c_mensagem.onblur = function(){ form_em_foco = false; }
   
   document.getElementById('c_botoes').style.marginTop = (parseInt(document.getElementById('c_mensagem_in').offsetTop)+parseInt(document.getElementById('c_mensagem_in').offsetHeight)-parseInt(document.getElementById('c_botoes').offsetTop)) + "px";

  }else if(nava[i].id=="li_2"){ // Botão Atuação

   nava[i].h = parseInt(nava[i].offsetHeight);
   nava[i].getElementsByTagName('a')[0].onmouseover = function(){  if(menu_aberto){ item_em_foco=2; barra_vai(this.parentNode); subs(1, 0); } }

  }else if(nava[i].id=="li_maissoma" || nava[i].id=="li_3" || nava[i].id=="li_4"){

   nava[i].getElementsByTagName('a')[0].onmouseover = function(){  if(menu_aberto){ item_em_foco=3; subs(1, 1); barra_vai(this.parentNode); } }

   // Botão Sobre
   if(nava[i].id=="li_4"){ nava[i].getElementsByTagName('a')[0].onclick = function(){ if(!controlPress){ sobre(); return false; } } }
   // Botão Cases
   else if(nava[i].id=="li_3"){ nava[i].getElementsByTagName('a')[0].onclick = function(){ if(!controlPress){ this.cat=2; celulas_carrega(this, false); return false; } } }

  }else if(nava[i].id=="li_home"){ // Botão Home

   nava[i].onmouseover = function(){  if(menu_aberto){ item_em_foco=3; subs(1, 1); } }
   nava[i].getElementsByTagName('a')[0].onclick = function(){ if(!controlPress){ categoria_ativa = 0; this.cat = 0; celulas_carrega(this, false); return false; } }

  }else if(nava[i].className=='li_atuacao_in_in'){ // Subitens do menu atuação

   var novaNava = nava[i].getElementsByTagName('a')[0];
   novaNava.cat = nava[i].id.split("_")[1];
   novaNava.onmouseover = function(){ if(menu_aberto){  menusub_vai(this); } }
   novaNava.onclick = function(){ if(!controlPress){ celulas_carrega(this, false); return false; } }

  }

 }


 var lts = document.getElementById('projetos-titulo-in').getElementsByTagName('a');
 for(var lt=0; lt<lts.length; lt++){

  ltsInfo = lts[lt].id.split("_");
  lts[lt].cat = ltsInfo[1];
  lts[lt].onclick = function(){ celulas_carrega(this, false); return false; }

 }

 document.getElementById('linka_compartilhar').onclick = function(){ linka_copia(false); }
 document.getElementById('linka_permalink_fecha').onclick = function(){ linka_copia(true); }

 document.getElementById('linka_maisinfo').onclick = function(){ if(this.foi==true){ linka_maisinfo(false); }else{ linka_maisinfo(true); } }
 document.getElementById('linka_maisinfo_fechar').onclick = function(){ linka_maisinfo(false); }

 var maisinfo = document.getElementById('linka_maisinfo_article_in');

 document.getElementById('contato_foi').onclick = function(){ contato_retorna(true); }
 document.getElementById('contato_err').onclick = function(){ contato_retorna(false); }

 posicionamentos();

 celulas_inicia();

 NTop = parseInt(N.offsetTop);

 if(W<1200) colunas = 1;
 else colunas = 2;

 barra_vai(null);
 
 sobre_carrega()
 if(!sobreAberto) document.getElementById('painel-esquerdo').style.left = (W*-2) + "px";

 document.getElementById('linka_permalink').onfocus = function(){ permafoco = true; }
 document.getElementById('linka_permalink').onblur = function(){ permafoco = false; }


 // ativação das funções contínuas
 window.onresize = posicionamentos;
 document.onmousemove = mouses;
 document.getElementById('tudo-in-in').onscroll = function(){ this.scrollLeft = 0; }
 document.getElementById('tudo-in').onscroll = function(){ this.scrollLeft = 0; }
 document.getElementById('tudo').onscroll = function(){ this.scrollLeft = 0; }
 document.body.onscroll = function(){ this.scrollLeft = 0; }

}


function scroll_zera(e){

 if(!e) e = window.event;

 e.srcElement.scrollLeft = 0;
 
 if(e.preventDefault) e.preventDefault();
 else e.returnValue = false;

}


/* Funções ligadas às células */
function celula_rola(imagem){ // Ativada quando do carregamento da imagem

 if(imagem!="x"){

  var celula = imagem.parentNode.parentNode;

  celula.W = parseInt(imagem.offsetWidth);
  celula.H = parseInt(imagem.offsetHeight);

  celula.style[celula.p] = (0-celula.H) + "px";
  celula.style.visibility = "visible";

  conta_celulas--;

 }

 if(conta_celulas == 0){ celulas.reverse(); celulas_vai(0, 0); if(!sobre_carregou){ /*sobre_carrega();*/ } }

}


function celulas_carrega(ob, mantem_esquerdo){

 if(!mantem_esquerdo) painel_esquerdo_fecha();

 celulas_ultimo_objeto = ob;

 document.getElementById('projetos-titulo-header').innerHTML = "";
 
 document.getElementById('tudo-in-in').style.overflowY = "hidden";

 document.getElementById('tudo-in-in-in').style.visibility = "hidden";

 document.title = "Kultur Studio";

 linka_maisinfo(false);

 celulas_liberadas = true;

 linka_copia(true);

 if(celulas_liberadas){

  var idp;

  if(ob.idpro){

   idp = "&idpro="+ob.idpro;
   var idp2 = "?idpro="+ob.idpro;
   window.setTimeout(function(){ ajaxHTML("projetos-titulo-header", "main_forms.php", "p=projeto_header&h="+H+"&w="+W+idp, "<p id='inner'>Carregando...</p>", "header_carregou()"); }, 500);
   window.setTimeout(function(){ ajaxHTML("linka_maisinfo_article_in", "main_forms.php", "p=projeto_info&h="+H+"&w="+W+idp, "Carregando...", "info_carregou()"); }, 500);

  }else{

   var idp = "";
   var idp2 = "";
   document.getElementById('projetos-titulo-header').innerHTML = "";
   document.getElementById('linka_maisinfo_article_in').innerHTML = "";

  }

  if(ob.linko){ var endereco = ob.linko; }
  else{ var endereco = categorias[ob.cat]; }

  window.setTimeout(function(){ ajaxHTML("tudo-in-in-in", "main_forms.php", "p="+endereco+"&h="+H+"&w="+W+idp, "Carregando...", "celulas_carregou('"+ob.cat+"')"); }, 500);

  permaurl = "www.kulturstudio.com/"+endereco+".php"+idp2;

  //painel_esquerdo_fecha();
  zoom_vai(null);
  celulas_liberadas = false;
  celulas = new Array();
  celulas2 = new Array();
  celula_linha_atual = 1;

  if(!idp || (idp && categoria_ativa==0) || (idp && ob.pvai)){

   titulo_rola('projetos-titulo-in', categorias[ob.cat]);
   categoria_ativa = ob.cat;

  }

  conta_celulas = 0;
  conta_celulas2 = 0;

  menu_maisinfo(true);

 }

}


function celulas_carregou(categoria){

 document.getElementById('tudo-in-in').style.overflowY = "hidden";
 document.getElementById('loader').style.display = "inherit";

 if(zoom_foi){

  celulas_requisitacao = categoria;

 }else{

  celulas_inicia();

  var obj = document.getElementById('projetos-nav');

  var zi = document.getElementById('painel-direito-in-in');
  if(zi){ var zh = parseInt(zi.offsetHeight); }
  else{ var zh = 0; }
  if(zh>H){ var hh = zh; }
  else{ var hh = H; }

  obj.style.height = hh + "px";

  obj.p = "top";
  obj.q = "offsetTop";
  obj.s = s_projetos_nav;
  if(categoria!=0){ obj.v = 0; }
  else{ obj.v = hh*-1; }

  movimenta(obj);

  titulo_rola('projetos-titulo-in', categorias[categoria]);

 }
 
 posicionamentos();


}


function celulas_inicia(){

 if(W<1200 && !colunas){
 
   colunas = 1;
   window.setTimeout(function(){ celulas_carrega(celulas_ultimo_objeto, true); }, 500);
  
 }else{

 // Rollover e rollout das imagens
 var cells = document.getElementById('home').getElementsByTagName('section');
 var celulas_carregadas = new Array();
 var temZoom = document.getElementById('painel-direito-in');

 for(i in cells){

  if(cells[i].className=="cell" || cells[i].className=="cellv"){

   if(cells[i].className=="cellv"){ var temVideo = true; }
   else{ var temVideo = false; }

   cells[i].className = "cell2";
   cells[i].style.visibility = "visible";

   var nSpan = document.createElement('a');
   nSpan.className = "over_over";
   nSpan._alpha = 0;

   if(temVideo){

    nSpan.innerHTML = "<img src='imagens/site/kultur-thumb-video-seta.png' alt='Play' class='over_normal' /><img src='imagens/site/kultur-thumb-video-setaplay.png' alt='Play' class='over_sobre' />";

   }

   var link = cells[i].getElementsByTagName('a')[0].href.split("/").pop().split(".php?");
   nSpan.linko = link[0];

   var extros = link[1].split("&");

   for(var j=0; j<extros.length; j++){

    var extro_in = extros[j].split("=");
    if(extro_in[1]){ nSpan[extro_in[0]] = extro_in[1]; }

   }

   nSpan.lk = cells[i].getElementsByTagName('a')[0].href;

   nSpan.onmouseover = function(){ cell_mostra(this, 10); }
   nSpan.onmouseout = function(){ cell_mostra(this, -5); }
   if(temZoom){ nSpan.onclick = function(){ zoom_vai(this); }; }
   else{ nSpan.onclick = function(){ if(controlPress){ this.href=this.lk; }else{ this.hrref="#"; celulas_carrega(this, false); } } }


   cells[i].spanClic = nSpan;

   cells[i].appendChild(nSpan);

   var cellImg = cells[i].getElementsByTagName('img')[0];

   if(cellImg){ cellImg.parentNode.parentNode.style.visibility = 'hidden'; }

   var cellParent = cellImg.parentNode;
   cellParent.removeChild(cellImg);

   var cellSrc =  cellImg.src;

   var nImg = document.createElement('img');
   nImg.src = cellSrc;
   nImg.onload = function(){ celula_rola(this); }

   cellParent.appendChild(nImg);

   /*
   if(parseInt(cellImg.offsetHeight)>0){ celulas_carregadas.push(cellImg); }
   else{ cellImg.onload = function(){ celula_rola(this); } }
   */

   cells[i].p = "top"; // propriedade que será alterada
   cells[i].q = "offsetTop";
   cells[i].t = 1;
   cells[i].ft = 100;
   cells[i].s = s_celulas;
   cells[i].b = "x";
   cells[i].T = parseInt(cells[i].offsetTop);
   cells[i].L = parseInt(cells[i].offsetLeft);

   var nome = cells[i].id.split("_");

   if(typeof(celulas[nome[1]])!="object"){ celulas[nome[1]] = new Array(); }
   celulas[nome[1]][nome[2]] = cells[i];
   conta_celulas++;
   conta_celulas2++;

  }

 }

 if(temZoom){

  menu_maisinfo(false);
  var zooms = document.getElementById('zoom_nav').getElementsByTagName('span');
  for(i in zooms){ zooms[i].onclick = function(){ zoom_anda(this); } }

 }

 for(i in celulas_carregadas){

  celula_rola(celulas_carregadas[i]);

 }
 
 }

}


function celulas_oculta(){

 var cells = document.getElementById('home').getElementsByTagName('section');
 for(var i=0; i<cells.length; i++){

  cells[i].style.visibility = "hidden";

 }

}


function celulas_vai(n, vai_tudo){ // Animação de entrada das células

 document.getElementById('loader').style.display = "none";

 if(celulas[n]){

  document.getElementById('tudo-in-in-in').style.visibility = "visible";
  document.getElementById('tudo-in-in-in').style.height = ((n+1)*215) + "px";

  if(vai_tudo){

   for(i in celulas2){

    if(celulas2[i].b=="x"){

     celulas2[i].v = parseInt(celulas2[i][celulas2[i].q])+celulas2[i].H;

     if(celulas2[i].v<=celulas2[i].T){

      movimenta(celulas2[i]);
      celulas2[i].f = "";

     }

    }

   }

  }

  var cell = celulas[n].shift();

  if(cell){

   if(cell.b=="x"){

    cell.v = parseInt(cell[cell.q])+cell.H;

    if(cell.v<=cell.T){

     cell.f = "celulas_vai("+n+", 0);";

     celulas2.push(cell);

     movimenta(cell);

    }

   }

  }else{

   if(celulas[n].length>=1){ celulas_vai(n, 0); }
   else{ celulas_vai(n+1, 1); }

  }

  if(((n+1)*215)>H) document.getElementById('tudo-in-in').style.overflowY = "auto";

 }else{

  var zi = document.getElementById('painel-direito-in-in');
  if(zi){ var zh = parseInt(zi.offsetHeight); }
  else{ var zh = 0; }
  var ch =  n*215;
  if(zh>ch){ document.getElementById('tudo-in-in-in').style.height = zh + "px"; }
  else{ document.getElementById('tudo-in-in-in').style.height = ch + "px"; }

  if(conta_celulas2==1){ zoom_vai(document.getElementById('c_0_0').spanClic); }
  celulas_liberadas = true;

  document.getElementById('tudo-in-in').style.overflowY = "auto";

 }

}


function cell_opac(ob){ // Animação de esmaecimento quando do rollover da célula

 ob._alpha+= ob.modo;

 if(ob._alpha>100){ ob._alpha = 100; ob.running = 0; }
 else if(ob._alpha<0){ ob._alpha = 0; ob.running = 0; }

 if(ob.parentNode.getElementsByTagName('header')[0]){ changeOpac(ob._alpha, ob.parentNode.getElementsByTagName('header')[0], ''); }
 changeOpac(ob._alpha, ob.parentNode.getElementsByTagName('span')[0], '');

 if(ob.running){ setTimeout(function(){ cell_opac(ob); }, 0); }

}


function cell_mostra(ob, modo){  // Rollover da célula

 ob.modo = modo;

 if(!ob.running){ ob.running = 1; cell_opac(ob); }

}


function h2_troca(titulo, vai){ // troca o título do projeto

 var obj = document.getElementById('projetos-titulo-in-in-in');
 obj.p = "top";
 obj.q = "offsetTop";
 obj.s = 3;

 if(vai==1){

  obj.innerHTML = titulo;
  obj.v = 0;

 }else{

  obj.v = parseInt(obj.offsetHeight)*-1;
  if(titulo){

   obj.f = "h2_troca('"+titulo+"', 1);";

  }

 }

 movimenta(obj);

}


function header_carregou(){

 var lsi = document.getElementById('projetos-titulo-in-in-in-in-in-in');

 if(lsi){

  var ls = lsi.getElementsByTagName('a');
  for(var i=0; i<ls.length; i++){

   ls[i].pvai = true;
   var infos = ls[i].href.split(".php?");
   var infos_in = infos[1].split("&");
   ls[i].idpro = infos_in[0].split("=")[1];
   ls[i].cat = infos_in[1].split("=")[1];
   ls[i].onclick = function(){ celulas_carrega(this, false); return false; }

  }

 }

 document.title = "Kultur Studio / "+document.getElementById('projetos-titulo-in-in').innerHTML;

}


function info_carregou(){



}


// Funções ligadas ao menu
function atuacao_vai(volta){

 var barh = parseInt(document.getElementById('bt_atuacao').offsetHeight);

 document.getElementById('li_atuacao').style.width = (parseInt(document.getElementById('li_2').offsetLeft)+parseInt(document.getElementById('li_2').offsetWidth)) + "px";
 document.getElementById('li_atuacao').style.top = (19-barh) + "px";

 ob = document.getElementById('li_atuacao_in');

 ob.p = "top";
 ob.q = "offsetTop";
 ob.s = s_atuacao_vai;

 ob2 = ob.parentNode;
 ob2.p = "height";
 ob2.q = "offsetHeight";
 ob2.s = s_atuacao_vai;

 if(volta){

  ob.v = -80;
  ob2.v = 0;
  menusub_vai(null);

 }else{

  var altura = 0;

  ob.v = 0;
  ob2.v = 82;

  for(var i=3; i<=6; i++){

   var obi = document.getElementById('at_'+i);
   var normal = obi.getElementsByClassName('normal')[0];
   var over = obi.getElementsByClassName('over')[0];

   altura+= parseInt(obi.offsetHeight);

   normal.style.display = "inherit"; over.style.display = "none";

  }

  document.getElementById('li_atuacao_in').style.height = altura + "px";

 }

 movimenta(ob);
 movimenta(ob2);

}

function barra_vai(item){

 var ob = document.getElementById('li_barra');

 ob.p = "left"; // propriedade que será alterada
 ob.q = "offsetLeft";

 ob.o = parseInt(ob[ob.q]); // valor inicial da propriedade

 ob.s = s_barra;
 ob.t = 10;

 var w = parseInt(ob.offsetWidth);

 if(!item){

  item = document.getElementById('li_maissoma');
  var num = 5;

 }else{

  var nome = item.id.split("_");
  var num = nome[1];

 }

 //ob.v = (parseInt(item.offsetLeft)+parseInt(item.offsetWidth))-w+W;
 ob.v = (w/-2)+(parseInt(item.offsetLeft)+parseInt(item.offsetWidth));
 movimenta(ob);

 for(var i=4; i>=1; i--){

  if(i>=num){

   document.getElementById('li_'+i+'_n').style.display = 'none';
   document.getElementById('li_'+i+'_o').style.display = 'inherit';

  }else{

   document.getElementById('li_'+i+'_n').style.display = 'inherit';
   document.getElementById('li_'+i+'_o').style.display = 'none';

  }

 }

}


function menu_foi(volta){

 var as = N.getElementsByTagName('span');

 for(i in as){

  if(volta){ var valor = -1; var valor2 = -80;}
  else{ var valor = -80; var valor2 = -1; }

  if(as[i].className=="menu_hide_in"){

   as[i].p = "left"; // propriedade que será alterada
   as[i].j = valor;

   as[i].s = s_menu_foi;
   as[i].t = 10;

   as[i].v = valor2;

   movimenta(as[i]);

  }

 }

 var home = document.getElementById("li_home_in");
  if(home){

   if(volta){ var valor = 60; var valor2 = 1;}
   else{ var valor = 1; var valor2 = 60; }

   home.p = "left"; // propriedade que será alterada
   home.j = valor;

   home.s = s_home;
   home.t = 10;

   home.v = valor2;

   movimenta(home);

  }

 if(!volta){ menu_aberto = true; sobrePos = ob_pos('li_4'); contatoPos = ob_pos('li_1'); }

}


function menu_maisinfo(volta){

  var menuInfo = document.getElementById('menu-info');
  menuInfo.p = "top";
  menuInfo.q = "offsetTop";
  menuInfo.s = s_maisinfo;

  if(volta){

   menuInfo.v = parseInt(menuInfo.offsetHeight)*-1;

  }else{

   menuInfo.v = 0;
   var pos = parseInt(menuInfo.parentNode.offsetTop);
   var fechar = document.getElementById('linka_maisinfo_fechar');
   var alt = parseInt(fechar.offsetHeight);
   fechar.parentNode.parentNode.parentNode.style.top = (pos-alt) + "px";

  }

  /*
  var mais = document.getElementById('linka_maisinfo');
  mais.indice = indice;
  mais.onclick = function(){ mais_info(this, 1); }
  */
  movimenta(menuInfo);

}


function menu_vai(volta){

 N.p = "left"; // propriedade que será alterada
 N.q = "offsetLeft";

 N.o = parseInt(N[N.q]); // valor inicial da propriedade

 N.s = s_menu_vai;

 if(menu_aberto && volta){ menu_aberto = false; subs(1, 1); N.f = "menu_foi(1)"; N.v = menuPosFechado; barra_vai(null); movimenta(N); N.style.height = "35px"; }// novo valor que a propriedade deve assumir
 else if(!menu_aberto && !volta){ N.f = "menu_foi(0)"; N.v = menuPosAberto; movimenta(N); N.style.height = "300px"; barra_vai(null); }

}


function menusub_vai(ob){

 var obj = document.getElementById('li_atuacao_in_barra2');

 obj.p = "top"; // propriedade que será alterada
 obj.q = "offsetTop";
 obj.o = parseInt(obj[obj.q]); // valor inicial da propriedade
 obj.s = 1;
 obj.t = 1;

 var delay = 0; // atraso nas animações em milésimos de segundos

 if(ob){

  var idi = ob.parentNode.id.split("_")[1];
  obj.v = parseInt(ob.parentNode.offsetTop)+parseInt(ob.parentNode.offsetHeight)-(parseInt(obj.offsetHeight)/2);

 }else{

  var idi = 0;
  obj.v = (parseInt(obj.offsetHeight)/2)*-1;

 }

 obj.f2 = "menusub_rotulo";
 window.setTimeout(function(){ movimenta2(obj); } , delay);

}


function menusub_rotulo(pos){

 for(var i=3; i<=6; i++){

  var ob = document.getElementById('at_'+i);
  var normal = ob.getElementsByClassName('normal')[0];
  var over = ob.getElementsByClassName('over')[0];

  if(parseInt(pos)+152>parseInt(ob.offsetTop)){

   normal.style.display = "none"; over.style.display = "inherit";

  }else{

   normal.style.display = "inherit"; over.style.display = "none";

  }

 }

}


function subs(contato, atuacao){

 contato_vai(contato);
 atuacao_vai(atuacao);
 menusub_vai(0);


}


// Funções ligadas ao +info
function linka_copia(fecha){

 if(fecha){

  document.getElementById('linka_permalinkbox').style.visibility = 'hidden';

 }else{

  var minfo = document.getElementById('menu-info');
  document.getElementById('linka_permalinkbox').style.top = (parseInt(minfo.parentNode.offsetTop)+parseInt(minfo.offsetHeight)) + "px";
  document.getElementById('linka_permalinkbox').style.visibility = 'visible';
  document.getElementById('linka_permalink').value = permaurl;
  document.getElementById('linka_permalink').select();

 }

}


function linka_copiado(){

 clearTimeout(temporizador);
 document.getElementById('linka_permalinkcopiado').style.visibility = 'visible';
 temporizador = window.setTimeout("document.getElementById('linka_permalinkcopiado').style.visibility = 'hidden';", 3000);

}


function linka_maisinfo(vai){

 linkou_maisinfo = vai;

 var ob = document.getElementById('linka_maisinfo_article');

 document.getElementById('linka_maisinfo').foi = vai;

 if((vai && parseInt(ob.offsetWidth)<300) || (!vai && parseInt(ob.offsetWidth)>0)){

  ob.style.left = (parseInt(document.getElementById('projetos-nav').offsetWidth)) + "px";
  ob.p = "width";
  ob.q = "offsetWidth";
  ob.s = s_maisinfo_vai;

  if(vai){ ob.v = 300; menu_maisinfo_aberto = true; }
  else{ ob.v = 0; menu_maisinfo_aberto = false; }

  if(!zoom_foi){

   var tudo_in = document.getElementById('tudo-in-in-in');
   tudo_in.p = "left";
   tudo_in.q = "offsetLeft";
   tudo_in.s = s_maisinfo_vai;

   if(W>=1200){

    if(vai){ tudo_in.v = W-900; }
    else{ tudo_in.v = W-1200; }

   }else if(W>=900){

    if(vai){ tudo_in.v = W-600; }
    else{ tudo_in.v = W-900; }

   }else{
   
    if(vai){ tudo_in.v = 300; }
    else{ tudo_in.v = 0; }
   
   }

   movimenta(tudo_in);

  }else{

   zoom_movimenta(0);

  }

  var painelDireito = document.getElementById('painel-direito-in');
  painelDireito.p = "width";
  painelDireito.q = "offsetWidth";
  painelDireito.s = s_maisinfo_vai;

  if(W>=1200){

   if(vai){ painelDireito.v = 600; }
   else{ painelDireito.v = 900; }

  }else if(W>=900){

   if(vai){ painelDireito.v = 300; }
   else{ painelDireito.v = 900; }

  }else{

   if(vai){ painelDireito.v = 300; }
   else{ painelDireito.v = 900; }

  }
   
  movimenta(painelDireito);

  movimenta(ob);

 }

}


function mais_info(id, cat){

 var obj = document.getElementById('projetos-nav');
 obj.p = "top";
 obj.q = "offsetTop";
 obj.s = s_projetos_nav;

 var zi = document.getElementById('painel-direito-in-in');
 if(zi){ var zh = parseInt(zi.offsetHeight); }
 else{ var zh = 0; }
 if(zh>H){ var hh = zh; }
 else{ var hh = H; }

 obj.style.height = hh + "px";


 if(id){

  var idp = "&idpro="+id;
  window.setTimeout(function(){ ajaxHTML("projetos-titulo-header", "main_forms.php", "p=projeto_header&h="+H+"&w="+W+idp, "<p id='inner'>Carregando...</p>", "header_carregou()"); }, 500);
  window.setTimeout(function(){ ajaxHTML("linka_maisinfo_article_in", "main_forms.php", "p=projeto_info&h="+H+"&w="+W+idp, "Carregando...", ""); }, 500);

  permaurl = "www.kulturstudio.com/projetos.php?idpro="+id;

  titulo_rola('projetos-titulo-in', categorias[cat]);

  obj.v = 0;

 }else if(cat && cat!=1){

  titulo_rola('projetos-titulo-in', categorias[cat]);

  obj.v = 0;

  menu_maisinfo(true);

 }else{

  obj.v = hh*-1;

 }

 movimenta(obj);
 //titulo_rola('projetos-titulo-in', categorias[cat]);

}



// Funções ligadas ao zoom
function zoom_anda(ob){

 ob = ob.getElementsByTagName('a')[0];

 var op = ob.parentNode.className.split("_")[1];

 if(op=="avanca"){

  zoom_movimenta(1);

 }else if(op=="volta"){

  zoom_movimenta(-1);

 }else{

  zoom_vai(null);

 }

}


function zoom_libera(){

 if(zoom_foi==true){

  zoom_foi = false;
  if(celulas_requisitacao){

   window.setTimeout(function(){ celulas_carregou(celulas_requisitacao); celulas_requisitacao = ""; }, 1);

  }

 }

}


function zoom_legenda(vai){

 var ob = document.getElementById(zoom_ativo+"_aside");

 if(ob){

  if(vai) ob.style.visibility = "visible";
  else ob.style.visibility = "hidden";

 }

}


function zoom_movimenta(sentido){

 //iframes_reset();

 var obj = document.getElementById('painel-direito-in-in');

 obj.p = "left";
 obj.q = "offsetLeft";

 if(colunas==2) obj.s = s_zoom_vai1;
 else obj.s = s_zoom_vai2;

 var zoom_info = zoom_ativo.split("_");
 var zoom_next = document.getElementById(zoom_info[0]+"_"+(parseInt(zoom_info[1])+sentido));

 if(zoom_ativo && sentido){
 
   var zob = document.getElementById(zoom_ativo);
   if(zob){

    var frm = zob.getElementsByTagName('iframe')[0];
    if(frm){ var src = frm.src; window.setTimeout("iframe_reset('"+frm.id+"', '"+src+"');", 800); }

   }

 }
 
 if(zoom_next){

  var zoom_nav = document.getElementById('zoom_nav');
  var zimg = zoom_next.getElementsByTagName('img')[0];

  if(zimg){

   himg = parseInt(zimg.offsetHeight);
   wimg = parseInt(zimg.offsetWidth);

   if(zimg.className=="phantom_pix"){

    var frm = zoom_next.getElementsByTagName('iframe')[0];
    zoom_nav.style.top = (parseInt(zoom_next.getElementsByTagName('img')[0].offsetHeight)*0.4) + "px";
    zoom_nav.style.height = (parseInt(zoom_next.getElementsByTagName('img')[0].offsetHeight)*0.20) + "px";

   }else{

    zoom_nav.style.top = 18 + "px";
    zoom_nav.style.height = himg + "px";

   }

  }

  zoom_nav.onmouseover = function(){ zoom_legenda(true); }
  zoom_nav.onmouseout = function(){ zoom_legenda(false); }

  var zoom_proxima = document.getElementById(zoom_info[0]+"_"+(parseInt(zoom_info[1])+sentido+1));
  if(zoom_proxima){ changeOpac(100, null, 'zoom_avanca_link'); }
  else{ changeOpac(0, null, 'zoom_avanca_link'); }

  var zoom_anterior = document.getElementById(zoom_info[0]+"_"+(parseInt(zoom_info[1])+sentido-1));
  if(zoom_anterior){ changeOpac(100, null, 'zoom_volta_link'); }
  else{ changeOpac(0, null, 'zoom_volta_link'); }

  if(menu_maisinfo_aberto){
  
   if(colunas==2){

    if(wimg<600){

     obj.v = (parseInt(zoom_next.parentNode.offsetLeft)+150)*-1;
     zoom_nav.style.width = wimg + "px";
     zoom_nav.style.left = ((600-wimg)/2) + "px";

    }else{

     obj.v = parseInt(zoom_next.parentNode.offsetLeft)*-1;
     zoom_nav.style.width = 600 + "px";
     zoom_nav.style.left = 0;

    }
   
   }else{
   
    if(wimg<300){

     obj.v = (parseInt(zoom_next.parentNode.offsetLeft)*-1)+450;
     zoom_nav.style.width = wimg + "px";
     zoom_nav.style.left = ((300-wimg)/2) + "px";

    }else{

     obj.v = (parseInt(zoom_next.parentNode.offsetLeft)+((900-wimg)/2))*-1;
     zoom_nav.style.width = 300 + "px";
     zoom_nav.style.left = 0;

    }
   
   }

  }else{
  
   if(colunas==2){
   
    if(wimg<900){

     obj.v = parseInt(zoom_next.parentNode.offsetLeft)*-1;
     zoom_nav.style.width = wimg + "px";
     zoom_nav.style.left = ((900-wimg)/2) + "px";

    }else{

     obj.v = parseInt(zoom_next.parentNode.offsetLeft)*-1;
     zoom_nav.style.width = 900 + "px";
     zoom_nav.style.left = 0;

    }

   }else{

    if(wimg<600){

     obj.v = (parseInt(zoom_next.parentNode.offsetLeft)-150)*-1;
     zoom_nav.style.width = wimg + "px";
     zoom_nav.style.left = 300+((600-wimg)/2) + "px";

    }else{

     obj.v = (parseInt(zoom_next.parentNode.offsetLeft)*-1)+300;
     zoom_nav.style.width = 600 + "px";
     zoom_nav.style.left = 300 + "px";

    }

   }
    
  }

  zoom_ativo = zoom_next.id;
  movimenta(obj);

 }

}


function zoom_vai(ob){

 obj = document.getElementById('tudo-in-in-in');

 obj.p = "left";
 obj.q = "offsetLeft";
 obj.s = s_zoom_vai;

 if(ob){

  if(W>=1200) obj.v = W-2100;
  else if(W>=900) obj.v = W-1500;
  else obj.v = -600;
 
  zoom_foi = true; obj.f = "";

  var zoomcell = document.getElementById(ob.parentNode.id.replace('c', 'z'));

  zoom_ativo = zoomcell.getElementsByTagName('article')[0].id;
  var zoom_info = zoom_ativo.split("_");

  var zoom_nav = document.getElementById('zoom_nav');
  var zimg = zoomcell.getElementsByTagName('img')[0];
  if(zimg){ var wimg = parseInt(zimg.offsetWidth); var himg=parseInt(zoomcell.getElementsByTagName('img')[0].offsetHeight); }
  else{ var wimg = 900; var himg = 506; }

  var obj2 = document.getElementById('painel-direito-in-in');

  if(obj2){

   if(menu_maisinfo_aberto){

    if(colunas==2){
    
     if(wimg<600){

      obj2.style.left = ((parseInt(zoomcell.offsetLeft)+150)*-1) + "px";
      zoom_nav.style.width = wimg + "px";
      zoom_nav.style.left = ((600-wimg)/2) + "px";

     }else{

      zoom_nav.style.width = 600 + "px";
      zoom_nav.style.left = 0;
      obj2.style.left = (parseInt(zoomcell.offsetLeft)*-1) + "px";

     }
     
    }else{
    
     if(wimg<300){

      obj2.style.left = ((parseInt(zoomcell.offsetLeft)+75)*-1) + "px";
      zoom_nav.style.width = wimg + "px";
      zoom_nav.style.left = ((300-wimg)/2) + "px";

     }else{

      zoom_nav.style.width = 300 + "px";
      zoom_nav.style.left = 0;
      obj2.style.left = ((parseInt(zoomcell.offsetLeft)+((900-wimg)/2))*-1) + "px";

     }
    
    }

   }else{

    if(colunas==2){

     if(wimg<900){

      obj2.style.left = (parseInt(zoomcell.offsetLeft)*-1) + "px";
      zoom_nav.style.width = wimg + "px";
      zoom_nav.style.left = ((900-wimg)/2) + "px";

     }else{

      zoom_nav.style.width = 900 + "px";
      zoom_nav.style.left = 0;
      obj2.style.left = (parseInt(zoomcell.offsetLeft)*-1) + "px";

     }

    }else{

     if(wimg<600){

      obj2.style.left = ((parseInt(zoomcell.offsetLeft)-150)*-1) + "px";
      zoom_nav.style.width = wimg + "px";
      zoom_nav.style.left = 300+((600-wimg)/2) + "px";

     }else{

      zoom_nav.style.width = 600 + "px";
      zoom_nav.style.left = 300 + "px";
      obj2.style.left = ((parseInt(zoomcell.offsetLeft)*-1)+300) + "px";

     }

    }

   }

  }


  if(zimg.className=="phantom_pix"){

   zoom_nav.style.top = (parseInt(zoomcell.getElementsByTagName('img')[0].offsetHeight)*0.4) + "px";
   zoom_nav.style.height = (parseInt(zoomcell.getElementsByTagName('img')[0].offsetHeight)*0.2) + "px";

  }else{

   zoom_nav.style.top = 18 + "px";
   zoom_nav.style.height = himg + "px";

  }
  zoom_nav.onmouseover = function(){ zoom_legenda(true); }
  zoom_nav.onmouseout = function(){ zoom_legenda(false); }

  var zoom_proxima = document.getElementById(zoom_info[0]+"_"+(parseInt(zoom_info[1])+1));
  if(zoom_proxima){ changeOpac(100, null, 'zoom_avanca_link'); }
  else{ changeOpac(0, null, 'zoom_avanca_link'); }

  var zoom_anterior = document.getElementById(zoom_info[0]+"_"+(parseInt(zoom_info[1])-1));
  if(zoom_anterior){ changeOpac(100, null, 'zoom_volta_link'); }
  else{ changeOpac(0, null, 'zoom_volta_link'); }

  if(zoom_anterior || zoom_proxima){ changeOpac(100, null, 'zoom_fecha_link'); }
  else{ changeOpac(0, null, 'zoom_fecha_link'); }

  /*
  if(menu_maisinfo_aberto){

   if(wimg<600){

    zoom_nav.style.left = ((600-wimg)/2) + "px";

   }else{

    zoom_nav.style.width = 600 + "px";
    zoom_nav.style.left = 0;

   }

  }else{

   if(zimg){ zoom_nav.style.left = parseInt(zimg.offsetLeft) + "px"; }
   else{ zoom_nav.style.left = "0"; }

  }

  */
 }else{

  if(zoom_ativo){
  
   var zob = document.getElementById(zoom_ativo);
   if(zob){
   
    var frm = zob.getElementsByTagName('iframe')[0];
    if(frm){ var src = frm.src; window.setTimeout("iframe_reset('"+frm.id+"', '"+src+"');", 800); }
   
   }
   
  }
  
  if(menu_maisinfo_aberto){
  
   if(W>=1200) obj.v = W-900;
   else if(W>=900) obj.v = W-600;
   else obj.v = 300;
  
  }else{
  
   if(W>=1200) obj.v = W-1200;
   else if(W>=900) obj.v = W-900;
   else obj.v = 0;
  
  }

  obj.f = "zoom_libera()";

 }

 movimenta(obj);

}


// Funções  ligadas aos vídeos
function iframe_reset(id, sc){

 var ob = document.getElementById(id);
 if(ob) ob.src= sc;
 
 window.setTimeout("document.getElementById('tudo').focus();", 1);

}

function iframe_reset2(){

 window.setTimeout("document.getElementById('tudo').focus();", 5000);

}


function iframes_reset(){

 var frames = document.getElementsByTagName('iframe');
 for(var i=0; i<frames.length; i++){

  frames[i].style.visibility = "hidden";

  var src = frames[i].src;
  frames[i].src = src;

  window.setTimeout("document.getElementById('"+frames[i].id+"').style.visibility = 'visible';", 1000);

 }

}


// Funções ligadas aos títulos
function titulo_rola(alvo, titul){

 titulo = document.getElementById(alvo+'-'+titul);
 alvo = document.getElementById(alvo);

 if(alvo && titulo){

  alvo.p = "left";
  alvo.q = "offsetLeft";
  alvo.s = s_titulo_rola;
  alvo.v = 1-parseInt(titulo.offsetLeft);

  movimenta(alvo);

  alvo2 = alvo.parentNode;
  alvo2.p = "width";
  alvo2.q = "offsetWidth";
  alvo2.s = s_titulo_rola;
  alvo2.v = parseInt(titulo.offsetWidth)+1;

  movimenta(alvo2);

 }

}


function titulo_troca(alvo, titulo, alter){

 var alv = document.getElementById(alvo);
 var oldsrc = alv.src.split("/");
 var newsrc = "";
 for(var i=0; i<oldsrc.length-1; i++){ newsrc+= oldsrc[i]+"/"; }

 alv.src = newsrc+titulo+".png";
 alv.alt = alter;

}


// Funções extras
function permalink(titulo, url){

 var stateObj = { pL:"" };
 history.pushState(stateObj, titulo, url);

}


// Funções ligadas ao contato
function contato_carregando(mostra){

 var load = document.getElementById('li_form_load');

 if(mostra){ load.style.display = 'inherit'; }
 else{ load.style.display = 'none'; }

}


function contato_manda(){

 contato_movimenta(true);

}


function contato_mandou(){

 if(retorno=="ok"){

  document.getElementById('contato_foi').style.display = 'inherit';
  document.getElementById('contato_err').style.display = 'none';

 }else{

  document.getElementById('contato_foi').style.display = 'none';
  document.getElementById('contato_err').style.display = 'inherit';

 }

 contato_carregando(false);
 contato_retorno_movimenta(true);

}


function contato_movimenta(vai){

 var ob = document.getElementById('li_form_direita');
 ob.p = "top";
 ob.q = "offsetTop";
 ob.s = s_contato_movimenta;

 if(vai){

   ob.v = (parseInt(ob.offsetHeight)+200)*-1;
   ob.f = "contato_carregando(true);"

 }else{

  ob.v = -2;
  ob.f = "contato_carregando(false);";

 }

 movimenta(ob);

}


function contato_retorna(limpa){

 if(limpa){

  var campos = document.getElementById('li_form_in_form').getElementsByClassName('campo');
  for(var c=0; c<campos.length; c++){ campos[c].value = ""; }

 }

 contato_retorno_movimenta(false);
 contato_movimenta(false);

}


function contato_retorno_movimenta(vai){

 var ob = document.getElementById('li_form_retorno');
 ob.p = "top";
 ob.q = "offsetTop";
 ob.s = s_contato_movimenta;

 if(vai){

  ob.v = 0;

 }else{

  ob.v = parseInt(ob.offsetHeight)*-1;

 }

 movimenta(ob);

}


function contato_vai(volta){

 document.getElementById('li_form').style.width = (parseInt(document.getElementById('li_1').offsetLeft)+parseInt(document.getElementById('li_1').offsetWidth)) + "px";

 ob = document.getElementById('li_form_in');

 ob.p = "top";
 ob.q = "offsetTop";
 ob.s = s_contato_vai;

 contato_fechado = volta;

 if(volta){

  ob.v = -240;

 }else{

  ob.v = -1;
  contato_movimenta(false);
  contato_retorno_movimenta(false);

 }

 movimenta(ob);

}


// Funções movidas por teclas
function tecla(oEvent){

 var oEvent = (oEvent) ? oEvent : event;
 var oTarget =(oEvent.target) ? oEvent.target : oEvent.srcElement;
 if(oEvent.ctrlKey && oEvent.keyCode==67 && permafoco){ linka_copiado(true); linka_copia(true); }
 else if(oEvent.ctrlKey && oEvent.keyCode==88 && permafoco){ linka_copiado(true); linka_copia(true); }
 else if(oEvent.keyCode==27 && permafoco){ linka_copia(true); }
 if(oEvent.metaKey && oEvent.keyCode==67 && permafoco){ linka_copiado(true); window.setTimeout(function(){ linka_copia(true); }, 100); }
 else if(oEvent.metaKey && oEvent.keyCode==88 && permafoco){ linka_copiado(true); window.setTimeout(function(){ linka_copia(true); }, 100); }
 else if(oEvent.ctrlKey ||  oEvent.metaKey) controlPress = true;

}


function tecla2(event){

 controlPress = false;

}


document.onkeydown = tecla;
document.onkeyup = tecla2;


// Funções ligadas ao painel esquerdo
function sobre(){

 ob1 = document.getElementById("painel-esquerdo");
 ob1.p = "left";
 ob1.q = "offsetLeft";
 ob1.s = s_sobre;
 ob1.v = 0;
 ob1.f = "painel_esquerdo_abre('1');";
 if(ob1.aberto!=1){ document.getElementById('painel-esquerdo-in').style.top = (H*-1) + "px"; }
 movimenta(ob1);

 var fechas = document.getElementsByClassName('sobre-btfechar');
 for(var i=0; i<fechas.length; i++){

  fechas[i].style.marginTop = (22-fechas[i].offsetHeight) + "px";

 }

 sobreAberto = true;
 
 posicionamentos();

}


function sobre_carrega(){

 sobre_carregou = true;
 ajaxHTML("painel-esquerdo-in", "main_forms.php", "p=sobre&h="+H+"&w="+W, "Carregando...", "painel_esquerdo_carregou()");

}


function painel_esquerdo_abre(abriu){ // Função executada quando o painel termina de abrir ou fechar

 var ob = document.getElementById('painel-esquerdo');

 // Funções específicas de cada caso(página)
 if(ob.aberto!=1){

  var obj = document.getElementById('painel-esquerdo-in');
  obj.p = "top";
  obj.q = "offsetTop";
  obj.s = s_sobre_desce;
  obj.v = 0;
  movimenta(obj);

 }

 // Determina se o painel foi aberto ou fechado
 ob.aberto = abriu;

}


function painel_esquerdo_carregou(){

 document.getElementById('sobre-conteudo').style.overflow = "hidden";

 var aS = document.getElementById('sobre-nav').getElementsByTagName('a');
 for(var i=0; i<aS.length; i++){

  aS[i].vId = aS[i].id.split("_")[1];
  aS[i].onclick = function(){ painel_rola_vertical('sobre-'+this.vId); titulo_rola('sobre-titulo-in', this.vId); return false; }

 }

 var fS = document.getElementsByClassName('sobre-fechar');
 for(var i=0; i<fS.length; i++){

  fS[i].style.display = "inherit";
  fS[i].onclick = function(){ linka(null, null, null); }

 }

 var fechas = document.getElementsByClassName('sobre-btfechar');
 for(var i=0; i<fechas.length; i++){

  fechas[i].style.display = "inherit";
  fechas[i].onclick = function(){ painel_esquerdo_fecha(); }

 }

}


function painel_esquerdo_fecha(){

 ob1 = document.getElementById("painel-esquerdo");
 ob1.p = "left";
 ob1.q = "offsetLeft";
 ob1.s = s_sobre;
 ob1.v = parseInt(ob1.offsetWidth)*-2;
 ob1.f = "painel_esquerdo_abre('1');";
 movimenta(ob1);

 sobreAberto = false;

}


function painel_rola_vertical(id){

 var ob = document.getElementById(id);
 
 sobreRolou = id;

 if(ob){

  var obj = ob.parentNode;
  obj.p = "top";
  obj.q = "offsetTop";
  obj.s = s_sobre_desce;
  obj.v = parseInt(ob.offsetTop)*-1;

  movimenta(obj);

 }

}

