function $(id){
	newId = document.getElementById(id);
	return newId;	
}

function cont(){

	var colunas = 4;
	var total = $('ler').getElementsByTagName('li').length;
	var porcoluna = Math.ceil(total/colunas);
	var resto = total%colunas;
	var col = new Array();
	var _total=u=_contRep=0;
	var _contCol=1;

	for(var i=0; i<total; i++){
		var mts = $('ler').getElementsByTagName('li')[i].innerHTML.split(" - ",3);
		(i>0)?mts1=$('ler').getElementsByTagName('li')[i-1].innerHTML.split(" - ",2):mts1=new Array();
		
		if(_total<=porcoluna){
			if(mts[0]!=mts1[0]){
				_contRep++;
			}
		}
		_total++;
	}
	return _contRep;
}
cont();
function exibe(){
	var colunas = 4;
	var totalLi = $('ler').getElementsByTagName('li').length;
	var total = $('ler').getElementsByTagName('li').length + _contRep;
	var porcoluna = Math.floor(total/colunas);
	var resto = total%colunas;
	var col = new Array();
	var _total=u=0;
	var _contCol=1;
	var _total = Math.ceil(_contRep/1.5);

	for(var i=0; i<4; i++){
		col[i] = document.createElement('ul');
		col[i].setAttribute('id','col'+i+'');
	}
	
	//document.getElementById('imprimir').appendChild(x);
	first = true;
	for(var i=0; i<total; i++){
		if ($('ler').getElementsByTagName('li')[i]) {
			z = document.createElement('li');
			var mts = $('ler').getElementsByTagName('li')[i].innerHTML.split(" - ", 3);
			(i > 0) ? mts1 = $('ler').getElementsByTagName('li')[i - 1].innerHTML.split(" - ", 2) : mts1 = new Array();
			
			if (_total <= porcoluna) {
				if (mts[0] != mts1[0]) {
					y = document.createElement('li');
					y.innerHTML = mts[0];
					(first == true) ? y.className = 'estadoTop' : y.className = 'estado';
					col[u].appendChild(y);
					$('imprimir').appendChild(col[u]);
				}
				if (first == true) {
					if (mts[0] == mts1[0]) {
						x = document.createElement('li');
						x.innerHTML = mts[0];
						col[u].appendChild(x);
						x.className = 'estadoTop';
						$('imprimir').appendChild(col[u]);
						_contCol++;
					}
				}
				x = document.createElement('a');
				x.setAttribute('href', mts[2]);
				x.innerHTML = mts[1];
				z.appendChild(x);
				col[u].appendChild(z);
				$('imprimir').appendChild(col[u]);
				if (_total == porcoluna) {
					_total = Math.floor(_contRep/2);
					if (u < 3) {
						u++;
						first = true;
					}
					
				}
				else {
					first = false
				}
				
			}
			_total++;
		}
	
	}

	$('ler').style.display = 'none';
	(total>=2)?$('interior').innerHTML = totalLi+' localidades':$('interior').innerHTML = totalLi+' localidade';
}

exibe();

// colunas que serao ajustadas pelo equalize() //

cols = [ 'col0','col1','col2','col3' ]

var bFs = ($('barrauol')) ? $('barrauol').offsetWidth/98.8 : 0 ;

function equalize() {

	maxHeight = 0;

	for(i=0,n=arguments.length;i<n;i++) cols.push(arguments[i]);

	for(i=0,n=cols.length;i<n;i++) if($(cols[i])) if($(cols[i]).clientHeight > maxHeight) maxHeight = $(cols[i]).clientHeight;

	for(i=0,n=cols.length;i<n;i++) if($(cols[i])) $(cols[i]).style.height = maxHeight/bFs  +2+'em';

}

equalize();

