document.observe("dom:loaded", function() {
	if ($('mainframe_wrapper')) {
		$('mainframe_wrapper').setStyle({marginTop:'35px'});		
	}
	else {
		$('mainframe').setStyle({marginTop:'35px'});		
	}
	
	// convert search engine friendly list of links to select pulldown
	var issues = $H();
	var selectedissue;
	$$('#newsletterselectwrapper ul li a').each(function(o) {
		// create hash of key -> value options for select pulldown
		var thiskey = o.id.replace(/^issue_/,'');
		thiskey = thiskey.replace(/-/,'/');
		if (o.hasClassName('selected')) {
			selectedissue = thiskey;
		}
		issues.set(thiskey, o.innerHTML);
	});
	var selectoptions;
	issues.each(function(pair) {
		selectoptions += '<option value = "' + pair.key + '"';
		if (pair.key == selectedissue) {
			selectoptions += ' selected="selected"';
		}
		selectoptions += '>' + pair.value + '</option>';
	});
	$('newsletterselectwrapper').update('<select id="newsletterselect">' + selectoptions + '</select>');
	
	$('newsletterselect').observe('change', function(e) {
		window.location.href = '/newsletterarchives/' + $('newsletterselect').getValue();			
	});
	
	$('searchform').observe('submit', function(e) { 
		e.stop(); 
		initSearch();
	});
	
	$('searchbutton').observe('click', function(e) {
		initSearch();		
	});
	
});

function initSearch() {
	if (!$('search').getValue()) { return; }
	window.location.href = '/newsletterarchives/search/' + $('search').getValue();
}
