//Exibição dos menus drop-down do site
var delay = false;
function dropDownMenus(id){
	menuNoticiasDropDown();
	menuOSistemaDropDown();
	menuSocialDropDown(id);
}

function menuSocialDropDown(id){
	var drop = document.getElementById("dropdownsocial");
	if(!drop)
		return false;
		//Chegando aqui prossigo sem problemas
	//Crio os submenus
	var ul = document.createElement("ul");
	var nomes = new Array("Aline Viezzer");
	var links = new Array("http://www.alineviezzer.com.br/gerenciador/newsletter.php?numero="+id);

	for(var i = 0; i < nomes.length; i++){
		var li = document.createElement("li");
		var a = document.createElement("a");

		a.setAttribute("href", links[i]);
		a.setAttribute("target","_blank")
		a.appendChild(document.createTextNode(nomes[i]));
		li.appendChild(a);
		ul.appendChild(li);
	}

	ul.style.display = "none";
	drop.appendChild(ul);

	drop.onmouseover = function(){
		//Esconde todos os submenus abertos
		escondeTodos();

		if(delay)
			clearTimeout(delay);

		var drop = document.getElementById("dropdownsocial");
		var submenu = drop.getElementsByTagName("ul");
		submenu = submenu[0];

		submenu.style.display = "";
	}

	drop.onmouseout = function(){
		var drop = document.getElementById("dropdownsocial");
		var submenu = drop.getElementsByTagName("ul");
		submenu = submenu[0];

		delay = setTimeout("delaySocial()", 1000);
	}
}
function delaySocial(){
	var drop = document.getElementById("dropdownsocial");
	var submenu = drop.getElementsByTagName("ul");
	submenu = submenu[0];

	submenu.style.display = "none";
}

//Menu de notícias ----------------
function menuNoticiasDropDown(){
	var drop = document.getElementById("dropdownnoticias");

	if(!drop)
		return false;

	//Chegando aqui prossigo sem problemas
	//Vou carregar os dados com ajax, de um XML, e criar os submenus
	getNoticiasSubMenu(drop);

	drop.onmouseover = function(){
		//Esconde todos os submenus abertos
		escondeTodos();

		if(delay)
			clearTimeout(delay);

		var drop = document.getElementById("dropdownnoticias");
		var submenu = drop.getElementsByTagName("ul");
		submenu = submenu[0];

		submenu.style.display = "";
	}

	drop.onmouseout = function(){
		var drop = document.getElementById("dropdownnoticias");
		var submenu = drop.getElementsByTagName("ul");
		submenu = submenu[0];

		delay = setTimeout("delayNoticias()", 1000);
	}
}

//Esconde o elemento passado
function delayNoticias(){
	var drop = document.getElementById("dropdownnoticias");
	var submenu = drop.getElementsByTagName("ul");
	submenu = submenu[0];

	submenu.style.display = "none";
}

//Menu de notícias ------


//Menu de O Sistema ----------------
function menuOSistemaDropDown(){
	var drop = document.getElementById("dropdownosistema");

	if(!drop)
		return false;

	//Chegando aqui prossigo sem problemas
	//Crio os submenus
	var ul = document.createElement("ul");
	var nomes = new Array("Apresentação", "Vantagens", "Locais com Expositor", "Produto Legalizado", "Modelos de Cartões");
	var links = new Array("./?O-Sistema/Apresentacao", "./?O-Sistema/Vantagens", "./?O-Sistema/Locais-com-expositor", "./?O-Sistema/Produto-Legalizado", "./?O-Sistema/Modelos-de-Cartoes");

	for(var i = 0; i < nomes.length; i++){
		var li = document.createElement("li");
		var a = document.createElement("a");

		a.setAttribute("href", links[i]);
		a.appendChild(document.createTextNode(nomes[i]));
		li.appendChild(a);
		ul.appendChild(li);
	}

	ul.style.display = "none";
	drop.appendChild(ul);

	drop.onmouseover = function(){
		//Esconde todos os submenus abertos
		escondeTodos();

		if(delay)
			clearTimeout(delay);

		var drop = document.getElementById("dropdownosistema");
		var submenu = drop.getElementsByTagName("ul");
		submenu = submenu[0];

		submenu.style.display = "";
	}

	drop.onmouseout = function(){
		var drop = document.getElementById("dropdownosistema");
		var submenu = drop.getElementsByTagName("ul");
		submenu = submenu[0];

		delay = setTimeout("delayOSistema()", 1000);
	}
}

function delayOSistema(){
	var drop = document.getElementById("dropdownosistema");
	var submenu = drop.getElementsByTagName("ul");
	submenu = submenu[0];

	submenu.style.display = "none";
}

//Menu de notícias ------


function escondeTodos(){
	var menu = document.getElementById("menuprincipal");
	var submenus = menu.getElementsByTagName("ul");

	for(var i = 0; i < submenus.length; i++){
		submenus[i].style.display = "none";
	}
}


//Retorna os dados para o submenu de notícias
function getNoticiasSubMenu(drop){
	var ajax = ajaxInit();

	if(ajax){
		ajax.open("GET", "./_xml/CategoriasNoticias.php", true);

		ajax.onreadystatechange = function(){
			if(ajax.readyState == 4) {
				if(ajax.status == 200){
					var result = ajax.responseXML;
					var retorno = result.getElementsByTagName("categoria");
					//return retorno;

					var ul = document.createElement("ul");
					for(var i = 0; i < retorno.length; i++){
						//alert(retorno[i].getAttribute("nome"));
						var li = document.createElement("li");
						var a = document.createElement("a");

						a.setAttribute("href", retorno[i].getAttribute("link"));
						a.appendChild(document.createTextNode(retorno[i].getAttribute("nome")));
						li.appendChild(a);
						ul.appendChild(li);
					}

					ul.style.display = "none";
					drop.appendChild(ul);
				}
				else{
					alert(ajax.statusText);
				}
			}
		}
		ajax.send(null);
		return;
	}
}