/*--------------------------------------------------------------------
JAVASCRIPT - Mani Menu, slide BG

Version: 	1.0 - 2007
author: 	Burocratik (alexandre gomes)
email: 		alex@burocratik.com
website: 	http://www.burocratik.com
-----------------------------------------------------------------------*/

/* =Funcao mover elemento
-----------------------------------------------------------------------*/
function moveElemento(elementID,fixo_x,inicial_y,final_y,interval) {
  if (!document.getElementById) return false;
  if (!document.getElementById(elementID)) return false;
  //
  var elem = document.getElementById(elementID);
  if (elem.movement) {
    clearTimeout(elem.movement);
  }
  //
  var ypos = inicial_y;
  if (ypos == final_y) {
    return true;
  }
  if (ypos < final_y) {
    ypos+=2;
  }
  if (ypos > final_y) {
    ypos--;
  }
  elem.style.backgroundPosition= fixo_x + "px" + " "+ ypos +"px";
  var inicial_y = ypos;
  //
  var aux = "moveElemento('"+elementID+"',"+fixo_x+","+inicial_y+","+final_y+","+interval+")";
  elem.movement = setTimeout(aux,interval);
}

/* =Interaccao
-----------------------------------------------------------------------*/
function preparaMenu() {
  if (!document.getElementsByTagName) return false;
  if (!document.getElementById) return false;
  if (!document.getElementById("navPrim")) return false;
// NOTA: vou buscar cada id aos botoes para quando estiver on, sem a nao kebrar 
  var links1 = document.getElementById("link1");
  var links2 = document.getElementById("link2");
  var links3 = document.getElementById("link3");
  var links4 = document.getElementById("link4");
// Comportamento dos Botoes: garantir k so &eacute; botao se tem o ID e tem o tag a
  if(links1.getElementsByTagName("a").length!=0){
  	links1.onmouseover = links1.onfocus = function() {
		moveElemento("link1",0,-33,0,5);
  	}
  	links1.onmouseout = links1.onblur = function() {
		moveElemento("link1",0,0,-33,5);
  	} 
  }
  //
  if(links2.getElementsByTagName("a").length!=0){
	  links2.onmouseover = links2.onfocus = function() {
		moveElemento("link2",-140,-33,0,5);
	  }
	  links2.onmouseout = links2.onblur = function() {
		moveElemento("link2",-140,0,-33,5);
	  }
  }
  //
  if(links3.getElementsByTagName("a").length!=0){
	  links3.onmouseover = links3.onfocus = function() {
		moveElemento("link3",-280,-33,0,5);
	  }
	  links3.onmouseout = links3.onblur = function() {
		moveElemento("link3",-280,0,-33,5);
	  }
  }
  //
  if(links4.getElementsByTagName("a").length!=0){
 	 links4.onmouseover = links4.onfocus = function() {
		moveElemento("link4",-420,-33,0,5);
	  }
	  links4.onmouseout = links4.onblur = function() {
		moveElemento("link4",-420,0,-33,5);
	  }    
   }
}


/* =CLIENTES: coloca-los todos fora do stage do on.load
-----------------------------------------------------------------------*/
var W3CDOM = (document.getElementsByTagName && document.createElement);
if (W3CDOM){
	var link = document.createElement('link');
	link.setAttribute("rel", "stylesheet");
	link.setAttribute("type", "text/css");
	link.setAttribute("href", "scripts/javascript-clientes.css");
	link.setAttribute("media", "screen");
	document.getElementsByTagName("head")[0].appendChild(link);
}

/* =Clientes: abrir e fechar das noticias
-----------------------------------------------------------------------*/
function fVisivelClientes(id) {
  var divs = document.getElementsByTagName("div");
  for (var i=0; i<divs.length; i++ ) {
    if (divs[i].className.indexOf("clientesForm") == -1) continue;
    if (divs[i].getAttribute("id") == id) {
		if (addClass("check",divs[i],"showClientesForm")){ //verifica se ja apliquei a class (isto e' se ja estava aberto)
			addClass("remove",divs[i],"showClientesForm"); //tira a class
		} else {
			addClass("add",divs[i],"showClientesForm"); //adiciona nova class, esta funcao esta em geral.js
		}	
    } else {
	  addClass("remove",divs[i],"showClientesForm"); //remove nova class, esta funcao esta em geral.js
    }
  }
}

function iniciarClientes() {
	if (!document.getElementsByTagName) return false;
	if (!document.getElementById) return false;
	var links = getElementsByClassName(document, "a", "clientes");
	for (var i=0; i<links.length; i++ ) {
   	var sectionId = links[i].getAttribute("href").split("#")[1];
    	if (!document.getElementById(sectionId)) continue;
			links[i].destination = sectionId;
    		links[i].onclick = function() {
      		fVisivelClientes(this.destination);
      		return false;
    	} 
	}
}




/* =Preparar Eventos
-----------------------------------------------------------------------*/
addLoadEvent(preparaMenu);
addLoadEvent(iniciarClientes);
