var iebrowser = false;

if (document.all) {
	if (!document.getElementById) {
		document.getElementById = document.all;
	}
	iebrowser = true;
}

var Root = new Object();
var nodeIndex = new Object();
var ACTIVE_COLOR = STANDARD_COLOR = '';

function navObj(_title, _id, _url, _parent,_bChildNodes) {
	this.title = _title;
	this.id = _id;
	this.type = "doc";
	this.url = _url;
	this.childNodes = new Object();
	this.parentNode = _parent;
	this.hasChildNodes = _bChildNodes;
    RootByID[_id] = this;     
}

function fnInArray(sSearchItem, arArray) {
	var i;
	if (sSearchItem != '' && arArray) {
		for (i = 0; i < arArray.length; i++) {
			if (sSearchItem.toLowerCase() == arArray[i].toLowerCase()) {
				return true;
			}
		}
	}
	return false;
}

function fnBuildLeftIndent(sLeftIndent) {
	sLeftIndent += '';
	return sLeftIndent;
}

var idcount = 0;

function uid() {
	var nid = 'block' + idcount;
	idcount = idcount + 1;
	return nid;
}

var doc = 'site.php';
RootByID = Array();
 Root['/pt/conheca_nos.html']= new navObj('Conhe&ccedil;a-nos','/pt/conheca_nos.html','/pt/conheca_nos.html',null,false,'');nodeIndex['/pt/conheca_nos.html'] ='/pt/conheca_nos.html';
 Root['/pt/contate_nos.html']= new navObj('Contate-nos','/pt/contate_nos.html','/pt/contate_nos.html',null,false,'');nodeIndex['/pt/contate_nos.html'] ='/pt/contate_nos.html';
 Root['/pt/projetos.html']= new navObj('Projetos','/pt/projetos.html','/pt/projetos.html',null,false,'');nodeIndex['/pt/projetos.html'] ='/pt/projetos.html';
 Root['/pt/links.html']= new navObj('Links','/pt/links.html','/pt/links.html',null,false,'');nodeIndex['/pt/links.html'] ='/pt/links.html';
 Root['/pt/album_de_fotos.html']= new navObj('&Aacute;lbum de Fotos','/pt/album_de_fotos.html','/pt/album_de_fotos.html',null,false,'');nodeIndex['/pt/album_de_fotos.html'] ='/pt/album_de_fotos.html';


function buildCustomTree(objNodes, iElement, sLeftIndent,nid) {
	var oNode;
	nid = (!nid)?'blockroot':nid;
	var display;
	var imageActive;
	var returnValue;
	var kleur; 
	var wijs; 
	var bull;
	bull = '<img src="/images/bullet_tri.gif" width="10" height="9" border="0">';
	var bHasChildren = false;
	var mahre;
	if (iElement == 1) {
		var mclass = ' class="subnavblock"';
	} else {
		var mclass = "";
	} 
	returnValue = '<div ' + mclass + ' id="' + nid + '" style="display:' + sLeftIndent + '">';
	iElement = iElement + 1;
	for (var oNode in objNodes) {
		nid = uid();
		if (!fnInArray(objNodes[oNode].url, arArray)) {
			display = 'none;';
			kleur = STANDARD_COLOR;
		} else {
			display = 'block';
			kleur = ACTIVE_COLOR;
		}
		wijs = '';	
		if (compareToLocation(objNodes[oNode].url)) {
			wijs = '';	
		}
		if (display == 'block') {
			mahref = '<a href="' + objNodes[oNode].url + '" ';
			if (iElement == 1 && objNodes[oNode].hasChildNodes) {
				mahref += ' onclick="return toggleObject(\'' + nid + '\');" ';
				gobj = nid;
			}
			mahref += 'class="mainnav' + iElement + '"';
			if (iElement > 1) {
				mahref += 'style="color: #FFFAE6;"';
			}
			mahref += '>';
			returnValue += '<table border="0" width="100%" cellpadding="2" cellspacing="0">'
			+ '<tr><td valign="top" align="left" width="10">'
			+ bull
			+ '</td>'
			+ '<td width="100%">'
			+ mahref+objNodes[oNode].title
			+ '</a>'
			+ wijs
			+ '</td>'
			+ '<td width="2"><img src="/images/spacing.gif" width="2" height="2" /></td>'
			+ '<td align="right" valign="bottom" width="1%">'
			+ mahref
			+ '<span name="img'
			+ nid
			+ '" id="img'
			+ nid
			+ '" src="/images/arrow_l'
			+ iElement
			+ '" vspace="2" border="0"></a></td></tr></table>\n';
		} else {
			mahref = '<a href="'+objNodes[oNode].url+'" ';
			if (iElement == 1 && objNodes[oNode].hasChildNodes) {
				mahref +='onclick="return toggleObject(\''+nid+'\');" ';
			}
			mahref += ' class="mainnav' + iElement + '" >';
			returnValue += '<table border="0" width="100%" cellpadding="2" cellspacing="0">'
			+ '<tr><td valign="top" align="left" width="10">'
			+ bull
			+ '</td>'
			+ '<td width="100%">'
			+ mahref + objNodes[oNode].title
			+ '</a>'
			+ wijs
			+ '</td>'
			+ '<td width="2"><img src="/images/spacing.gif" width="2" height="2" /></td>'
			+ '<td align="right" valign="top" width="1%"><span name="img' + nid + '" id="img' + nid + '"></td></tr></table>\n';
		}
		var sTempLeft = sLeftIndent;
		if (objNodes[oNode].hasChildNodes && iElement < 2) {
			returnValue += buildCustomTree(objNodes[oNode].childNodes, iElement, display, nid);
		}
	}
	return returnValue + '</div>\n\n';
}

function compareToLocation( _naam ) {
	if (lastPiece( _naam ) == lastPiece(document.location)) {
		return true;
	} else {
		return false;
	}
}

function lastPiece(volnaam) {
	var strNaam = new String(volnaam);
	var intA = strNaam.lastIndexOf('/');
	var lastbit = strNaam.substr(intA);	
	return lastbit;
}

function writeNavigation() {
	var contentTxt;
	contentTxt = '';
	var display = '';
	contentTxt += buildCustomTree(Root, 0, '');
	document.write(contentTxt);
}

var arArray = new Array();
var locStr = new String(document.location);
var pageID = locStr.slice(locStr.lastIndexOf('/') + 1, locStr.length);
pageID = (pageID.indexOf('?') > 0 ) ? pageID.slice(0, pageID.lastIndexOf('?')) : pageID;
pageID = document.location.pathname;

if (pageID != '') {
	pageID = pageID;
	setUrlStr(Root,pageID,pageID);
}

var gobj = 0;

function toggleObject(id) {
	obj = document.getElementById(id);
	imgobj = document.getElementById('img' + id);
	if (obj.style.display == 'none') {
		if (gobj) {
			sobj = document.getElementById(gobj);
			simgobj = document.getElementById('img' + gobj);
			sobj.style.display = 'none';
			simgobj.src = '/images/spacing.gif';
			gobj = 0;
		}
		gobj = id;
		vdisplay = 'block';
		imgobj.src = '/images/spacing.gif';
	} else {
		gobj = 0;
		vdisplay = 'none';
		imgobj.src = '/images/spacing.gif';
	}
	obj.style.display = vdisplay;
	return false;
}

function setUrlStr(sN, pageID, str) {
	var newString = '';
	for (var i in sN) {
		if (sN[i].url == pageID) {
			arArray = str.split(',');
		} else {
			newString = str + ',' + sN[i].url;	
			if (sN[i].hasChildNodes) {
				setUrlStr(sN[i].childNodes, pageID, newString);	
			}
		}
	}
}

