(function($){
		$.fn.linkedSelect = function(url, destination, params) {
			var params = $.extend({
					loadingText : 'Loading …'
			},params);
			var $dest = $(destination);

			return this.each(function(){
					$(this).bind('change', function() {
							var $$ = $(this);

							$dest.attr('disabled', 'disabled')
								.html('<option value="">' + params.loadingText + '</option>')
								.ajaxStart(function(){
										$$.show();
								});

							$.getJSON(url,{id: $$.val()}, function(j){
									if (j.length > 1) {
										var options = '';
										for (var i = 0; i < j.length; i++) {
											options += '<option value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
										}

										$dest.removeAttr('disabled').html(options);

									} else {
										$dest.html('');
									}
							}); // end getJSON
					});  // end change
			}); // end return each
		};  // end function
})(jQuery);
