(function($){ 
$.fn.toggleSearch = function() {
	
	// set defaults to google
	$( "#googleSearch").attr("checked", "true");
	$( "#clustySearchFields > :input").attr("disabled", "true");
	$( "#clustySearchFields" ).hide();
	$( "#googleSearchFields > :input").attr("disabled", "");
	$( "#googleSearchFields" ).show();
	$("#searchForm").attr({action: "http://www.google.com/search"});	

	return this.click( function() {
		// set up toggle
		var searchOption = $(this).attr('id');
		if (  searchOption == "clustySearch" ) {
			var onSearch = "#clustySearchFields";
			var onQuery = "#clustyQuery";
			var offSearch = "#googleSearchFields";
			var offQuery = "#googleQuery";	
		} else {
			var onSearch = "#googleSearchFields";
			var onQuery = "#googleQuery";
			var offSearch = "#clustySearchFields";	
			var offQuery = "#clustyQuery";			
		}
		
		// sync query fields 		
		if ( $( offQuery ).attr("value") != undefined  ) $( onQuery ).attr( "value", $( offQuery ).attr("value") );
		// perform toggle
		$( offSearch + " > :input").attr("disabled", "true");
		$( offSearch ).hide();
		$( onSearch + " > :input").attr("disabled", "");
		$( onSearch ).show();
		
		// set form action	
		$("#searchForm").attr({action: this.value});		
		
	} );
};
} )(jQuery);