// VARIÁVEIS GLOBAIS
var offsetX=0;
var offsetY=0;
var redimensionado=0;
var opcao=0;
var leftX=0;
var rightX=0;
var topY=0;
var bottomY=0;
var submenu;
var styleleft;
var styletop;
var subwidth;
var subheight;
var menu;
var objeto;
var objeto2;
var aux=13;

// INÍCIO DO SCRIPT DE MENU

// testes para navegador
if(document.all) {
	ns = 0;
	ie = 1;
	fShow="visible";
	fHide="hidden";
} else if(document.getElementById) {
	ns = 1;
	ie = 0;
	fShow="visible";
	fHide="hidden";
}

if(!window.event && window.captureEvents) {
	// set up event capturing for mouse events (add or subtract as desired)
	window.captureEvents(Event.MOUSEOVER|Event.MOUSEOUT|Event.CLICK|Event.DBLCLICK|Event.ONSCROLL);
	// set window event handlers (add or subtract as desired)
	window.onmouseover = WM_getCursorHandler;
	window.onmouseout = WM_getCursorHandler;
	window.onclick = WM_getCursorHandler;
	window.ondblclick = WM_getCursorHandler;
	window.onscroll = calcularoffset;
	// create an object to store the event properties 
	window.event = new Object;
}

function WM_getCursorHandler(e) {
	// set event properties to global vars (add or subtract as desired)
	window.event.clientX = e.pageX;
	window.event.clientY = e.pageY;
	window.event.x = e.layerX;
	window.event.y = e.layerY;
	window.event.screenX = e.screenX;
	window.event.screenY = e.screenY;
	// route the event back to the intended function
	if ( routeEvent(e) == false ) {
		return false;
	} else {
		return true;
	}
}

// primeira parte, função que passa os parâmetros do submenu escolhido
// para a segunda parte
function mostramenu(opcao) {
	if(opcao==1) {  // submenu pesquisa
		hideAll();
		submenu = "pesquisa";
		menu = "menu_pesquisa";
		subwidth = 200;
		subheight = 47;
		styleleft = 80;
		styletop = 125;
		mostramenu2();
		opcao = 1;
	} else if(opcao==2) {  // submenu pós-graduação
		hideAll();
		submenu = "posgraduacao";
		menu = "menu_posgrad";
		subwidth = 200;
		subheight = 79;
		styleleft = 125;
		styletop = 150;
		mostramenu2();
		opcao = 2;
	} else if(opcao==3) {  // submenu graduação
		hideAll();
		submenu = "graduacao";
		menu = "menu_grad";
		subwidth = 210;
		subheight = 160;
		styleleft = 101;
		styletop = 175;
		mostramenu2();
		opcao = 3;
	} else if(opcao==4) {  // submenu cultura & extensão
		hideAll();
		submenu = "cultura";
		menu = "menu_cultura";
		subwidth = 150;
		subheight = 108;
		styleleft = 150;
		styletop = 200;
		mostramenu2();
		opcao = 4;
	}
}

// segunda parte, função que mostra o menu, dados os parâmetros
function mostramenu2() {
	if(ie==1) {
		document.all[submenu].style.top = parseInt(styletop)+"px";
		document.all[submenu].style.left = parseInt(styleleft)+"px";
		document.all[submenu].style.visibility = fShow;
		document.all[menu].style.color = "#CC8800";
	} else {
		document.getElementById(submenu).style.top = parseInt(styletop+aux)+"px";
		document.getElementById(submenu).style.left = styleleft+"px";
		document.getElementById(submenu).style.visibility = fShow;
		document.getElementById(menu).style.color = "#CC8800";
	}
	rightX = styleleft+subwidth;
	leftX = 8;
	topY = styletop;
	bottomY = subheight+styletop;
	if(ns==1) {
		topY = topY - aux;
		bottomY = bottomY + aux;
	}
}

// função que faz update nos menus, escondendo caso o mouse esteja fora
// de posição do menu
function updateIt() {
	var x = window.event.clientX + offsetX;
	var y = window.event.clientY + offsetY;
	if(x > rightX || x < leftX) {
		hideAll();
	}
	if(y < topY || y > bottomY) {
		hideAll();
	}
}

// função que atualiza valores de x e y para rolagem (offSet)
function calcularoffset() {
	if(ie==1) {
		offsetX = document.body.scrollLeft;
		offsetY = document.body.scrollTop;
	}
}

// função que esconde todos os submenus e reinicializa as variáveis de
// controle de posição, caso seja necessário
function hideAll() {
	objeto = "pesquisa";
	objeto2 = "menu_pesquisa";
	hideAll2();
	objeto = "posgraduacao";
	objeto2 = "menu_posgrad";
	hideAll2();
	objeto = "graduacao";
	objeto2 = "menu_grad";
	hideAll2();
	objeto = "cultura";
	objeto2 = "menu_cultura";
	hideAll2();
	objeto = "material";
	objeto2 = "menu_material";
	hideAll2();
}

// função complementar da anterior
function hideAll2() {
	if(ns==1) {
		if(document.getElementById(objeto) && document.getElementById(objeto2)) {
			document.getElementById(objeto).style.visibility = fHide;
			document.getElementById(objeto2).style.color = "#000000";
			if(opcao!=0) {
				rightX = 0;
				leftX = 0;
				topY = 0;
				bottomY = 0;
			}
		}
	} else {
		if(document.all[objeto] && document.all[objeto2]) {
			document.all[objeto].style.visibility = fHide;
			document.all[objeto2].style.color = "#000000";
			if(opcao!=0) {
				rightX = 0;
				leftX = 0;
				topY = 0;
				bottomY = 0;
			}
		}
	}
}

// FIM DO SCRIPT DE MENU

// função que recarrega a página com o grupo de pesquisa escolhido na lista
function mudargrupopes() {
	top.location.href = "pesquisa_grupos.php?id="+parent.document.getElementById("grupos").options[parent.document.getElementById("grupos").selectedIndex].value;
}

// função que recarrega a página com o grupo de pós-graduação escolhido na lista
function mudargrupopos() {
	top.location.href = "posgrad_grupos.php?id="+parent.document.getElementById("grupos").options[parent.document.getElementById("grupos").selectedIndex].value;
}

// mostrar o iframe de detalhes
function mostrariframe(i,j,k) {
	if(ie==1) {
		document.getElementById("idframe").style.width = parseInt(document.body.clientWidth * 0.95 - 153)+"px";
		document.getElementById("idframe").style.left = parseInt((document.body.clientWidth * 0.05)/2 + 153)+"px";
		if(offsetY == 0) {
			document.getElementById("idframe").style.height = parseInt(document.body.clientHeight * 0.95 - 125)+"px";
			document.getElementById("idframe").style.top = parseInt((document.body.clientHeight * 0.05)/2 + 125)+"px";
		} else {
			document.getElementById("idframe").style.top = parseInt((document.body.clientHeight * 0.05)/2 + offsetY)+"px";
			document.getElementById("idframe").style.height = parseInt(document.body.clientHeight * 0.95)+"px";
		}
	} else {
		document.getElementById("idframe").style.width = parseInt(window.innerWidth * 0.95 - 153)+"px";
		document.getElementById("idframe").style.left = parseInt((window.innerWidth * 0.05)/2 + 153)+"px";
		if(window.pageYOffset == 0) {
			document.getElementById("idframe").style.height = parseInt(window.innerHeight * 0.91 - 125)+"px";
			document.getElementById("idframe").style.top = parseInt((window.innerWidth * 0.05)/2 + 125)+"px";
		} else {
			document.getElementById("idframe").style.height = parseInt(window.innerHeight * 0.91)+"px";
			document.getElementById("idframe").style.top = parseInt((window.innerWidth * 0.05)/2 + window.pageYOffset)+"px";
		}
	}
	if(j==1) {
		parent.idframe.location.href = "docentes_iframe_profs.php?id="+parseInt(i);
	} else if(j==2) {
		parent.idframe.location.href = "docentes_iframe_convidados.php?id="+parseInt(i);
	} else if(j==3) {
		parent.idframe.location.href = "tecnicos_iframe.php?id="+parseInt(i);
	} else if(j==4) {
		parent.idframe.location.href = "alunosgrad_iframe.php?id="+parseInt(i);
	} else if(j==5) {
		parent.idframe.location.href = "alunosgrad_iframe.php?id="+parseInt(i);
	} else if(j==6) {
		parent.idframe.location.href = "alunosposgrad_iframe.php?tipo="+parseInt(k)+"&id="+parseInt(i);
	}
	parent.document.getElementById("idframe").style.visibility = fShow;
}
