Event.onDOMReady.add(function() {
	var sm = DOM.matchOne('#smLnks');
	DOM.setStyle(sm,'visibility', 'hidden');
	createForm(sm);

	formatColumns(sm);
	DOM.setStyle(sm,'visibility', '');
	
	
	function createForm(sm) {
		
		var h = DOM.create('input', {'type': 'text', 'name': 'h', id: 'h_keywords', maxlength:'100'});
		var label = DOM.create('label', {'for': 'h_keywords', children: 'Search:' });
		var show = DOM.create('button', { type: 'button', children: 'Show' });
		var clear = DOM.create('button', { type: 'button', children: 'Clear' });
		
		var form = DOM.create('fieldset' , {
			className: 'panel idx1 col',
			children: [
				{tag: 'p', attr: { children: 'Enter a search term to highlight the links in which you\'re interested' }},
				{tag: 'p', attr: { children: [label, h, ' ', show,' ', clear] }}
			]
		});
		
		sm.appendChild(form);
		
		Event.add(show, 'click', function() {
			localSearchHighlight('?h=' + h.value);
		});
		
		Event.add(clear, 'click', function() {
			unhighlight(document.getElementsByTagName('body')[0]);
			h.value='';
		});
	}

	function formatColumns(sm) {
	
		var col0 = DOM.create('div', { className: 'col' });
		var col1 = col0.cloneNode(false);
		DOM.addClass(col0, 'idx0');
		DOM.addClass(col1, 'idx1');
		
		var items = DOM.match("dd,li", sm).length;
		
		var adopter = col0;
		var adopted = 0;
		var half = items / 2;
		DOM.match('dl',sm).forEach(function(dl) {
			if ( adopted <= half ) 
				adopted += DOM.match("dd,li", dl).length;
				
			DOM.adopt(adopter, dl);
		
			if (adopted > half )
				adopter = col1;
		});
		sm.appendChild(col0);
		sm.appendChild(col1);
		
	}

});
