var menuList;
var pathList;
var iframe;
var path;
var init_path;
var selected_path;
var nosporca_path = "Nós, por cá";
var separator_path = " > ";

function loadPage()
{
	showDate();
	loadMenu();
	loadArray();
	loadIFrame();
	loadPath();
}

function showDate()
{
	var date, dateLabel;
	var dayNumber, dayWeek, month, year;
	
	date = new Date();
	
	dayNumber = date.getDate();
	dayWeek = date.getDay();
	month = date.getMonth();
	year = date.getYear();
	
	switch (dayWeek)
	{
		case 0: dateLabel = "Domingo";break;
		case 1: dateLabel = "Segunda-Feira";break;
		case 2: dateLabel = "Terça-Feira";break;
		case 3: dateLabel = "Quarta-Feira";break;
		case 4: dateLabel = "Quinta-Feira";break;
		case 5: dateLabel = "Sexta-Feira";break;
		case 6: dateLabel = "Sábado";break;
		
	}
	
	dateLabel = dateLabel + " - " + dayNumber + " de ";
	
	switch (month)
	{
		case 0: dateLabel = dateLabel + "Janeiro";break;
		case 1: dateLabel = dateLabel + "Fevereiro";break;
		case 2: dateLabel = dateLabel + "Março";break;
		case 3: dateLabel = dateLabel + "Abril";break;
		case 4: dateLabel = dateLabel + "Maio";break;
		case 5: dateLabel = dateLabel + "Junho";break;
		case 6: dateLabel = dateLabel + "Julho";break;
		case 7: dateLabel = dateLabel + "Agosto";break;
		case 8: dateLabel = dateLabel + "Setembro";break;
		case 9: dateLabel = dateLabel + "Outubro";break;
		case 10: dateLabel = dateLabel + "Novembro";break;
		case 11: dateLabel = dateLabel + "Dezembro";break;				
	}

	dateLabel = dateLabel + " de " + year;
	
	document.getElementById("date").innerHTML = dateLabel;
	
}

/*
function displayChild(parentID)
{
	var finish;
	var child, i;
	
	finish = false;
	i = 1;
	
	
	while (!finish)
	{
		child = document.getElementById(parentID + "_" + i);
		
		if (child == null)
		{
			finish = true;
		}
		else
		{
			//alert(child.currentStyle.getAttribute("visibility"));
			//alert(child.style.getAttribute("display"));
			//alert((child.style.getAttribute("visibility") == "hidden")?"visible":"hidden");
			//alert((child.style.getAttribute("display") == "none")?"inherit":"none");
			child.style.setAttribute("visibility", (child.style.getAttribute("visibility") == "hidden")?"visible":"hidden");
			child.style.setAttribute("display", (child.style.getAttribute("display") == "none")?"":"none");
			//child.currentStyle.visibility = (child.currentStyle.getAttribute("visibility") == "hidden")?"visible":"hidden";
			//child.currentStyle.display = (child.currentStyle.getAttribute("display") == "none")?"":"none";
			i++;
		}
	}
	//alert(parentID);
}
*/

function displayChild(parentID)
{
	var finish;
	var child, i;
	
	finish = false;
	i = 1;
	
	child = document.getElementById(parentID + "_0");
	
	if (child != null)
	{
		/*
		if (child.style.getAttribute("visibility") == "hidden")
		{
			child.style.setAttribute("visibility", "visible");
			
			if (iframe != null)
			{
				iframe.src = menuList[parentID];
			}
		}
		else
		{
			child.style.setAttribute("visibility", "hidden");
		}
		*/
		
		if (child.style.getAttribute("display") == "none")
		{
			child.style.setAttribute("display", "block");
			//selected_path = (init_path + pathList[parentID]);
			openUrl(parentID);
		}
		else
		{
			if (selected_path == (init_path + separator_path + pathList[parentID]))
			{
				child.style.setAttribute("display", "none");
			}
			else
			{
				//selected_path = (init_path + pathList[parentID]);
				openUrl(parentID);
			}
		}
				/*
		child.style.setAttribute("visibility", (child.style.getAttribute("visibility") == "hidden")?"visible":"hidden");
		child.style.setAttribute("display", (child.style.getAttribute("display") == "none")?"":"none");
		*/
	}
	else
	{
		openUrl(parentID);
	}
}


function loadMenu()
{
	var finish;
	var menu, i, menuText, child;
	
	menuText = "Menu";
	finish = false;
	i = 1;
	
	while (!finish)
	{
		menu = document.getElementById(menuText + "_" + i);
		
		if (menu == null)
		{
			finish = true;
		}
		else
		{			
			child = document.getElementById(menuText + "_" + i + "_" + 0);
			
			//menuList.push(menuText + "_" + i);
			if (child != null)
			{
				//child.style.setAttribute("visibility", "hidden");
				child.style.setAttribute("display", "none");
			}
		
			i++;
		}
	}
	
	loadArray();

/*
	if (i > 1)
	{		
		menuList = new Array(i - 1);
		subMenuList = new Array(i - 1);
	}
	*/
}



function loadArray()
{
	var url = "content.htm";
	
	menuList = new Array(0);
	
	menuList['menu_1'] = "nos-por-ca/" + url;
	menuList['menu_1_1'] = "nos-por-ca/do-estado/" + url;
	menuList['menu_1_2'] = "nos-por-ca/do-cidadao/" + url;
	menuList['menu_2'] = "do-imperio/" + url;
	menuList['menu_2_1'] = "do-imperio/guerra/" + url;
	menuList['menu_2_2'] = "do-imperio/rapina/" + url;
	menuList['menu_3'] = "luta-dos-povos/" + url;
	menuList['menu_3_1'] = "luta-dos-povos/medio-oriente/" + url;
	menuList['menu_3_2'] = "luta-dos-povos/america-latina/" + url;
	menuList['menu_3_3'] = "luta-dos-povos/mundo/" + url;
	menuList['menu_4'] = "movimentos/" + url;
	menuList['menu_4_1'] = "movimentos/mov-estudantil/" + url;
	menuList['menu_4_2'] = "movimentos/mov-operario/" + url;
	menuList['menu_4_3'] = "movimentos/mov-social/" + url;
	menuList['menu_5'] = "opios/" + url;
	menuList['menu_6'] = "ensino/" + url;
	menuList['menu_7'] = "cultura/" + url;
	menuList['menu_7_1'] = "cultura/poesia/" + url;
	menuList['menu_7_2'] = "cultura/escritos/" + url;
	menuList['menu_8'] = "comunicados/" + url;
	menuList['menu_9'] = "links/" + url;
	menuList['menu_10'] = "arquivo/" + url;
	menuList['menu_11'] = "editorial/" + url;
	
	pathList = new Array(0);
	
	pathList['menu_1'] = "Nós, Por Cá";
	pathList['menu_1_1'] = "Nós, Por Cá > Do Estado";
	pathList['menu_1_2'] = "Nós, Por Cá > Do Cidadão";
	pathList['menu_2'] = "Do Império";
	pathList['menu_2_1'] = "Do Império > Guerra";
	pathList['menu_2_2'] = "Do Império > Rapina";
	pathList['menu_3'] = "Luta Dos Povos";
	pathList['menu_3_1'] = "Luta Dos Povos > Médio Oriente";
	pathList['menu_3_2'] = "Luta Dos Povos > América Latina";
	pathList['menu_3_3'] = "Luta Dos Povos > Mundo";
	pathList['menu_4'] = "Movimentos";
	pathList['menu_4_1'] = "Movimentos > Mov. Estudantil";
	pathList['menu_4_2'] = "Movimentos > Mov. Operário";
	pathList['menu_4_3'] = "Movimentos > Mov. Social";
	pathList['menu_5'] = "Ópios";
	pathList['menu_6'] = "Ensino";
	pathList['menu_7'] = "Cultura";
	pathList['menu_7_1'] = "Cultura > Poesia";
	pathList['menu_7_2'] = "Cultura > Escritos";
	pathList['menu_8'] = "Comunicados";
	pathList['menu_9'] = "Links";
	pathList['menu_10'] = "Arquivo";
	pathList['menu_11'] = "Editorial";
	
	pathList['nos-por-ca'] = "Nós, Por Cá";
	pathList['do-cidadao'] = "Do Cidadão";
	pathList['do-estado'] = "Do Estado";
	
	pathList['do-imperio'] = "Do Império";
	pathList['guerra'] = "Guerra";
	pathList['rapina'] = "Rapina";
	
	pathList['luta-dos-povos'] = "Luta Dos Povos";
	pathList['medio-oriente'] = "Médio Oriente";
	pathList['america-latina'] = "América Latina";
	pathList['mundo'] = "Mundo";
	
	pathList['movimentos'] = "Movimentos";
	pathList['mov-estudantil'] = "Mov. Estudantil";
	pathList['mov-operario'] = "Mov. Operário";
	pathList['mov-social'] = "Mov. Social";
	
	pathList['opios'] = "Ópios";
	pathList['ensino'] = "Ensino";
	pathList['cultura'] = "Cultura";
	pathList['poesia'] = "Poesia";
	pathList['escritos'] = "Escritos";
	
	pathList['comunicados'] = "Comunicados";
	
	pathList['links'] = "Links";
	
	pathList['arquivo'] = "Arquivo";
	
	pathList['opiniao'] = "Opinião";
	
	pathList['noticias'] = "Notícias";
	
	pathList['divida-soberana'] = "Não Pagamos a Dívida Odiosa";
	
	pathList['aborto'] = "Dossier: Aborto";
	
	pathList['guerra-civil'] = "Guerra Civil de Espanha";
	
	pathList['hispania-artigos'] = "Hispania";
	
	pathList['pena-morte-artigos'] = "Pena de Morte";
	
	pathList['fascismo'] = "Fascismo";
	
	pathList['historia-pide'] = "PIDE/DGS";
	
	pathList['artigos-anteriores'] = "Artigos Anteriores";
}

/*
function desliza()
{
	var a;
	
	a = document.getElementById("ahah");
	//alert(a.offsetLeft + " " + a.offsetTop + " " + a.offsetHeight + " " + a.offsetWidth);
	alert(a.style.top);

}
*/


//document.onselectstart=new Function("return false")

function loadIFrame()
{
	var url;
	
	url = "content.htm";

	if (document.all)
	{
		iframe = document.all.body_frame;
	}
	else
	{
		if (document.getElementById)
		{
			iframe = document.getElementById("body-frame");
		}
	}
	
	if (iframe != null)
	{
		iframe.src = url;
	}
}

function loadPath()
{
	init_path = "> Início";

	if (document.getElementById)
	{
		path = document.getElementById("path");
	}
	
	if (path != null)
	{
		path.innerHTML = init_path;
		selected_path = init_path;
	}
}

/*
function openUrl(id)
{
	if ((iframe != null) && (path != null))
	{
		iframe.src = menuList[id];
		path.innerHTML = init_path + pathList[id];
		selected_path = init_path + pathList[id];
	}
}
*/

function openUrl(str, refreshTitle)
{
	if (str != null) {
		var s = str.split("/");
		var path_str = init_path;
		var i;
		//alert(str);
		for (i = 0; i < s.length; i++) {
			//alert(s[i]);
			if (pathList[s[i]] != null) {
				path_str = path_str + separator_path + pathList[s[i]];
			}
		}
		if (menuList[str] != null) {
			iframe.src = menuList[str];
		} else {
			iframe.src = str;
		}
		//alert(path_str);
		if (refreshTitle != false) {
			if (path_str.lastIndexOf("undefined") == -1) {
				path.innerHTML = path_str;
				selected_path = path_str;
			}
		}
	}
	window.scrollTo(0,0);
	/*
	if ((iframe != null) && (path != null))
	{
		iframe.src = menuList[id];
		path.innerHTML = init_path + pathList[id];
		selected_path = init_path + pathList[id];
	}
	*/
}

function setPath(str_path) {
		if (path != null) {
				path.innerHTML = str_path;
		}
}
