window.onload = function() {
	var items = document.getElementById("menu").getElementsByTagName("li");

	for (var i=0; i < items.length; i++) {
		(function() {
			var self = i;
		
			items[i].onmouseover = function() {
				var menu = document.getElementById("menu").getElementsByTagName("li");
				
				for (var k=0; k < menu.length; k++) {
					menu[k].getElementsByTagName('img')[0].style.display = 'inline';
				}
				
				this.getElementsByTagName('img')[0].style.display = 'none';
				
				var div = document.getElementById("submenu").getElementsByTagName("div");
				
				for (var j=0; j < div.length; j++) {
					div[j].style.display = "none";
				}

				div[self].style.display = "";			
			}
		})();
	}

	var items = document.getElementById("submenu").getElementsByTagName("div");

	for (var i=0; i < items.length; i++) {
		(function() {
			var timer = 0;
		
			items[i].onmouseover = function() {
				var a = this.getElementsByTagName("*");
				
				for (var j=0; j < a.length; a++)
					a.onmouseover = function() {
						window.clearTimeout(timer);
					}
					
				window.clearTimeout(timer);
			}
			
			items[i].onmouseout = function() {
				var self = this;
				
				timer = window.setTimeout(function() {
					self.style.display = "none";
					
					var menu = document.getElementById("menu").getElementsByTagName("li");
					for (var k=0; k < menu.length; k++) {
						menu[k].getElementsByTagName('img')[0].style.display = 'inline';
					}
				}, 500);
			}
		})();
	}
	
	var balls = [document.getElementById("ser"), document.getElementById("pensar"), document.getElementById("fazer")];
	var t1 = []; // Open
	var t2 = [];
	var t3 = [];

	for (var i=0; i < balls.length; i++) {
		(function() {
			var ball = balls[i];
			var n = i;
			
			ball.onmouseover = function() {
				if (t3[n]) {
					window.clearTimeout(t3[n]);
				}
				
				switch (this.id) {
					case 'ser': sze = 305; break;
					default: sze = 257; break;
				}
				
				Animation.start(this, t1[n], sze);
			}
			
			ball.onmouseout = function() {
				var self = this;
			
				t3[n] = window.setTimeout(function() {
					Animation.end(self, t2[n])
				}, 200);
			}
		
		})();
	}
}

var Animation = {	
	start: function(a, b, c) {
		var self = a;
		self.style.zIndex = 6;
	
		b = window.setInterval(function() {
			if ((width = parseInt(self.style.width.replace("px", "")) + 10) > c) {
				window.clearTimeout(b);
				self.getElementsByTagName("h2")[0].getElementsByTagName("a")[0].className = "in";
				self.getElementsByTagName("div")[2].style.display = "block";
				return;
			}
		
			self.style.width = width + "px";
			self.style.left = parseInt(self.style.left.replace("px", "")) - 5 + "px";
			
			self.style.height = parseInt(self.style.height.replace("px", "")) + 10 + "px";
			self.style.top = parseInt(self.style.top.replace("px", "")) - 5 + "px";
		}, 10);
	},
	
	end: function(a, b) {
		var self = a;
		self.style.zIndex = 5;
			
		b = window.setInterval(function() {
			if ((width = parseInt(self.style.width.replace("px", "")) - 10) < 114) {
				window.clearTimeout(b);
				return;
			}
		
			self.getElementsByTagName("div")[2].style.display = "none";
			self.getElementsByTagName("h2")[0].getElementsByTagName("a")[0].className = "";
		
			self.style.width = width + "px";
			self.style.left = parseInt(self.style.left.replace("px", "")) + 5 + "px";
			
			self.style.height = parseInt(self.style.height.replace("px", "")) - 10 + "px";
			self.style.top = parseInt(self.style.top.replace("px", "")) + 5 + "px";
			
		}, 10);
	}
};

function pop_img(url) {
	window.open(url, '', 'status=0,toolbar=0,location=0,menubar=0,directories=0,width=500,height=400');
}

var tooltip = {
	//alert("Alerta");
	
/*Exemplo*/
/*
if (document.all){}
else document.captureEvents(Event.CLICK);
document.onclick=mouse;
*/
/*Exemplo*/
	start: function(a) {

		var td = a.getElementsByTagName('td');
		
		for (var i=0; i < td.length; i++) {
			td[i].onmouseover = function() {
				tooltip.remove();
				valordlargura = event.x; /*Cria a variável de largura*/
				valordaltura = event.y; /*Cria a variável de altura*/
				
				/*Exemplo pego na internet*/
				/*
				if (document.all){}
				else document.captureEvents(Event.CLICK);
				document.onclick=mouse;
				*/
				
				
				/*
				//function mouse(e) {
						if (navigator.appName == 'Netscape'){
								valordlargura = event.pageX;
								valordaltura = event.pageY;
						} else {
								valordlargura = event.clientX;
								valordaltura = event.clientY;
						}
						//alert("x:"+xcurs+" y:"+ycurs);
						
						*/
				//}
				/*Fim do exemplo*/


				if ((div = this.getElementsByTagName('div')) && div.length > 0)
					tooltip.display(div[0].innerHTML);
				else
					tooltip.remove();
			}
		}
	},
	
	display: function(txt) {
		if (!(tip = document.getElementById('__tip'))) {
			var tip = document.createElement('div');
			tip.id = '__tip';
			tip.innerHTML += '<span><a href="#" onclick="tooltip.remove()">Fechar</a></span><div></div>';
			
			/*
			valorx = event.x;	
			valory = event.y;
			*/
			tip.style.left += valordlargura + 'px';
			tip.style.top += valordaltura + 'px';
			
			document.getElementsByTagName('body')[0].appendChild(tip);
		}
		
		tip.childNodes[1].innerHTML = txt;
	},
	
	remove: function() {
		if (tip = document.getElementById('__tip'))
			document.getElementsByTagName('body')[0].removeChild(tip);
	}
}
/*Exemplo*/
//}
/*Exemplo*/
function submitform()
{
  document.myform.submit();
}
/*Abre janela pop-up*/
var win = null;
function NovaJanela(pagina,nome,w,h,scroll){
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
	win = window.open(pagina,nome,settings);
}

/*Abre e fecha a DIV*/
		function showdiv(ativar,id1,id2)    	 
		{								 
			var A=document.getElementById(id1);
			var B=document.getElementById(id2);
			if(ativar=='sim')
			{
				B.style.display = 'block';
				A.style.display= 'none';
			}
			else
			{
				A.style.display = 'block';
				B.style.display= 'none';
			}
		}
		
/*Abre e fecha a DIV*/
function mostrar(nomeCamada){
document.getElementById(nomeCamada).style.display="block";
}
function ocultar(nomeCamada){
document.getElementById(nomeCamada).style.display="none";
}

/*Força o CEP a ter só numero*/
function Numero(e)
{
navegador = /msie/i.test(navigator.userAgent);
if (navegador)
var tecla = event.keyCode;
else
var tecla = e.which;

if(tecla > 47 && tecla < 58) // numeros de 0 a 9
return true;
else
{
if (tecla != 8) // backspace
return false;
else
return true;
}
}

/* No Form de visita, tira a data para o 6 e 7 ano */
function trocadata(){
//valor = "Texto";
var valornum = document.agendevisita.serie.selectedIndex
var valorvalue = document.agendevisita.serie.options[valornum].value
var valor = document.agendevisita.serie.options[valornum].text
	
	var sDiv = document.getElementById("botao");	
	if (valorvalue=='7º ano A  (lista de espera)' || valorvalue=='6º ano (lista de espera)') {
		  sDiv.style.display = "none"; 
		  //alert("Esconde");
	}else{
		  sDiv.style.display = "block";       
		  //alert("Mostra");
	}
	
	var sDiv = document.getElementById("botaoesc");	
	if (valorvalue=='7º ano A  (lista de espera)' || valorvalue=='6º ano (lista de espera)') {
		  sDiv.style.display = "block"; 
		  //document.getElementById("campo3").checked = !campo3.checked; 
		  //alert("Mostra");
	}else{
		  sDiv.style.display = "none";       
		  document.getElementById("campo3").disabled = !campo3.disabled; 
		  //alert("Esconde");
	}
	
return false;
}
