DOM.adopt = function(o, a) { o.appendChild( a.parentNode.removeChild(a) ); };
var ArisColumns = new function() {
	
	function least(arr) {
		var idxRet = 0;
		arr.forEach(function(item,idx,list) { 
			if ( item < list[idxRet] )
				idxRet = idx;
		});
		return idxRet;
	}
	function formatColumns(sm) {
	
		var h =sm.offsetHeight
	
		if (DOM.match('div.industry',sm).length < 2) return;

		DOM.addClass(sm,'columns');
		var col0 = DOM.create('div', { className: 'col' });
		var col1 = col0.cloneNode(false);
		var col2 = col0.cloneNode(false);
		DOM.addClass(col0, 'idx0');
		DOM.addClass(col1, 'idx1');
		DOM.addClass(col2, 'idx2');

		//var items = DOM.match("h2,li", sm).length;
		
		var adopter = col0;
		var adopted = 0;
		var half = Math.floor(h / 3);
		var cols = [col0,col1,col2];
		var lens = [0,0,0];
		DOM.match('div.industry',sm).forEach(function(dl) {
			var hIdx = least(lens);
			lens[hIdx] += (dl.offsetHeight + 30);
			DOM.adopt(cols[hIdx],dl);
//			if ( adopter!=col2 ) {
//				adopted += (dl.offsetHeight + 30);
//			}
//			DOM.adopt(adopter, dl);
//			if (adopted > half ) {
//				adopter = adopter==col1 ? col2 : col1;
//				adopted = 0;
//			}
		});
		sm.appendChild(col0);
		sm.appendChild(col1);
		sm.appendChild(col2);
		
	}
	return {
		create: function(selector) {
			Event.onDOMReady.add(function() {
				var node = DOM.matchOne(selector);			
				if ( !node ) return;
				DOM.setStyle(node,'visibility', 'hidden');
				formatColumns(node);
				DOM.setStyle(node,'visibility', '');
			});
		}
	}
};