
jQuery(document).ready(function(){
	jQuery("#searchsubmit").bind("click", function(e) {
		if(jQuery('#mainsearch > #formcontents > #Search').attr('value') !== jQuery('#mainsearch > #formcontents > #previous_search').attr('value')){
			jQuery('#mainsearch > #formcontents > :hidden').each(function(i){
			    if(jQuery(this).attr('name').substring(0, 6) === 'facet_'){
			        jQuery(this).attr('value', '');
			    }
			});

			jQuery('#mainsearch > #formcontents > #begin').attr('value', 0);
			jQuery('#mainsearch > #formcontents > #new_search').attr('value', 1);
		}	
	});
});

jQuery(document).ready(function(){
	debug("DEFAULT_LINEHEIGHT: " + DEFAULT_LINEHEIGHT);
	var lh = jQuery('.description > p').css('line-height');
	if(lh){
		if(lh === 'normal'){  // yes this is for IE...
			lh = '14px';
		}
		lh = parseFloat(lh.replace(/px/, ''));
		DEFAULT_LINEHEIGHT	= Math.round( (lh < Math.round(lh)) ? lh + 0.5 : lh );
		debug("DEFAULT_LINEHEIGHT: " + DEFAULT_LINEHEIGHT);
	}
});

function updateSelection(field, value){
	jQuery('#begin').attr('value', 0);
	jQuery('#mainsearch > #formcontents > #' + field).attr('value', value);
	jQuery('#mainsearch').submit();
	return false;
}

function perPageOnChange() {
	updateSelection('perpage', jQuery('#perpage_selector > :selected').attr('value'));
}

function useSpellingSuggestion(suggestion) {
	updateSelection('Search', suggestion);
}


