window.onload = function() {
	if(getUrlName() == "portfolio") {
		document.getElementById("statusPage").style.display = "none";
	}
}
window.onscroll = function() {
	if(document.getElementById("menuLateral") != null) {
		divMoving("menuLateral");
	}
	if(document.getElementById("PortfolioDir") != null) {
		divMoving("PortfolioDir");
	}	
}
//Array que contera os 'ids' de todos os elementos dados.
var array = new Array();
//Contador de Elementos (Correspondente ao Menu Lateral da Default)
var i = 0;
var allImgsPortfolio;
var activePortfolio;
var totalImgsInPortfolio;
var activeImgInPortfolio;
//Posicao do Item do Portfolio que esta sendo mostrado no momento.
var indexPortfolio = 0;
//Total de Itens do Portfolio
var totalPortfolio = 0;
//Retorna true ou false, caso o elemento exista ou nao, no array.
function checkElement(e) {
	if(i == 0) {
		document.getElementById("textoProdutoDefault").style.display = "none";
		array[i] = e;
			i++;
	}
	for(x = 0; x<=array.length-1; x++) {
		if(array[x].toString() == e.toString()) {
			return true;
		}
	}
	return false;
}
// Checa se um determinado elemento existe no array (consequentemente no html, também).
// Caso exista, seta a propriedade 'Display - Block' nele, e 'Display - None' nos demais. 
// Caso não exista. Adiciona ele no array, e repete os passos anteriores.
// Parametros:
// n => String com o id do elemento a ser mostrado.
function mostraConteudo(n) {
	if(!checkElement(n)) {
		array[i] = n;
		i++;
	}
	for(j = 0; j<=array.length-1;j++) {
		if(array[j].toString() == n.toString()) {
			document.getElementById(n).style.display = "block";
		}
		else {
			document.getElementById(array[j]).style.display = "none";
		}
	}
}
// Muda a cor de um botao dado.
// Parametros:
// txt => id do Botao
function changeColor(txt) {
	if(document.getElementById('btn'+txt) != null) {
		var activeButton = document.getElementById('btn'+txt);
		activeButton.style.backgroundPosition = "0 -70px";
		activeButton.style.color = "#FFFFFF";
	}
}
function getUrlName() {
	var myloc = window.location.href;
	var locarray = myloc.substring(myloc.lastIndexOf("/")+1,myloc.indexOf(".aspx"));
	locarray = locarray.replace(".aspx","");
	return locarray;
}
function divMoving(id) {	
	startY = 0;
	obj = document.getElementById(id);
	if (document.body.scrollTop > startY)
		obj.style.top = document.body.scrollTop + 10;
} 
function getConnection() {
	try {
		return new ActiveXObject("Msxml3.XMLHTTP");
	} catch(e) {
		try {
			return new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				return new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				try {
					return new XMLHttpRequest();
				} catch(e) {
					return null;
				}
			}
		}
	}
}
function doConnection() {
	con = getConnection();
	con.open("GET","portfolio.xml.aspx",true);
	con.onreadystatechange = update;
	con.send(null);
}
function update() {
	if(con.readyState == 4) {
		if(con.status == 200) {
			organizer();
		}
	}
}
function organizer() {
	var frm = document.forms["filtros"];
	document.getElementById("statusPage").style.display = "block";
	leftOutput = document.getElementById("PortfolioEsq");
	leftOutput.innerHTML = "";
	xmlobj = con.responseXML;
	index = 0;
	it = 0;
	onlyTheFirstTime = true;
	for(var aNode = xmlobj.firstChild; aNode != null; aNode = aNode.nextSibling) {
		for(var aNodeSon = aNode.firstChild; aNodeSon != null; aNodeSon = aNodeSon.nextSibling) {
			if(aNodeSon.nodeName.toString().toLowerCase() == "tipo") {
					leftOutput.innerHTML += "<div id=\"pf"+index+"\" class=\"portfolio\">";
					actualOutput = document.getElementById("pf"+index);
					actualOutput.innerHTML += "<h2>"+aNodeSon.attributes[0].value+"</h2>";
					for(var aNodeGrandSon = aNodeSon.firstChild; aNodeGrandSon != null; aNodeGrandSon = aNodeGrandSon.nextSibling) {
						if(aNodeGrandSon.nodeName.toString().toLowerCase() == "site") {
							if(onlyTheFirstTime) {
								startDescr = it;
								onlyTheFirstTime = false;
							}
							for(i = 0; i < aNodeGrandSon.attributes.length; i++) {
								if(aNodeGrandSon.attributes[i].name.toLowerCase() == "imgthumb") {
									activePortfolio = it;
									actualOutput.innerHTML += "<div style=\"padding: 5px 10px 5px 0; display: inline;\"><a href=\"javascript:descricao("+activePortfolio+",0)\"><img src=\"."+aNodeGrandSon.attributes[i].value+"\" border=\"0\" width=\"91px\" height=\"55px\"></a></div>";
									totalPortfolio++;
								}
							}		
						}
						it++;
					}
					leftOutput.innerHTML += "</div>";
					index++;
			}
		}
	}
	activePortfolio = 0;
	activeImgInPortfolio = 0;
	descricao(startDescr,0);
	document.getElementById("statusPage").style.display = "none";
}	
function anterior() {
	if(activeImgInPortfolio == 0) {
		activeImgInPortfolio = totalImgsInPortfolio-1;
		descricao(activePortfolio,activeImgInPortfolio);
	}
	else {
		activeImgInPortfolio--;
		descricao(activePortfolio,activeImgInPortfolio);
	}
}
function proximo() {
	if(activeImgInPortfolio == totalImgsInPortfolio-1) {
		activeImgInPortfolio = 0;
		descricao(activePortfolio,activeImgInPortfolio);
	}
	else {
		activeImgInPortfolio++;
		descricao(activePortfolio,activeImgInPortfolio);
	}
}
function descricao(k,z) {
	activePortfolio = k;
	titulo = document.getElementById("PortfolioDirTitle");
	img = document.getElementById("PortfolioDirSiteImg");
	siteState = document.getElementById("PortfolioDirSiteState");
	siteUrl = document.getElementById("PortfolioDirSiteUrl");
	caseDown = document.getElementById("PortfolioDirCaseDownload"); 
	fullDescr = document.getElementById("PortfolioDirFullDescr");
	titulo.innerHTML = "";
	img.innerHTML = "";
	siteState.innerHTML = "";
	siteUrl.innerHTML = "";
	caseDown.innerHTML = "";
	fullDescr.innerHTML = "";
	xmlobj = con.responseXML;
	it = 0;
	for(var aNode = xmlobj.firstChild; aNode != null; aNode = aNode.nextSibling) {
		for(var aNodeSon = aNode.firstChild; aNodeSon != null; aNodeSon = aNodeSon.nextSibling) {
			if(aNodeSon.nodeName.toString().toLowerCase() == "tipo") {
				for(var aNodeGrandSon = aNodeSon.firstChild; aNodeGrandSon != null; aNodeGrandSon = aNodeGrandSon.nextSibling) {
					if(it == k) {
					if(aNodeGrandSon.nodeName.toString().toLowerCase() == "site") {
						fullDescr.innerHTML = aNodeGrandSon.firstChild.data;
						for(i = 0; i < aNodeGrandSon.attributes.length; i++) {
								if(aNodeGrandSon.attributes[i].name.toLowerCase() == "titulo") {
									titulo.innerHTML = "<h2>"+aNodeGrandSon.attributes[i].value+"/"+aNodeSon.attributes[0].value+"</h2>";
								}
								else if(aNodeGrandSon.attributes[i].name.toLowerCase() == "imgportfolio") {
									allImgsPortfolio = aNodeGrandSon.attributes[i].value.toLowerCase().split(',');
									totalImgsInPortfolio = allImgsPortfolio.length;
									img.innerHTML = "<img src=\"iconstructor/custom/portfolio/"+allImgsPortfolio[z]+"\" border=\"0\" width=\"248px\" height=\"188px\">";
								}
								else if(aNodeGrandSon.attributes[i].name.toLowerCase() == "estado") {
									if(aNodeGrandSon.attributes[i].value.toLowerCase() == "0") {
											siteState.innerHTML = "<img src=\"images/portfolio/controls/bolaVermelha.gif\" border=\"0\" width=\"18px\" height=\"18px\">";
									} else if(aNodeGrandSon.attributes[i].value.toLowerCase() == "1") {
											siteState.innerHTML = "<img src=\"images/portfolio/controls/bolaVerde.gif\" border=\"0\" width=\"18px\" height=\"18px\">";
									} else {
											siteState.innerHTML = "<img src=\"images/portfolio/controls/bolaAmarela.gif\" border=\"0\" width=\"18px\" height=\"18px\">";
									}
								}
								else if(aNodeGrandSon.attributes[i].name.toLowerCase() == "siteurl") {
									siteUrl.innerHTML = "<a target=\"_blank\" href=\"http://"+aNodeGrandSon.attributes[i].value+"\">"+aNodeGrandSon.attributes[i].value+"</a>";
								}
								else if(aNodeGrandSon.attributes[i].name.toLowerCase() == "urlcase") {
									caseDown.innerHTML = "<img src=\"images/portfolio/controls/case.gif\" border=\"0\" width=\"18px\" height=\"18px\">&nbsp;<a href=\"http://"+aNodeGrandSon.attributes[i].value+"\">download do case</a>";
								}
							}
						}		
					}
					it++;
				}
			}
		}
	}
}
//Lista Menu Topo Mapa do Site sem IC
var arrayMenus = ["Empresa","Serviços","Produtos","Clientes","Portfólio","Intranet","Contato"];var arrayLinks = ["Empresa","Servicos","Produtos","Clientes","Portfolio","Intranet","Contato"];